MiniDevil As beautiful as a shell
minishell_ui.h File Reference

UI mode structures, macros & function prototypes. More...

#include <sys/ioctl.h>
#include <termios.h>
#include "structs.h"
#include "libft.h"
#include "ft_printf.h"
#include "signals.h"
+ Include dependency graph for minishell_ui.h:
+ This graph shows which files directly or indirectly include this file:

Detailed Description

UI mode structures, macros & function prototypes.

Definition in file minishell_ui.h.

Macros

#define ESC_SEQ   "\033["
 
#define CLEAR_SCREEN   "\033[2J\033[H"
 
#define CLEAR_LINE   "\033[2K"
 
#define CURSOR_HIDE   "\033[?25l"
 
#define CURSOR_SHOW   "\033[?25h"
 
#define SAVE_CURSOR   "\033[s"
 
#define RESTORE_CURSOR   "\033[u"
 
#define RESET   "\033[0m"
 
#define BOLD   "\033[1m"
 
#define DIM   "\033[2m"
 
#define CYAN   "\033[38;5;51m"
 
#define PURPLE   "\033[38;5;141m"
 
#define GREEN   "\033[38;5;47m"
 
#define RED   "\033[38;5;196m"
 
#define YELLOW   "\033[38;5;226m"
 
#define WHITE   "\033[38;5;231m"
 
#define GRAY   "\033[38;5;240m"
 
#define C_FIRE1   "\033[38;5;196m"
 
#define C_FIRE2   "\033[38;5;202m"
 
#define C_FIRE3   "\033[38;5;208m"
 
#define C_FIRE4   "\033[38;5;214m"
 
#define C_FIRE5   "\033[38;5;220m"
 
#define C_BLOOD1   "\033[38;5;52m"
 
#define C_BLOOD2   "\033[38;5;88m"
 
#define C_BLOOD3   "\033[38;5;124m"
 
#define C_BLOOD4   "\033[38;5;160m"
 
#define C_BLOOD5   "\033[38;5;196m"
 
#define BOX_TL   "╭"
 
#define BOX_TR   "╮"
 
#define BOX_BL   "╰"
 
#define BOX_BR   "╯"
 
#define BOX_H   "─"
 
#define BOX_V   "│"
 
#define CMD_BOX_HEIGHT   3
 
#define WAIFU_BOX_W   24
 
#define EXIT_BOX_H   3
 
#define MIN_WIDTH   80
 
#define MIN_HEIGHT   24
 
#define MAX_CMD_LEN   1024
 
#define MAX_LINES   1000
 
#define BUF_SIZE   4096
 
#define MINISHELL_PATH   "./minishell"
 
#define KEY_ESC   27
 
#define KEY_ENTER   10
 
#define KEY_BACKSPACE   127
 
#define KEY_CTRL_D   4
 
#define KEY_CTRL_C   3
 
#define KEY_UP   1001
 
#define KEY_DOWN   1002
 
#define KEY_LEFT   1003
 
#define KEY_RIGHT   1004
 
#define MOOD_HAPPY   0
 
#define MOOD_UPSET   1
 
#define MOOD_PROUD   2
 

Functions

void run_ui_mode (t_shell *shell)
 Entry point for UI mode. More...
 
void init_term (t_ui *ui)
 Prepare the terminal and UI state for the main event. More...
 
void cleanup_term (t_ui *ui)
 Clean up the UI terminal state and free output memory. More...
 
void get_term_size (t_term *term)
 Get the terinal dimensions via ioctl and store them. More...
 
void set_raw_mode (t_term *term)
 Switch the terminal into non canonical and no echo mode. More...
 
void restore_term_mode (t_term *term)
 Restore the terminal to the saved settings. More...
 
void print_goodbye (void)
 Print the exit banner to STDOUT. More...
 
void setup_ui_signals (void)
 Set up SIGWINCH and SIGINT handlers for the UI loop. More...
 
void out_add_line (t_out *out, const char *line)
 Append a duplicate of a line to the output buffer. More...
 
void out_clear (t_out *out)
 Free stored output lines and reset the scroll state. More...
 
void out_free (t_out *out)
 Clear all output lines and free the lines pointer array. More...
 
void add_welcome_msg (t_ui *ui)
 Fill the output buffer w/ an introductory welcome banner. More...
 
void update_waifu_mood (t_ui *ui, int mood)
 Set the waifu mood. More...
 
void draw_waifu_box (t_ui *ui)
 Draw the waifu panel in the right sidebar. More...
 
void print_at (int row, int col, const char *str)
 Move the terminal cursor to [row, col] and write str. More...
 
void draw_hline (int width, const char *color)
 Draw a horizontal line of dashes with optional color. More...
 
char * truncate_line (const char *line, int max_w)
 Copy up to max_width visible characters into a static buffer. More...
 
int visual_strlen (const char *s)
 Calculate the visual display width of a UTF-8 string in terminal cols. More...
 
void draw_box (t_box *b)
 Draw a complete box. More...
 
void draw_box_title (t_box *b, const char *title)
 Draw the top border of a box with title in the center. More...
 
void draw_box_sides (t_box *b)
 Draw the left and right borders of a box. More...
 
void draw_box_bottom (t_box *b)
 Draw the bottom border of a box. More...
 
void draw_ui (t_ui *ui)
 Clear the screen and redraw the UI from scratch. More...
 
void draw_cmd_box (t_ui *ui)
 Draw the command input box (top left of the UI) More...
 
void draw_exit_box (t_ui *ui)
 Draw the exit code status box (right sidebare, below waifu) More...
 
void redraw_cmd_only (t_ui *ui)
 Redraws only the command input line. More...
 
void draw_out_line (t_ui *ui, int y, int i, int w)
 Draw one raw inside the output box (including the side borders) More...
 
void draw_out_box (t_ui *ui)
 Draw the full output box with title and borders. More...
 
void redraw_output_only (t_ui *ui)
 Redraw only the output box interior rows without borders nor title. More...
 
int read_key (void)
 Read 1 keypress or escape sequence from STDIN. More...
 
void cmd_add_char (t_cmd *cmd, char c)
 Append a printable character to the command buffer. More...
 
void cmd_del_char (t_cmd *cmd)
 Remove the last character from the command buffer. More...
 
void handle_key (t_shell *shell, int key)
 Dispatch key code to the appropriate UI action. More...
 
void cmd_execute (t_shell *shell)
 Execute the current command buffer & reset it. More...
 
void execute_minishell_cmd (t_shell *shell)
 Fork a child to execute a minishell command & capture its output. More...
 
void read_output_from_fd (t_ui *ui, int fd)
 Read all available bytes from fd and split into output lines. More...
 
int process_ui_input (char *input, t_shell *shell)
 Full pipeline inside the UI. More...
 
void ft_msleep (int ms)
 Sleep for approximately ms millisecondes using a little trick. More...
 
void draw_welcome (void)
 Draw complete welcome animation sequence and clean up. More...
 
void draw_happy (int y, int x)
 Draw happy Neko chan ASCII art. More...
 
void draw_upset (int y, int x)
 Draw upset Neko chan ASCII art. More...
 
void draw_proud (int y, int x)
 Draw proud Neko chan ASCII art. More...
 

Macro Documentation

◆ ESC_SEQ

#define ESC_SEQ   "\033["

Definition at line 28 of file minishell_ui.h.

◆ CLEAR_SCREEN

#define CLEAR_SCREEN   "\033[2J\033[H"

Definition at line 29 of file minishell_ui.h.

◆ CLEAR_LINE

#define CLEAR_LINE   "\033[2K"

Definition at line 30 of file minishell_ui.h.

◆ CURSOR_HIDE

#define CURSOR_HIDE   "\033[?25l"

Definition at line 31 of file minishell_ui.h.

◆ CURSOR_SHOW

#define CURSOR_SHOW   "\033[?25h"

Definition at line 32 of file minishell_ui.h.

◆ SAVE_CURSOR

#define SAVE_CURSOR   "\033[s"

Definition at line 33 of file minishell_ui.h.

◆ RESTORE_CURSOR

#define RESTORE_CURSOR   "\033[u"

Definition at line 34 of file minishell_ui.h.

◆ RESET

#define RESET   "\033[0m"

Definition at line 37 of file minishell_ui.h.

◆ BOLD

#define BOLD   "\033[1m"

Definition at line 38 of file minishell_ui.h.

◆ DIM

#define DIM   "\033[2m"

Definition at line 39 of file minishell_ui.h.

◆ CYAN

#define CYAN   "\033[38;5;51m"

Definition at line 42 of file minishell_ui.h.

◆ PURPLE

#define PURPLE   "\033[38;5;141m"

Definition at line 43 of file minishell_ui.h.

◆ GREEN

#define GREEN   "\033[38;5;47m"

Definition at line 44 of file minishell_ui.h.

◆ RED

#define RED   "\033[38;5;196m"

Definition at line 45 of file minishell_ui.h.

◆ YELLOW

#define YELLOW   "\033[38;5;226m"

Definition at line 46 of file minishell_ui.h.

◆ WHITE

#define WHITE   "\033[38;5;231m"

Definition at line 47 of file minishell_ui.h.

◆ GRAY

#define GRAY   "\033[38;5;240m"

Definition at line 48 of file minishell_ui.h.

◆ C_FIRE1

#define C_FIRE1   "\033[38;5;196m"

Definition at line 51 of file minishell_ui.h.

◆ C_FIRE2

#define C_FIRE2   "\033[38;5;202m"

Definition at line 52 of file minishell_ui.h.

◆ C_FIRE3

#define C_FIRE3   "\033[38;5;208m"

Definition at line 53 of file minishell_ui.h.

◆ C_FIRE4

#define C_FIRE4   "\033[38;5;214m"

Definition at line 54 of file minishell_ui.h.

◆ C_FIRE5

#define C_FIRE5   "\033[38;5;220m"

Definition at line 55 of file minishell_ui.h.

◆ C_BLOOD1

#define C_BLOOD1   "\033[38;5;52m"

Definition at line 58 of file minishell_ui.h.

◆ C_BLOOD2

#define C_BLOOD2   "\033[38;5;88m"

Definition at line 59 of file minishell_ui.h.

◆ C_BLOOD3

#define C_BLOOD3   "\033[38;5;124m"

Definition at line 60 of file minishell_ui.h.

◆ C_BLOOD4

#define C_BLOOD4   "\033[38;5;160m"

Definition at line 61 of file minishell_ui.h.

◆ C_BLOOD5

#define C_BLOOD5   "\033[38;5;196m"

Definition at line 62 of file minishell_ui.h.

◆ BOX_TL

#define BOX_TL   "╭"

Definition at line 68 of file minishell_ui.h.

◆ BOX_TR

#define BOX_TR   "╮"

Definition at line 69 of file minishell_ui.h.

◆ BOX_BL

#define BOX_BL   "╰"

Definition at line 70 of file minishell_ui.h.

◆ BOX_BR

#define BOX_BR   "╯"

Definition at line 71 of file minishell_ui.h.

◆ BOX_H

#define BOX_H   "─"

Definition at line 72 of file minishell_ui.h.

◆ BOX_V

#define BOX_V   "│"

Definition at line 73 of file minishell_ui.h.

◆ CMD_BOX_HEIGHT

#define CMD_BOX_HEIGHT   3

Definition at line 79 of file minishell_ui.h.

◆ WAIFU_BOX_W

#define WAIFU_BOX_W   24

Definition at line 80 of file minishell_ui.h.

◆ EXIT_BOX_H

#define EXIT_BOX_H   3

Definition at line 81 of file minishell_ui.h.

◆ MIN_WIDTH

#define MIN_WIDTH   80

Definition at line 82 of file minishell_ui.h.

◆ MIN_HEIGHT

#define MIN_HEIGHT   24

Definition at line 83 of file minishell_ui.h.

◆ MAX_CMD_LEN

#define MAX_CMD_LEN   1024

Definition at line 84 of file minishell_ui.h.

◆ MAX_LINES

#define MAX_LINES   1000

Definition at line 85 of file minishell_ui.h.

◆ BUF_SIZE

#define BUF_SIZE   4096

Definition at line 86 of file minishell_ui.h.

◆ MINISHELL_PATH

#define MINISHELL_PATH   "./minishell"

Definition at line 89 of file minishell_ui.h.

◆ KEY_ESC

#define KEY_ESC   27

Definition at line 92 of file minishell_ui.h.

◆ KEY_ENTER

#define KEY_ENTER   10

Definition at line 93 of file minishell_ui.h.

◆ KEY_BACKSPACE

#define KEY_BACKSPACE   127

Definition at line 94 of file minishell_ui.h.

◆ KEY_CTRL_D

#define KEY_CTRL_D   4

Definition at line 95 of file minishell_ui.h.

◆ KEY_CTRL_C

#define KEY_CTRL_C   3

Definition at line 96 of file minishell_ui.h.

◆ KEY_UP

#define KEY_UP   1001

Definition at line 97 of file minishell_ui.h.

◆ KEY_DOWN

#define KEY_DOWN   1002

Definition at line 98 of file minishell_ui.h.

◆ KEY_LEFT

#define KEY_LEFT   1003

Definition at line 99 of file minishell_ui.h.

◆ KEY_RIGHT

#define KEY_RIGHT   1004

Definition at line 100 of file minishell_ui.h.

◆ MOOD_HAPPY

#define MOOD_HAPPY   0

Definition at line 103 of file minishell_ui.h.

◆ MOOD_UPSET

#define MOOD_UPSET   1

Definition at line 104 of file minishell_ui.h.

◆ MOOD_PROUD

#define MOOD_PROUD   2

Definition at line 105 of file minishell_ui.h.

Function Documentation

◆ run_ui_mode()

void run_ui_mode ( t_shell shell)

Entry point for UI mode.

Return silently if shell is NULL, not a tty or terminal is too small

Parameters
shellShell state

Definition at line 91 of file ui_main.c.

References cleanup_term(), init_ui(), MIN_HEIGHT, MIN_WIDTH, print_goodbye(), t_shell::ui, ui_loop(), and t_shell::ui_mode.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_term()

void init_term ( t_ui ui)

Prepare the terminal and UI state for the main event.

  • Get terminal size, enable raw mode, hide cursor and clean screen
  • Call init_ui_state() to inialize the rest of the UI struct to 0
Parameters
ui

Definition at line 51 of file terminal_init.c.

References CLEAR_SCREEN, CURSOR_HIDE, get_term_size(), init_ui_state(), set_raw_mode(), and t_ui::term.

Referenced by init_ui().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cleanup_term()

void cleanup_term ( t_ui ui)

Clean up the UI terminal state and free output memory.

  • Clear the screen, restore cursor and restore original terminal mode
  • Free output lines array via out_free
Parameters
ui

Definition at line 68 of file terminal_init.c.

References CLEAR_SCREEN, CURSOR_SHOW, t_ui::out, out_free(), restore_term_mode(), and t_ui::term.

Referenced by run_ui_mode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_term_size()

void get_term_size ( t_term term)

Get the terinal dimensions via ioctl and store them.

Fallback is 80x24 (default) in case ioctl fails

Parameters
termTerminal state to fill with width and height

Definition at line 22 of file terminal.c.

References t_term::height, and t_term::width.

Referenced by check_resize(), and init_term().

+ Here is the caller graph for this function:

◆ set_raw_mode()

void set_raw_mode ( t_term term)

Switch the terminal into non canonical and no echo mode.

  • Save original termios settings in term->orig for later
  • Disable ECHO and ICANON & set VMIN = 1 and VTIME = 0
Parameters
termTerminal state (original is saved before modification)

Definition at line 46 of file terminal.c.

References t_term::orig.

Referenced by init_term().

+ Here is the caller graph for this function:

◆ restore_term_mode()

void restore_term_mode ( t_term term)

Restore the terminal to the saved settings.

Parameters
termTerminal state (holds the saved orig termios)

Definition at line 63 of file terminal.c.

References t_term::orig.

Referenced by cleanup_term().

+ Here is the caller graph for this function:

◆ print_goodbye()

void print_goodbye ( void  )

Print the exit banner to STDOUT.

Definition at line 71 of file terminal.c.

References BOLD, PURPLE, and RESET.

Referenced by run_ui_mode().

+ Here is the caller graph for this function:

◆ setup_ui_signals()

void setup_ui_signals ( void  )

Set up SIGWINCH and SIGINT handlers for the UI loop.

  • SIGWINCH is handled by handle_ui_sigwinch() with SA_RESTART
  • SIGINT is ignored so CTRL C doesn't kill the UI

Definition at line 31 of file ui_signals.c.

References handle_ui_sigwinch().

Referenced by init_ui().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ out_add_line()

void out_add_line ( t_out out,
const char *  line 
)

Append a duplicate of a line to the output buffer.

Do nothing if the buffers already reached MAX_LINES

Parameters
outOutput to append to
lineString to store

Definition at line 23 of file output.c.

References t_out::count, t_out::lines, and MAX_LINES.

Referenced by add_welcome_msg(), handle_fork_error(), init_pipe_and_fds(), process_output_char(), and read_output_from_fd().

+ Here is the caller graph for this function:

◆ out_clear()

void out_clear ( t_out out)

Free stored output lines and reset the scroll state.

Parameters
outOutput state to clear

Definition at line 37 of file output.c.

References t_out::count, t_out::lines, and t_out::scroll.

Referenced by cmd_execute(), exec_ui_builtin(), and out_free().

+ Here is the caller graph for this function:

◆ out_free()

void out_free ( t_out out)

Clear all output lines and free the lines pointer array.

Parameters
outOutput to release

Definition at line 57 of file output.c.

References t_out::lines, and out_clear().

Referenced by cleanup_term(), and exec_child().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ add_welcome_msg()

void add_welcome_msg ( t_ui ui)

Fill the output buffer w/ an introductory welcome banner.

Parameters
uiUI state for which output buffer receives the banner

Definition at line 68 of file output.c.

References t_ui::out, and out_add_line().

Referenced by ui_loop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update_waifu_mood()

void update_waifu_mood ( t_ui ui,
int  mood 
)

Set the waifu mood.

Parameters
uiUI state
moodNew mood value

Definition at line 21 of file waifu.c.

References t_waifu::mood, and t_ui::waifu.

Referenced by cmd_execute(), exec_parent(), execute_minishell_cmd(), handle_fork_error(), and init_pipe_and_fds().

+ Here is the caller graph for this function:

◆ draw_waifu_box()

void draw_waifu_box ( t_ui ui)

Draw the waifu panel in the right sidebar.

Parameters
uiUI state

Definition at line 48 of file waifu.c.

References C_FIRE4, t_box::color, draw_box_bottom(), draw_box_sides(), draw_box_title(), t_box::h, render_waifu_mood(), t_ui::term, t_box::w, WAIFU_BOX_W, t_term::width, t_box::x, and t_box::y.

Referenced by draw_ui().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ print_at()

void print_at ( int  row,
int  col,
const char *  str 
)

Move the terminal cursor to [row, col] and write str.

Parameters
rowTarget row (starting at 1)
colTarget colum (starting at 1)
strString to print

Definition at line 22 of file drawing_utils.c.

Referenced by draw_box_bottom(), draw_box_sides(), draw_box_title(), draw_box_top(), draw_cmd_box(), draw_exit_box(), draw_happy(), draw_out_line(), draw_proud(), draw_upset(), and redraw_cmd_only().

+ Here is the caller graph for this function:

◆ draw_hline()

void draw_hline ( int  width,
const char *  color 
)

Draw a horizontal line of dashes with optional color.

Parameters
widthNumber of dash characters to write
colorANSI color escape string to apply

Definition at line 33 of file drawing_utils.c.

References RESET.

Referenced by draw_box_bottom(), draw_box_title(), and draw_box_top().

+ Here is the caller graph for this function:

◆ truncate_line()

char* truncate_line ( const char *  line,
int  max_width 
)

Copy up to max_width visible characters into a static buffer.

Handles UTF-8 sequences

Parameters
lineSource string to truncate (could be NULL)
max_widthMaximum number to include
Returns
Pointer to static buffer holding the truncated result
Note
The static buffer gets overwritten on every call

Definition at line 42 of file drawing_text.c.

References BUF_SIZE, and utf8_byte_len().

Referenced by draw_line_content().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ visual_strlen()

int visual_strlen ( const char *  s)

Calculate the visual display width of a UTF-8 string in terminal cols.

4 byte (emoji range) are counted as 2 columns, the others as 1

Parameters
sUTF-8 string (NULL terminated)
Returns
Visual column width of the string

Definition at line 75 of file drawing_text.c.

References utf8_byte_len().

Referenced by draw_box_title().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draw_box()

void draw_box ( t_box b)

Draw a complete box.

Parameters
bBox descriptor (with position, width and colors)

Definition at line 70 of file drawing_box.c.

References draw_box_bottom(), draw_box_sides(), and draw_box_top().

Referenced by draw_exit_box().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draw_box_title()

void draw_box_title ( t_box b,
const char *  title 
)

Draw the top border of a box with title in the center.

Parameters
bBox descriptor (with position, width and colors)
titleLabel string to embed in the border

Definition at line 83 of file drawing_box.c.

References BOLD, BOX_TL, BOX_TR, t_box::color, draw_hline(), print_at(), RESET, visual_strlen(), t_box::w, t_box::x, and t_box::y.

Referenced by draw_cmd_box(), draw_out_box(), and draw_waifu_box().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draw_box_sides()

void draw_box_sides ( t_box b)

Draw the left and right borders of a box.

Parameters
bBox descriptor (with position, width and colors)

Definition at line 48 of file drawing_box.c.

References BOX_V, t_box::color, print_at(), RESET, t_box::w, t_box::x, and t_box::y.

Referenced by draw_box(), draw_cmd_box(), and draw_waifu_box().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draw_box_bottom()

void draw_box_bottom ( t_box b)

Draw the bottom border of a box.

Parameters
bBox descriptor (with position, width and colors)

Definition at line 34 of file drawing_box.c.

References BOX_BL, BOX_BR, t_box::color, draw_hline(), t_box::h, print_at(), RESET, t_box::w, t_box::x, and t_box::y.

Referenced by draw_box(), draw_cmd_box(), draw_out_box(), and draw_waifu_box().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draw_ui()

void draw_ui ( t_ui ui)

Clear the screen and redraw the UI from scratch.

Draw all 4 panels: command box, waifu, exit box and output box

Parameters
uiUI state

Definition at line 76 of file drawing.c.

References CLEAR_SCREEN, draw_cmd_box(), draw_exit_box(), draw_out_box(), and draw_waifu_box().

Referenced by check_resize(), and ui_loop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draw_cmd_box()

void draw_cmd_box ( t_ui ui)

Draw the command input box (top left of the UI)

Render a titled box with a block cursor

Parameters
uiUI state

Definition at line 22 of file drawing.c.

References BOLD, t_cmd::buf, C_FIRE3, C_FIRE4, t_ui::cmd, t_box::color, draw_box_bottom(), draw_box_sides(), draw_box_title(), t_box::h, t_cmd::len, print_at(), RESET, t_ui::term, t_box::w, WAIFU_BOX_W, t_term::width, t_box::x, and t_box::y.

Referenced by draw_ui().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draw_exit_box()

void draw_exit_box ( t_ui ui)

Draw the exit code status box (right sidebare, below waifu)

Colours the exit code green on success and red on failure

Parameters
uiUI state

Definition at line 50 of file drawing.c.

References BOLD, C_FIRE1, C_FIRE2, C_FIRE5, t_box::color, draw_box(), EXIT_BOX_H, t_out::exit_code, t_box::h, t_ui::out, print_at(), RESET, t_ui::term, t_box::w, WAIFU_BOX_W, t_term::width, t_box::x, and t_box::y.

Referenced by draw_ui().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ redraw_cmd_only()

void redraw_cmd_only ( t_ui ui)

Redraws only the command input line.

Parameters
uiUI state

Definition at line 90 of file drawing.c.

References BOLD, t_cmd::buf, C_FIRE4, t_ui::cmd, t_cmd::len, print_at(), RESET, t_ui::term, WAIFU_BOX_W, and t_term::width.

Referenced by ui_loop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draw_out_line()

void draw_out_line ( t_ui ui,
int  y,
int  i,
int  w 
)

Draw one raw inside the output box (including the side borders)

Parameters
uiUI state
yTop row of the output box
iRow index within the box (0 based)
wWidth of the output box

Definition at line 57 of file drawing_output.c.

References BOX_V, C_FIRE2, draw_line_content(), t_ui::out, print_at(), RESET, and t_out::scroll.

Referenced by draw_out_box(), and redraw_output_only().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draw_out_box()

void draw_out_box ( t_ui ui)

Draw the full output box with title and borders.

THe box grows to fill the terminal from row 5 to the last 2 rows

Parameters
uiUI state

Definition at line 79 of file drawing_output.c.

References C_FIRE2, t_box::color, draw_box_bottom(), draw_box_title(), draw_out_line(), t_box::h, t_term::height, t_ui::term, t_box::w, WAIFU_BOX_W, t_term::width, t_box::x, and t_box::y.

Referenced by draw_ui().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ redraw_output_only()

void redraw_output_only ( t_ui ui)

Redraw only the output box interior rows without borders nor title.

Used after scroll events in order to refresh content without full redraw

Parameters
uiUI state

Definition at line 106 of file drawing_output.c.

References draw_out_line(), t_term::height, t_ui::term, WAIFU_BOX_W, and t_term::width.

Referenced by handle_scroll().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read_key()

int read_key ( void  )

Read 1 keypress or escape sequence from STDIN.

Returns
int Key code as defined by the KEY_ constants or -1 on error

Definition at line 20 of file input.c.

References KEY_DOWN, KEY_ESC, KEY_LEFT, KEY_RIGHT, and KEY_UP.

Referenced by ui_loop().

+ Here is the caller graph for this function:

◆ cmd_add_char()

void cmd_add_char ( t_cmd cmd,
char  c 
)

Append a printable character to the command buffer.

Does nothing if the buffer could cause an overflow on MAX_CMD_LEN

Parameters
cmdCommand buffer
cCharacter to append

Definition at line 57 of file input.c.

References t_cmd::buf, t_cmd::len, and MAX_CMD_LEN.

Referenced by handle_key().

+ Here is the caller graph for this function:

◆ cmd_del_char()

void cmd_del_char ( t_cmd cmd)

Remove the last character from the command buffer.

Does nothing if the buffer is empty

Parameters
cmdCommand buffer

Definition at line 74 of file input.c.

References t_cmd::buf, and t_cmd::len.

Referenced by handle_key().

+ Here is the caller graph for this function:

◆ handle_key()

void handle_key ( t_shell shell,
int  key 
)

Dispatch key code to the appropriate UI action.

Parameters
shell
key

Definition at line 119 of file input.c.

References t_cmd::buf, t_ui::cmd, cmd_add_char(), cmd_del_char(), cmd_execute(), handle_scroll(), KEY_BACKSPACE, KEY_CTRL_C, KEY_CTRL_D, KEY_DOWN, KEY_ENTER, KEY_UP, t_cmd::len, MAX_CMD_LEN, t_ui::running, and t_shell::ui.

Referenced by ui_loop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cmd_execute()

void cmd_execute ( t_shell shell)

Execute the current command buffer & reset it.

Parameters
shellShell state

Definition at line 52 of file command.c.

References t_cmd::buf, t_ui::cmd, exec_ui_builtin(), execute_minishell_cmd(), t_cmd::len, MAX_CMD_LEN, MOOD_HAPPY, t_ui::out, out_clear(), t_shell::ui, and update_waifu_mood().

Referenced by handle_key().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ execute_minishell_cmd()

void execute_minishell_cmd ( t_shell shell)

Fork a child to execute a minishell command & capture its output.

Creates a pipe, forks, runs exec_child() in the child and exec_parent() in the parent

Parameters
shellShell state (contains command buffer and UI output)

Definition at line 137 of file execute.c.

References exec_child(), exec_parent(), handle_fork_error(), init_pipe_and_fds(), MOOD_HAPPY, t_shell::ui, and update_waifu_mood().

Referenced by cmd_execute().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read_output_from_fd()

void read_output_from_fd ( t_ui ui,
int  fd 
)

Read all available bytes from fd and split into output lines.

Reads in chunks of BUF_SIZE and any unterminated line is flushed after EOF

Parameters
uiUI states
fdFile descriptor to read from (pipe read end)

Definition at line 53 of file execute_utils.c.

References BUF_SIZE, t_ui::out, out_add_line(), and process_output_char().

Referenced by exec_parent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ process_ui_input()

int process_ui_input ( char *  input,
t_shell shell 
)

Full pipeline inside the UI.

tokenize -> expand_all_tokens -> parse -> collect_heredocs -> executor

Parameters
inputCommand string to execute
shellShell state (provides environment and execution context)
Returns
Exit status of the command, 1 on expand error, 2 on failure and 130 on heredoc interruption

Definition at line 88 of file execute_utils.c.

References collect_heredocs(), executor(), expand_all_tokens(), free_ast(), free_token_list(), parse(), and tokenize().

Referenced by exec_child().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ft_msleep()

void ft_msleep ( int  ms)

Sleep for approximately ms millisecondes using a little trick.

  • Sets VMIN = 0 so read() doesn't wait for a character
  • Sets VTIME = ms / 100 so read() blocks for that many deciseconds before returning with nothing
  • The result is thus an imitation of a sleep that doesn't use usleep() which is not allowed by the Minishell subject
  • Original terminal settings are saved and restored after the read
Parameters
msMilliseconds to sleep
Warning
Because of VTIME resolution, precision is limited to ~100 ms

Definition at line 28 of file welcome_utils.c.

Referenced by animate_demon(), animate_loading(), animate_quote(), animate_title(), cleanup_screen(), draw_border_effect(), draw_welcome(), flash_demon_eyes(), print_quote_lines(), and ui_loop().

+ Here is the caller graph for this function:

◆ draw_welcome()

void draw_welcome ( void  )

Draw complete welcome animation sequence and clean up.

Definition at line 68 of file welcome.c.

◆ draw_happy()

void draw_happy ( int  y,
int  x 
)

Draw happy Neko chan ASCII art.

Parameters
yTop row of the first line
xLeft col of the first art line

Definition at line 21 of file waifu_art.c.

References print_at().

Referenced by render_waifu_mood().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draw_upset()

void draw_upset ( int  y,
int  x 
)

Draw upset Neko chan ASCII art.

Parameters
yTop row of the first line
xLeft col of the first art line

Definition at line 38 of file waifu_art.c.

References print_at().

Referenced by render_waifu_mood().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draw_proud()

void draw_proud ( int  y,
int  x 
)

Draw proud Neko chan ASCII art.

Parameters
yTop row of the first line
xLeft col of the first art line

Definition at line 55 of file waifu_art.c.

References print_at().

Referenced by render_waifu_mood().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Go to the source code of this file.