Module: reefvision.term
Source: ./reefvision/term.reef
Overview
reefvision.term — terminal host surface for ReefVision
Opens a TTY in raw mode, optional alternate screen, cursor hide/show, size probe, color-depth heuristic (COLORTERM/TERM), and CSI/SGR emit used by the cell-buffer flush path.
Host C: reef_rv_* only (reef_rv_term). Clean break from legacy TUI packages; no curses. ColorDepth lives here (design §7.2 / §8.3); Style/Cell arrive in later packages and import this type.
ESC (0x1b) cannot be embedded in Reef string literals, so CSI/SGR bytes are emitted via reef_rv_write_esc / cup / sgr_* helpers.
Types
ColorDepth (enum)
Logical device color capability. Emitter maps RGB down to this depth. Lives in term (not theme/cell) so open/probe can set it without a dependency cycle; theme/cell import ColorDepth from here.
Variants:
MonoAnsi16Color256TrueColor
TermError (enum)
Variants:
NoneNotATTYRawEnterFailedIoctlFailedNotOpenWriteFailed
TermConfig
Fields:
| Name | Type |
|---|---|
use_alternate_screen |
bool |
hide_cursor_by_default |
bool |
enter_raw |
bool |
require_tty |
bool |
enable_mouse |
bool |
in_fd |
int |
out_fd |
int |
Term
pen/Style deferred to cell/theme packages — flush will track last style.
Fields:
| Name | Type |
|---|---|
in_fd |
int |
out_fd |
int |
width |
int |
height |
int |
depth |
ColorDepth |
raw_saved |
pointer |
cursor_x |
int |
cursor_y |
int |
cursor_visible |
bool |
alt_screen |
bool |
mouse_enabled |
bool |
is_open |
bool |
config |
TermConfig |
TermResult (enum)
Variants:
Ok(Term)Err(TermError)
Functions
fn reef_rv_isatty(fd: int): int
fn reef_rv_get_width(fd: int): int
fn reef_rv_get_height(fd: int): int
fn reef_rv_raw_enter(fd: int): pointer
fn reef_rv_raw_restore(fd: int, saved: pointer): int
fn reef_rv_read(fd: int, buf: string, n: int): int
fn reef_rv_write(fd: int, buf: string, n: int): int
fn reef_rv_write_esc(fd: int, seq: string): int
fn reef_rv_write_cup(fd: int, row: int, col: int): int
fn reef_rv_write_sgr_truecolor_fg(fd: int, r: int, g: int, b: int): int
fn reef_rv_write_sgr_truecolor_bg(fd: int, r: int, g: int, b: int): int
fn reef_rv_write_sgr_256_fg(fd: int, n: int): int
fn reef_rv_write_sgr_256_bg(fd: int, n: int): int
fn reef_rv_write_sgr_16_fg(fd: int, idx: int): int
fn reef_rv_write_sgr_16_bg(fd: int, idx: int): int
fn term_config_default(): TermConfig
fn term_config_fullscreen(): TermConfig
Full-screen UI defaults: raw + alt screen + hidden cursor + SGR mouse.
fn detect_color_depth(): ColorDepth
- COLORTERM truecolor/24bit → TrueColor
- TERM has 256color / xterm / screen-256 / tmux-256 → Color256
- TERM linux/ansi/vt100 → Ansi16; dumb → Mono
- default Color256 (modern terminals often omit COLORTERM)
fn term_open(config: TermConfig): TermResult
fn term_width(term: Term): int
fn term_height(term: Term): int
fn term_depth(term: Term): ColorDepth
fn term_is_open(term: Term): bool
fn term_in_fd(term: Term): int
fn term_out_fd(term: Term): int
fn term_write(term: Term, data: string): int
fn term_read(term: Term, buf: string, n: int): int
Read up to n bytes into a pre-sized string buffer (caller owns buffer). Returns bytes read, or -1.
fn term_mouse_enabled(term: Term): bool
fn term_bel_byte(): string
fn is_ok(r: TermResult): bool
fn is_err(r: TermResult): bool
fn empty_term(): Term
fn unwrap(r: TermResult): Term
fn error_of(r: TermResult): TermError
Procedures
proc term_close(term: Term)
Always safe to call: leave alt screen, show cursor, reset SGR, restore termios.
proc term_refresh_size(term: Term)
proc term_set_depth(term: Term, depth: ColorDepth)
proc term_force_depth(term: Term, depth: ColorDepth)
Alias for tests / constrained consoles (design §8.3 step 4).
proc term_emit_cup(term: Term, x: int, y: int)
proc term_hide_cursor(term: Term)
proc term_show_cursor(term: Term)
proc term_clear(term: Term)
proc term_mouse_enable(term: Term)
proc term_mouse_disable(term: Term)
proc term_bracketed_paste_enable(term: Term)
proc term_bracketed_paste_disable(term: Term)
proc term_clipboard_query(term: Term)
OSC 52 query: ESC ] 52 ; c ; ? BEL (many terminals ignore; no-op is fine).
proc term_clipboard_set(term: Term, text: string)
OSC 52 set: ESC ] 52 ; c ; BEL
text must already be base64 (or "!" to clear). Empty → clear.
proc term_enter_alt_screen(term: Term)
proc term_leave_alt_screen(term: Term)
proc term_sgr_reset(term: Term)
proc term_sgr_bold(term: Term, enabled: bool)
proc term_sgr_underline(term: Term, enabled: bool)
proc term_sgr_reverse(term: Term, enabled: bool)
proc term_sgr_truecolor_fg(term: Term, r: int, g: int, b: int)
proc term_sgr_truecolor_bg(term: Term, r: int, g: int, b: int)
proc term_sgr_256_fg(term: Term, n: int)
proc term_sgr_256_bg(term: Term, n: int)
proc term_sgr_16_fg(term: Term, idx: int)
proc term_sgr_16_bg(term: Term, idx: int)
Generated by reefc doc