The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
tty.h File Reference

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).

Detailed Description

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.

Macro Definition Documentation

◆ TTY_CSI_PARAMS_MAX

#define TTY_CSI_PARAMS_MAX   4

◆ TTY_MODE_COOKED

#define TTY_MODE_COOKED   0

◆ TTY_MODE_RAW

#define TTY_MODE_RAW   1

◆ TTY_COLOR_DEFAULT_FG

#define TTY_COLOR_DEFAULT_FG   7

◆ TTY_COLOR_DEFAULT_BG

#define TTY_COLOR_DEFAULT_BG   0

Enumeration Type Documentation

◆ tty_state_t

Enumerator
TTY_STATE_NORMAL 
TTY_STATE_ESC 
TTY_STATE_CSI 
TTY_STATE_CSI_PRIV 

Function Documentation

◆ tty_init()

void tty_init ( tty_t * tty,
const tty_backend_t * backend )

initialize a tty on a backend.

starts in cooked mode, normal parser state.

Parameters
ttythe terminal to initialize.
backendthe character-cell backend (must outlive the tty).

◆ tty_putchar()

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.).

Parameters
ttythe terminal.
cthe byte to process.

◆ tty_write()

void tty_write ( tty_t * tty,
const char * str )

feed a null-terminated string through tty_putchar(), as one batch.

Parameters
ttythe terminal.
strthe string to write.

◆ tty_begin_batch()

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.

Parameters
ttythe terminal.

◆ tty_end_batch()

void tty_end_batch ( tty_t * tty)

end a batch: redraw the caret where the cursor ended up and flush once.

Parameters
ttythe terminal.

◆ tty_set_mode()

uint8_t tty_set_mode ( tty_t * tty,
uint8_t mode )

set the line-discipline mode (TTY_MODE_COOKED or TTY_MODE_RAW).

Parameters
ttythe terminal.
modethe new mode.
Returns
the previous mode.