|
ginnOS
The reference: libc, the libraries and the kernel
|
terminal (TTY) layer. More...
#include "common/stdint.h"Go to the source code of this file.
Data Structures | |
| struct | tty_backend_t |
| character-cell backend a tty draws onto. More... | |
| struct | tty_t |
| a terminal instance. More... | |
Macros | |
| #define | TTY_CSI_PARAMS_MAX 4 |
| #define | TTY_MODE_COOKED 0 |
| #define | TTY_MODE_RAW 1 |
| #define | TTY_COLOR_DEFAULT_FG 7 |
| #define | TTY_COLOR_DEFAULT_BG 0 |
Enumerations | |
| enum | tty_state_t { TTY_STATE_NORMAL , TTY_STATE_ESC , TTY_STATE_CSI , TTY_STATE_CSI_PRIV } |
Functions | |
| void | tty_init (tty_t *tty, const tty_backend_t *backend) |
| initialize a tty on a backend. | |
| void | tty_putchar (tty_t *tty, char c) |
| feed one output byte through the terminal state machine. | |
| void | tty_write (tty_t *tty, const char *str) |
| feed a null-terminated string through tty_putchar(), as one batch. | |
| void | tty_begin_batch (tty_t *tty) |
| start a batch of output. | |
| void | tty_end_batch (tty_t *tty) |
| end a batch: redraw the caret where the cursor ended up and flush once. | |
| uint8_t | tty_set_mode (tty_t *tty, uint8_t mode) |
| set the line-discipline mode (TTY_MODE_COOKED or TTY_MODE_RAW). | |
terminal (TTY) layer.
a tty_t is a terminal state machine sitting between byte-oriented callers (kernel printf, the write syscall) and a character-cell backend (the VGA text buffer today, a serial line or framebuffer later). it owns the ANSI escape parser, cursor handling, and line-discipline mode, none of which the backend needs to know about. the backend only has to place a glyph at a cell, scroll, clear, and move the hardware cursor.
splitting this out of the VGA driver lets a future system have several terminals (virtual consoles, a serial tty) that share one state machine.
| #define TTY_CSI_PARAMS_MAX 4 |
| #define TTY_MODE_COOKED 0 |
| #define TTY_MODE_RAW 1 |
| #define TTY_COLOR_DEFAULT_FG 7 |
| #define TTY_COLOR_DEFAULT_BG 0 |
| enum tty_state_t |
| void tty_init | ( | tty_t * | tty, |
| const tty_backend_t * | backend ) |
initialize a tty on a backend.
starts in cooked mode, normal parser state.
| tty | the terminal to initialize. |
| backend | the character-cell backend (must outlive the tty). |
| void tty_putchar | ( | tty_t * | tty, |
| char | c ) |
feed one output byte through the terminal state machine.
printable characters are drawn; control characters and ANSI escape sequences are interpreted (cursor movement, erase, etc.).
| tty | the terminal. |
| c | the byte to process. |
| void tty_write | ( | tty_t * | tty, |
| const char * | str ) |
feed a null-terminated string through tty_putchar(), as one batch.
| tty | the terminal. |
| str | the string to write. |
| void tty_begin_batch | ( | tty_t * | tty | ) |
start a batch of output.
until the matching tty_end_batch(), bytes are drawn but the caret is hidden and nothing is flushed to the display, so the screen never shows a half-finished update (e.g. a shell redrawing its line, where the cursor briefly visits column 0). batches nest.
| tty | the terminal. |
| void tty_end_batch | ( | tty_t * | tty | ) |
end a batch: redraw the caret where the cursor ended up and flush once.
| tty | the terminal. |