ze
Loading...
Searching...
No Matches
Files | Functions
Collaboration diagram for Terminal:

Files

file  terminal.c
 Raw terminal mode helpers and key decoding.
 

Functions

void die (const char *s)
 Abort the program after resetting the screen and printing perror.
 
void disableRawMode (void)
 Restore cooked terminal mode.
 
void enableRawMode (void)
 Enable raw terminal mode and register an atexit handler.
 
char editorReadKey (void)
 Read a key, decoding escape sequences into editorKey values.
 
int getCursorPosition (int *rows, int *cols)
 Query the terminal for the current cursor position.
 
int getWindowSize (int *rows, int *cols)
 Obtain terminal window size in rows and columns.
 

Detailed Description

Function Documentation

◆ die()

void die ( const char *  s)

Abort the program after resetting the screen and printing perror.

Clears the screen, moves the cursor home, prints a perror() message for s, and exits with code 1.

Parameters
[in]sMessage passed to perror(). Must be a NUL-terminated string.

◆ disableRawMode()

void disableRawMode ( void  )

Restore cooked terminal mode.

Restores original termios captured in E.orig_termios. On failure, calls die().

See also
enableRawMode()

◆ editorReadKey()

char editorReadKey ( void  )

Read a key, decoding escape sequences into editorKey values.

Blocks until one byte is read; if the byte begins an escape sequence, attempts to parse known sequences into control codes.

Returns
ASCII char or one of the custom key codes (e.g., ARROW_*).

◆ enableRawMode()

void enableRawMode ( void  )

Enable raw terminal mode and register an atexit handler.

Captures current termios into E.orig_termios, registers atexit handler to restore it, and configures raw input/output settings.

Postcondition
Raw mode active; on failure, terminates via die().
See also
disableRawMode()

◆ getCursorPosition()

int getCursorPosition ( int *  rows,
int *  cols 
)

Query the terminal for the current cursor position.

Sends CSI 6n and parses the response.

Parameters
[out]rowsReceives 1-based row number.
[out]colsReceives 1-based column number.
Returns
0 on success; -1 on failure.

◆ getWindowSize()

int getWindowSize ( int *  rows,
int *  cols 
)

Obtain terminal window size in rows and columns.

Uses ioctl(TIOCGWINSZ) and falls back to cursor probing if needed.

Parameters
[out]rowsReceives number of rows.
[out]colsReceives number of columns.
Returns
0 on success; -1 on failure.
See also
getCursorPosition()