MiniDevil As beautiful as a shell
drawing_output.c
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* drawing_output.c :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: baelgadi <baelgadi@student.42.fr> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2026/02/17 17:49:01 by zotaj-di #+# #+# */
9 /* Updated: 2026/03/04 03:28:23 by baelgadi ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #include "minishell_ui.h"
14 
25 static void draw_line_content(t_ui *ui, int line_idx, int w)
26 {
27  char *line;
28  int clear_len;
29 
30  if (line_idx < ui->out.count && ui->out.lines[line_idx])
31  {
32  line = truncate_line(ui->out.lines[line_idx], w - 4);
33  ft_printf("%s", line);
34  clear_len = w - 3 - (int)ft_strlen(line);
35  if (clear_len > 0)
36  {
37  while (clear_len-- > 0)
38  write(STDOUT_FILENO, " ", 1);
39  }
40  }
41  else
42  {
43  clear_len = w - 3;
44  while (clear_len-- > 0)
45  write(STDOUT_FILENO, " ", 1);
46  }
47 }
48 
57 void draw_out_line(t_ui *ui, int y, int i, int w)
58 {
59  int line_idx;
60 
61  line_idx = ui->out.scroll + i;
62  print_at(y + 1 + i, 2, C_FIRE2);
63  write(STDOUT_FILENO, BOX_V, 3);
64  write(STDOUT_FILENO, RESET, ft_strlen(RESET));
65  write(STDOUT_FILENO, " ", 1);
66  draw_line_content(ui, line_idx, w);
67  print_at(y + 1 + i, 2 + w - 1, C_FIRE2);
68  write(STDOUT_FILENO, BOX_V, 3);
69  write(STDOUT_FILENO, RESET, ft_strlen(RESET));
70 }
71 
79 void draw_out_box(t_ui *ui)
80 {
81  t_box b;
82  int i;
83 
84  b.y = 5;
85  b.x = 2;
86  b.h = ui->term.height - 5 - 2;
87  b.w = ui->term.width - WAIFU_BOX_W - 4;
88  b.color = C_FIRE2;
89  draw_box_title(&b, "Output");
90  i = 0;
91  while (i < b.h - 2)
92  {
93  draw_out_line(ui, b.y, i, b.w);
94  i++;
95  }
96  draw_box_bottom(&b);
97 }
98 
107 {
108  int y;
109  int w;
110  int h;
111  int i;
112 
113  y = 5;
114  w = ui->term.width - WAIFU_BOX_W - 4;
115  h = ui->term.height - 5 - 2;
116  i = 0;
117  while (i < h - 2)
118  {
119  draw_out_line(ui, y, i, w);
120  i++;
121  }
122 }
void draw_box_bottom(t_box *b)
Draw the bottom border of a box.
Definition: drawing_box.c:34
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
static void draw_line_content(t_ui *ui, int line_idx, int w)
Write a single scrolled output line's content to STDOUT.
void redraw_output_only(t_ui *ui)
Redraw only the output box interior rows without borders nor title.
void draw_out_line(t_ui *ui, int y, int i, int w)
Draw one raw inside the output box (including the side borders)
void draw_out_box(t_ui *ui)
Draw the full output box with title and borders.
char * truncate_line(const char *line, int max_width)
Copy up to max_width visible characters into a static buffer.
Definition: drawing_text.c:42
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_V
Definition: minishell_ui.h:73
#define C_FIRE2
Definition: minishell_ui.h:52
#define RESET
Definition: minishell_ui.h:37
#define WAIFU_BOX_W
Definition: minishell_ui.h:80
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
char ** lines
Array of output lines.
Definition: minishell_ui.h:148
int scroll
Current scroll's offset.
Definition: minishell_ui.h:150
int width
Cols.
Definition: minishell_ui.h:128
int height
Rows.
Definition: minishell_ui.h:129
UI state.
Definition: minishell_ui.h:167
t_out out
Output state.
Definition: minishell_ui.h:170
t_term term
Terminal state.
Definition: minishell_ui.h:168