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

terminal state machine: ANSI escape parsing, cursor handling, output. More...

#include "tty.h"

Functions

void tty_init (tty_t *tty, const tty_backend_t *backend)
 initialize a tty on a backend.
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.
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.
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 state machine: ANSI escape parsing, cursor handling, output.

this is the logic that used to live in console.c, lifted onto a tty_t so it no longer talks to the VGA driver directly. all cell access goes through the backend ops, so the same parser drives any character-cell device.

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