MiniDevil As beautiful as a shell
ui_main.c File Reference

UI main loop: draws interface, reads input, handles resize. More...

#include "minishell_ui.h"
+ Include dependency graph for ui_main.c:

Detailed Description

UI main loop: draws interface, reads input, handles resize.

Definition in file ui_main.c.

Functions

static void init_ui (t_shell *shell)
 Allocate and initialize the t_ui struct and attach it to shell. More...
 
static void check_resize (t_shell *shell)
 Handle a SIGWINCH signal (get new terminal dimensions and redraw) More...
 
static void ui_loop (t_shell *shell)
 Run the main loop. More...
 
void run_ui_mode (t_shell *shell)
 Entry point for UI mode. More...
 

Function Documentation

◆ init_ui()

static void init_ui ( t_shell shell)
static

Allocate and initialize the t_ui struct and attach it to shell.

Calls init_term and setup_ui_signals after allocation

Parameters
shellShell state (receives the new UI pointer)
Warning
On allocation failure it calls exit(1)

Definition at line 23 of file ui_main.c.

References init_term(), t_ui::running, setup_ui_signals(), and t_shell::ui.

Referenced by run_ui_mode().

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

◆ check_resize()

static void check_resize ( t_shell shell)
static

Handle a SIGWINCH signal (get new terminal dimensions and redraw)

Parameters
shellShell state

Definition at line 44 of file ui_main.c.

References draw_ui(), g_signal, get_term_size(), and t_shell::ui.

Referenced by ui_loop().

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

◆ ui_loop()

static void ui_loop ( t_shell shell)
static

Run the main loop.

  • Show the welcome animation, wait ~2s and enter the event loop
  • Read keys, dispatche handle_key() and redraw
  • Exit when shell->ui->running is set to 0
Parameters
shellShell state

Definition at line 63 of file ui_main.c.

References add_welcome_msg(), check_resize(), CURSOR_HIDE, draw_ui(), draw_welcome(), ft_msleep(), handle_key(), KEY_DOWN, KEY_ENTER, KEY_UP, read_key(), redraw_cmd_only(), and t_shell::ui.

Referenced by run_ui_mode().

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

◆ 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:

Go to the source code of this file.