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 
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 
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 }
void draw_box_bottom(t_box *b)
Draw the bottom border of a box.
Definition: drawing_box.c:34
static void draw_box_top(t_box *b)
Draw the top border of a box.
Definition: drawing_box.c:20
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
void draw_box_sides(t_box *b)
Draw the left and right borders of a box.
Definition: drawing_box.c:48
void draw_box(t_box *b)
Draw a complete box.
Definition: drawing_box.c:70
int visual_strlen(const char *s)
Calculate the visual display width of a UTF-8 string in terminal cols.
Definition: drawing_text.c:75
void draw_hline(int width, const char *color)
Draw a horizontal line of dashes with optional color.
Definition: drawing_utils.c:33
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
UI mode structures, macros & function prototypes.
#define BOX_TL
Definition: minishell_ui.h:68
#define BOX_BL
Definition: minishell_ui.h:70
#define BOLD
Definition: minishell_ui.h:38
#define BOX_V
Definition: minishell_ui.h:73
#define BOX_TR
Definition: minishell_ui.h:69
#define RESET
Definition: minishell_ui.h:37
#define BOX_BR
Definition: minishell_ui.h:71
Box position & style for drawing.
Definition: minishell_ui.h:115
int x
Left col.
Definition: minishell_ui.h:117
int h
Height in rows.
Definition: minishell_ui.h:118
int w
Width in cols.
Definition: minishell_ui.h:119
int y
Top row.
Definition: minishell_ui.h:116
const char * color
ANSI color str.
Definition: minishell_ui.h:120