MiniDevil As beautiful as a shell
input.c File Reference

Key input reading (decodes escape sequences & arrow keys) More...

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

Detailed Description

Key input reading (decodes escape sequences & arrow keys)

Definition in file input.c.

Functions

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...
 
static void handle_scroll (t_ui *ui, int key)
 Adjust the scroll offset and refresh the output panel. More...
 
void handle_key (t_shell *shell, int key)
 Dispatch key code to the appropriate UI action. More...
 

Function Documentation

◆ 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_scroll()

static void handle_scroll ( t_ui ui,
int  key 
)
static

Adjust the scroll offset and refresh the output panel.

  • KEY_UP decrements scroll (starting from 0)
  • KEY_DOWN increments scrolls (up to count - 10)
Parameters
uiUI state
keyKEY_UP or KEY_DOWN

Definition at line 92 of file input.c.

References t_out::count, KEY_DOWN, KEY_UP, t_ui::out, redraw_output_only(), and t_out::scroll.

Referenced by handle_key().

+ Here is the call graph for this function:
+ 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:

Go to the source code of this file.