Module: ui.backend.tty
Source: ./ui/backend/tty.reef
Overview
ui/backend/tty.reef - Terminal/TTY backend using ANSI escape codes Part of reef-stdlib UI module
This module provides a curses-like text-based UI backend that works on any terminal supporting ANSI escape codes. It's useful for:
- Console/terminal applications
- Server management interfaces
- SSH-accessible UIs
- Text-mode games
- Retro computing aesthetics
The TTY backend uses ANSI escape sequences for cursor positioning, colors, and other terminal control. No curses/ncurses dependency required.
Types
TTYError (enum)
Variants:
NoneNotATTYIoctlFailedInvalidOperationUnsupportedTerminal
TTYConfig
Fields:
| Name | Type |
|---|---|
raw_mode |
bool |
no_signal |
bool |
eight_bit |
bool |
use_alternate_screen |
bool |
TTY
Fields:
| Name | Type |
|---|---|
fd |
int |
width |
int |
height |
int |
cursor_x |
int |
cursor_y |
int |
config |
TTYConfig |
is_open |
bool |
original_termios |
pointer |
TTYResult (enum)
Variants:
Ok(TTY)Err(TTYError)
Functions
fn reef_tty_open(): int
Terminal operations
fn reef_tty_close(fd: int): int
fn reef_tty_get_width(fd: int): int
fn reef_tty_get_height(fd: int): int
fn reef_tty_is_tty(fd: int): int
fn reef_tty_set_raw(fd: int): pointer
fn reef_tty_restore(fd: int, termios: pointer): int
fn reef_tty_write(fd: int, buf: string, len: int): int
fn tty_config_default(): TTYConfig
fn tty_config_raw_mode(): TTYConfig
fn tty_open(): TTYResult
fn tty_open_with_config(config: TTYConfig): TTYResult
fn tty_width(tty: TTY): int
fn tty_height(tty: TTY): int
fn tty_is_open(tty: TTY): bool
fn tty_get_cursor_x(tty: TTY): int
fn tty_get_cursor_y(tty: TTY): int
fn reef_tty_write_box_tl(fd: int): int
Box drawing uses C helper to write Unicode characters
fn reef_tty_write_box_tr(fd: int): int
fn reef_tty_write_box_bl(fd: int): int
fn reef_tty_write_box_br(fd: int): int
fn reef_tty_write_box_h(fd: int): int
fn reef_tty_write_box_v(fd: int): int
fn reef_tty_write_char(fd: int, ch: char): int
fn is_ok(r: TTYResult): bool
fn is_err(r: TTYResult): bool
fn unwrap(r: TTYResult): TTY
fn empty_tty(): TTY
fn error(r: TTYResult): TTYError
fn reef_tty_write_esc(fd: int, seq: string): int
fn reef_tty_write_cursor_pos(fd: int, row: int, col: int): int
fn reef_tty_write_fg_rgb(fd: int, r: int, g: int, b: int): int
fn reef_tty_write_bg_rgb(fd: int, r: int, g: int, b: int): int
Procedures
proc tty_close(tty: TTY)
proc tty_clear(tty: TTY)
proc tty_clear_line(tty: TTY)
proc tty_clear_to_end(tty: TTY)
proc tty_refresh(tty: TTY)
proc tty_move_cursor(tty: TTY, x: int, y: int)
proc tty_hide_cursor(tty: TTY)
proc tty_show_cursor(tty: TTY)
proc tty_save_cursor(tty: TTY)
proc tty_restore_cursor(tty: TTY)
proc tty_print(tty: TTY, text: string)
proc tty_print_at(tty: TTY, x: int, y: int, text: string)
proc tty_set_fg(tty: TTY, color: core.Color)
proc tty_set_bg(tty: TTY, color: core.Color)
proc tty_set_bold(tty: TTY, enabled: bool)
proc tty_set_underline(tty: TTY, enabled: bool)
proc tty_set_blink(tty: TTY, enabled: bool)
proc tty_set_reverse(tty: TTY, enabled: bool)
proc tty_reset_style(tty: TTY)
proc tty_draw_box(tty: TTY, x: int, y: int, w: int, h: int)
proc tty_draw_hline(tty: TTY, x: int, y: int, length: int)
proc tty_draw_vline(tty: TTY, x: int, y: int, length: int)
proc tty_put_char(tty: TTY, x: int, y: int, ch: char)
proc tty_put_char_styled(tty: TTY, x: int, y: int, ch: char, fg: core.Color, bg: core.Color)
proc write_escape_seq(fd: int, seq: string)
proc write_cursor_pos(fd: int, row: int, col: int)
proc write_fg_color(fd: int, r: int, g: int, b: int)
proc write_bg_color(fd: int, r: int, g: int, b: int)
Generated by reefc doc