13 #ifndef MINISHELL_UI_H
14 # define MINISHELL_UI_H
16 # include <sys/ioctl.h>
20 # include "ft_printf.h"
28 # define ESC_SEQ "\033["
29 # define CLEAR_SCREEN "\033[2J\033[H"
30 # define CLEAR_LINE "\033[2K"
31 # define CURSOR_HIDE "\033[?25l"
32 # define CURSOR_SHOW "\033[?25h"
33 # define SAVE_CURSOR "\033[s"
34 # define RESTORE_CURSOR "\033[u"
37 # define RESET "\033[0m"
38 # define BOLD "\033[1m"
39 # define DIM "\033[2m"
42 # define CYAN "\033[38;5;51m"
43 # define PURPLE "\033[38;5;141m"
44 # define GREEN "\033[38;5;47m"
45 # define RED "\033[38;5;196m"
46 # define YELLOW "\033[38;5;226m"
47 # define WHITE "\033[38;5;231m"
48 # define GRAY "\033[38;5;240m"
51 # define C_FIRE1 "\033[38;5;196m"
52 # define C_FIRE2 "\033[38;5;202m"
53 # define C_FIRE3 "\033[38;5;208m"
54 # define C_FIRE4 "\033[38;5;214m"
55 # define C_FIRE5 "\033[38;5;220m"
58 # define C_BLOOD1 "\033[38;5;52m"
59 # define C_BLOOD2 "\033[38;5;88m"
60 # define C_BLOOD3 "\033[38;5;124m"
61 # define C_BLOOD4 "\033[38;5;160m"
62 # define C_BLOOD5 "\033[38;5;196m"
79 # define CMD_BOX_HEIGHT 3
80 # define WAIFU_BOX_W 24
83 # define MIN_HEIGHT 24
84 # define MAX_CMD_LEN 1024
85 # define MAX_LINES 1000
86 # define BUF_SIZE 4096
89 # define MINISHELL_PATH "./minishell"
94 # define KEY_BACKSPACE 127
98 # define KEY_DOWN 1002
99 # define KEY_LEFT 1003
100 # define KEY_RIGHT 1004
103 # define MOOD_HAPPY 0
104 # define MOOD_UPSET 1
105 # define MOOD_PROUD 2
126 typedef struct s_term
157 typedef struct s_waifu
221 void print_at(
int row,
int col,
const char *str);
223 void draw_hline(
int width,
const char *color);
void set_raw_mode(t_term *term)
Switch the terminal into non canonical and no echo mode.
void out_free(t_out *out)
Clear all output lines and free the lines pointer array.
void out_clear(t_out *out)
Free stored output lines and reset the scroll state.
void init_term(t_ui *ui)
Prepare the terminal and UI state for the main event.
void draw_box_bottom(t_box *b)
Draw the bottom border of a box.
void cleanup_term(t_ui *ui)
Clean up the UI terminal state and free output memory.
void out_add_line(t_out *out, const char *line)
Append a duplicate of a line to the output buffer.
int process_ui_input(char *input, t_shell *shell)
Full pipeline inside the UI.
void draw_hline(int width, const char *color)
Draw a horizontal line of dashes with optional color.
void redraw_cmd_only(t_ui *ui)
Redraws only the command input line.
void restore_term_mode(t_term *term)
Restore the terminal to the saved settings.
void execute_minishell_cmd(t_shell *shell)
Fork a child to execute a minishell command & capture its output.
void cmd_del_char(t_cmd *cmd)
Remove the last character from the command buffer.
void print_goodbye(void)
Print the exit banner to STDOUT.
void ft_msleep(int ms)
Sleep for approximately ms millisecondes using a little trick.
void handle_key(t_shell *shell, int key)
Dispatch key code to the appropriate UI action.
void add_welcome_msg(t_ui *ui)
Fill the output buffer w/ an introductory welcome banner.
void setup_ui_signals(void)
Set up SIGWINCH and SIGINT handlers for the UI loop.
char * truncate_line(const char *line, int max_w)
Copy up to max_width visible characters into a static buffer.
int visual_strlen(const char *s)
Calculate the visual display width of a UTF-8 string in terminal cols.
void draw_exit_box(t_ui *ui)
Draw the exit code status box (right sidebare, below waifu)
void draw_cmd_box(t_ui *ui)
Draw the command input box (top left of the UI)
void cmd_add_char(t_cmd *cmd, char c)
Append a printable character to the command buffer.
void draw_happy(int y, int x)
Draw happy Neko chan ASCII art.
void read_output_from_fd(t_ui *ui, int fd)
Read all available bytes from fd and split into output lines.
void cmd_execute(t_shell *shell)
Execute the current command buffer & reset it.
void redraw_output_only(t_ui *ui)
Redraw only the output box interior rows without borders nor title.
void draw_ui(t_ui *ui)
Clear the screen and redraw the UI from scratch.
void get_term_size(t_term *term)
Get the terinal dimensions via ioctl and store them.
void update_waifu_mood(t_ui *ui, int mood)
Set the waifu mood.
int read_key(void)
Read 1 keypress or escape sequence from STDIN.
void draw_box_title(t_box *b, const char *title)
Draw the top border of a box with title in the center.
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.
void draw_box_sides(t_box *b)
Draw the left and right borders of a box.
void draw_upset(int y, int x)
Draw upset Neko chan ASCII art.
void draw_box(t_box *b)
Draw a complete box.
void draw_proud(int y, int x)
Draw proud Neko chan ASCII art.
void run_ui_mode(t_shell *shell)
Entry point for UI mode.
void draw_welcome(void)
Draw complete welcome animation sequence and clean up.
void draw_waifu_box(t_ui *ui)
Draw the waifu panel in the right sidebar.
void print_at(int row, int col, const char *str)
Move the terminal cursor to [row, col] and write str.
Signal handler prototypes.
Central type definitions for mandatory part.
Box position & style for drawing.
const char * color
ANSI color str.
int cursor
Cursor position.
int len
Current input length.
char ** lines
Array of output lines.
int scroll
Current scroll's offset.
int exit_code
Last command exit code.
int count
Nbr of stored lines.
Terminal dimensions & saved state.
int running
Event loop flag.
t_waifu waifu
Waifu state.
t_term term
Terminal state.
int blink
!wip Blink animation state