MiniDevil As beautiful as a shell
output.c
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* output.c :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: baelgadi <baelgadi@student.42.fr> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2026/02/17 17:13:48 by zotaj-di #+# #+# */
9 /* Updated: 2026/03/04 02:09:02 by baelgadi ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #include "minishell_ui.h"
14 
23 void out_add_line(t_out *out, const char *line)
24 {
25  if (out->count < MAX_LINES)
26  {
27  out->lines[out->count] = ft_strdup(line);
28  out->count++;
29  }
30 }
31 
37 void out_clear(t_out *out)
38 {
39  int i;
40 
41  i = 0;
42  while (i < out->count)
43  {
44  free(out->lines[i]);
45  out->lines[i] = NULL;
46  i++;
47  }
48  out->count = 0;
49  out->scroll = 0;
50 }
51 
57 void out_free(t_out *out)
58 {
59  out_clear(out);
60  free(out->lines);
61 }
62 
69 {
70  out_add_line(&ui->out, "");
71  out_add_line(&ui->out, " ╔══════════════════════════════════════════╗");
72  out_add_line(&ui->out, " ║ ║");
73  out_add_line(&ui->out, " ║ Welcome to Minishell UI! ║");
74  out_add_line(&ui->out, " ║ ║");
75  out_add_line(&ui->out, " ║ • Type commands and press Enter ║");
76  out_add_line(&ui->out, " ║ • Press Ctrl-D to exit ║");
77  out_add_line(&ui->out, " ║ • Type 'clear' to clear output ║");
78  out_add_line(&ui->out, " ║ ║");
79  out_add_line(&ui->out, " ╚══════════════════════════════════════════╝");
80  out_add_line(&ui->out, "");
81 }
UI mode structures, macros & function prototypes.
#define MAX_LINES
Definition: minishell_ui.h:85
void out_free(t_out *out)
Clear all output lines and free the lines pointer array.
Definition: output.c:57
void out_clear(t_out *out)
Free stored output lines and reset the scroll state.
Definition: output.c:37
void out_add_line(t_out *out, const char *line)
Append a duplicate of a line to the output buffer.
Definition: output.c:23
void add_welcome_msg(t_ui *ui)
Fill the output buffer w/ an introductory welcome banner.
Definition: output.c:68
Output display state.
Definition: minishell_ui.h:147
char ** lines
Array of output lines.
Definition: minishell_ui.h:148
int scroll
Current scroll's offset.
Definition: minishell_ui.h:150
int count
Nbr of stored lines.
Definition: minishell_ui.h:149
UI state.
Definition: minishell_ui.h:167
t_out out
Output state.
Definition: minishell_ui.h:170