MiniDevil As beautiful as a shell
terminal.c
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* terminal.c :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: baelgadi <baelgadi@student.42.fr> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2026/02/17 17:48:16 by zotaj-di #+# #+# */
9 /* Updated: 2026/03/04 02:12:25 by baelgadi ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #include "minishell_ui.h"
14 
22 void get_term_size(t_term *term)
23 {
24  struct winsize ws;
25 
26  if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0)
27  {
28  term->width = ws.ws_col;
29  term->height = ws.ws_row;
30  }
31  else
32  {
33  term->width = 80;
34  term->height = 24;
35  }
36 }
37 
46 void set_raw_mode(t_term *term)
47 {
48  struct termios raw;
49 
50  tcgetattr(STDIN_FILENO, &term->orig);
51  raw = term->orig;
52  raw.c_lflag &= ~(ECHO | ICANON);
53  raw.c_cc[VMIN] = 1;
54  raw.c_cc[VTIME] = 0;
55  tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
56 }
57 
64 {
65  tcsetattr(STDIN_FILENO, TCSAFLUSH, &term->orig);
66 }
67 
71 void print_goodbye(void)
72 {
73  ft_printf("\n" PURPLE BOLD);
74  ft_printf("╔════════════════════════════════════════╗\n");
75  ft_printf("║ ║\n");
76  ft_printf("║ See you next time ! ║\n");
77  ft_printf("║ ║\n");
78  ft_printf("╚════════════════════════════════════════╝\n" RESET "\n");
79 }
UI mode structures, macros & function prototypes.
#define PURPLE
Definition: minishell_ui.h:43
#define BOLD
Definition: minishell_ui.h:38
#define RESET
Definition: minishell_ui.h:37
Terminal dimensions & saved state.
Definition: minishell_ui.h:127
struct termios orig
Original termios settings.
Definition: minishell_ui.h:130
int width
Cols.
Definition: minishell_ui.h:128
int height
Rows.
Definition: minishell_ui.h:129
void set_raw_mode(t_term *term)
Switch the terminal into non canonical and no echo mode.
Definition: terminal.c:46
void restore_term_mode(t_term *term)
Restore the terminal to the saved settings.
Definition: terminal.c:63
void print_goodbye(void)
Print the exit banner to STDOUT.
Definition: terminal.c:71
void get_term_size(t_term *term)
Get the terinal dimensions via ioctl and store them.
Definition: terminal.c:22