MiniDevil
As beautiful as a shell
drawing_box.c
Go to the documentation of this file.
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* drawing_box.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: baelgadi <baelgadi@student.42.fr> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2026/02/17 17:48:56 by zotaj-di #+# #+# */
9
/* Updated: 2026/03/04 03:25:20 by baelgadi ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include "
minishell_ui.h
"
14
20
static
void
draw_box_top
(
t_box
*b)
21
{
22
print_at
(b->
y
, b->
x
, b->
color
);
23
write(STDOUT_FILENO,
BOX_TL
, 3);
24
draw_hline
(b->
w
- 2, b->
color
);
25
write(STDOUT_FILENO,
BOX_TR
, 3);
26
ft_printf(
"%s"
,
RESET
);
27
}
28
34
void
draw_box_bottom
(
t_box
*b)
35
{
36
print_at
(b->
y
+ b->
h
- 1, b->
x
, b->
color
);
37
write(STDOUT_FILENO,
BOX_BL
, 3);
38
draw_hline
(b->
w
- 2, b->
color
);
39
write(STDOUT_FILENO,
BOX_BR
, 3);
40
ft_printf(
"%s"
,
RESET
);
41
}
42
48
void
draw_box_sides
(
t_box
*b)
49
{
50
int
i;
51
52
i = 1;
53
while
(i < b->h - 1)
54
{
55
print_at
(b->
y
+ i, b->
x
, b->
color
);
56
write(STDOUT_FILENO,
BOX_V
, 3);
57
ft_printf(
"%s"
,
RESET
);
58
print_at
(b->
y
+ i, b->
x
+ b->
w
- 1, b->
color
);
59
write(STDOUT_FILENO,
BOX_V
, 3);
60
ft_printf(
"%s"
,
RESET
);
61
i++;
62
}
63
}
64
70
void
draw_box
(
t_box
*b)
71
{
72
draw_box_top
(b);
73
draw_box_sides
(b);
74
draw_box_bottom
(b);
75
}
76
83
void
draw_box_title
(
t_box
*b,
const
char
*title)
84
{
85
int
title_len;
86
int
pad;
87
88
title_len =
visual_strlen
(title) + 2;
89
pad = (b->
w
- title_len - 2) / 2;
90
print_at
(b->
y
, b->
x
, b->
color
);
91
write(STDOUT_FILENO,
BOX_TL
, 3);
92
draw_hline
(pad, b->
color
);
93
ft_printf(
" %s%s%s "
,
BOLD
, title,
RESET
);
94
ft_printf(
"%s"
, b->
color
);
95
draw_hline
(b->
w
- 2 - title_len - pad, b->
color
);
96
write(STDOUT_FILENO,
BOX_TR
, 3);
97
ft_printf(
"%s"
,
RESET
);
98
}
draw_box_bottom
void draw_box_bottom(t_box *b)
Draw the bottom border of a box.
Definition:
drawing_box.c:34
draw_box_top
static void draw_box_top(t_box *b)
Draw the top border of a box.
Definition:
drawing_box.c:20
draw_box_title
void draw_box_title(t_box *b, const char *title)
Draw the top border of a box with title in the center.
Definition:
drawing_box.c:83
draw_box_sides
void draw_box_sides(t_box *b)
Draw the left and right borders of a box.
Definition:
drawing_box.c:48
draw_box
void draw_box(t_box *b)
Draw a complete box.
Definition:
drawing_box.c:70
visual_strlen
int visual_strlen(const char *s)
Calculate the visual display width of a UTF-8 string in terminal cols.
Definition:
drawing_text.c:75
draw_hline
void draw_hline(int width, const char *color)
Draw a horizontal line of dashes with optional color.
Definition:
drawing_utils.c:33
print_at
void print_at(int row, int col, const char *str)
Move the terminal cursor to [row, col] and write str.
Definition:
drawing_utils.c:22
minishell_ui.h
UI mode structures, macros & function prototypes.
BOX_TL
#define BOX_TL
Definition:
minishell_ui.h:68
BOX_BL
#define BOX_BL
Definition:
minishell_ui.h:70
BOLD
#define BOLD
Definition:
minishell_ui.h:38
BOX_V
#define BOX_V
Definition:
minishell_ui.h:73
BOX_TR
#define BOX_TR
Definition:
minishell_ui.h:69
RESET
#define RESET
Definition:
minishell_ui.h:37
BOX_BR
#define BOX_BR
Definition:
minishell_ui.h:71
t_box
Box position & style for drawing.
Definition:
minishell_ui.h:115
t_box::x
int x
Left col.
Definition:
minishell_ui.h:117
t_box::h
int h
Height in rows.
Definition:
minishell_ui.h:118
t_box::w
int w
Width in cols.
Definition:
minishell_ui.h:119
t_box::y
int y
Top row.
Definition:
minishell_ui.h:116
t_box::color
const char * color
ANSI color str.
Definition:
minishell_ui.h:120
src
ui
draw
drawing_box.c
MiniDEVIL
— generated by Doxygen 1.9.1