Module: reefvision.cell

Source: ./reefvision/cell.reef


Overview

reefvision.cell — geometry, styles, cell buffer, dirty flush

Pure Reef double-buffer of terminal cells (design §7.1–7.3). Drawing ops clip OOB. Flush compares front vs back and emits cup + SGR + UTF-8 for dirty cells via reefvision.term (host path is reef_rv only).

FrameStyle §8.4: Ascii / UnicodeLight / None. Box-drawing code points are stored as integers (U+25xx); emit encodes UTF-8 in pure Reef. ColorDepth lives in reefvision.term; flush maps RGB down to device depth with private quantizers (theme Task 4 may re-export refined versions).


Types

Point

Fields:

Name Type
x int
y int

Rect

Fields:

Name Type
x int
y int
w int
h int

Color

Logical color: always RGB; flush maps to term.ColorDepth.

Fields:

Name Type
r int
g int
b int

Style

Fields:

Name Type
fg Color
bg Color
bold bool
underline bool
reverse bool

Cell

Fields:

Name Type
ch int
style Style

CellBuffer

Fields:

Name Type
width int
height int
cells [Cell]

FrameStyle (enum)

Variants:

  • Ascii
  • UnicodeLight
  • None

Functions

fn box_ascii_tl(): int

fn box_ascii_t(): int

fn box_ascii_tr(): int

fn box_ascii_v(): int

fn box_ascii_bl(): int

fn box_ascii_b(): int

fn box_ascii_br(): int

fn box_light_tl(): int

fn box_light_t(): int

fn box_light_tr(): int

fn box_light_v(): int

fn box_light_bl(): int

fn box_light_b(): int

fn box_light_br(): int

fn box_double_tl(): int

fn box_double_t(): int

fn box_double_tr(): int

fn box_double_v(): int

fn box_double_bl(): int

fn box_double_b(): int

fn box_double_br(): int

fn point(x: int, y: int): Point

fn rect(x: int, y: int, w: int, h: int): Rect

fn rect_empty(r: Rect): bool

fn point_in_rect(p: Point, r: Rect): bool

fn rect_contains(outer: Rect, inner: Rect): bool

fn max_int(a: int, b: int): int

fn min_int(a: int, b: int): int

fn rect_intersect(a: Rect, b: Rect): Rect

fn rect_union(a: Rect, b: Rect): Rect

fn rect_clip_to_size(r: Rect, width: int, height: int): Rect

Clip rectangle to [0,width) × [0,height). Empty if no overlap.

fn clamp_byte(v: int): int

fn color_rgb(r: int, g: int, b: int): Color

fn color_black(): Color

fn color_white(): Color

fn color_eq(a: Color, b: Color): bool

fn style_default(): Style

fn style_make(fg: Color, bg: Color, bold: bool, underline: bool, reverse: bool): Style

fn style_eq(a: Style, b: Style): bool

fn cell_make(ch: int, style: Style): Cell

fn cell_space(style: Style): Cell

fn cell_eq(a: Cell, b: Cell): bool

fn cell_index(buf: CellBuffer, x: int, y: int): int

fn in_bounds(buf: CellBuffer, x: int, y: int): bool

fn cellbuf_create(w: int, h: int): CellBuffer

fn cellbuf_get(buf: CellBuffer, x: int, y: int): Cell

OOB returns a space with default style (tests use in-bounds only).

fn codepoint_display_width(cp: int): int

East-Asian-ish wide check (not a full UAX #11 table — enough for box/CJK/hexagrams). Terminals advance the cursor by this many columns after writing the code point.

fn text_display_width(text: string): int

fn codepoint_to_utf8(cp: int): string

Encode Unicode code point to a UTF-8 string for term_write.

fn utf8_decode_step(s: string, i: int): Point

Decode one UTF-8 code point starting at byte index i. On invalid/truncated sequences, emit the byte as a Latin-1-ish cell and advance by 1.

fn cellbuf_diff_count(front: CellBuffer, back: CellBuffer): int

fn rgb_to_256(r: int, g: int, b: int): int

xterm 256: 16 system + 6x6x6 cube (16..231) + 24 greys (232..255).

fn rgb_cube_level(v: int): int

fn rgb_to_ansi16(r: int, g: int, b: int): int

Nearest of 16 ANSI colors (indices 0..15: standard then bright).

fn ansi16_r(i: int): int

fn ansi16_g(i: int): int

fn ansi16_b(i: int): int


Procedures

proc fill_cells_range(cells: [Cell], start: int, count: int, style: Style)

proc cellbuf_resize(buf: CellBuffer, w: int, h: int)

proc cellbuf_clear(buf: CellBuffer, style: Style)

proc cellbuf_put(buf: CellBuffer, x: int, y: int, ch: int, style: Style)

proc cellbuf_fill_rect(buf: CellBuffer, r: Rect, ch: int, style: Style)

proc cellbuf_draw_text(buf: CellBuffer, x: int, y: int, text: string, style: Style)

proc cellbuf_draw_text_in(buf: CellBuffer, x: int, y: int, text: string, style: Style, clip: Rect)

Draw text clipped to a rectangle (inclusive origin, exclusive of right/bottom via point_in_rect). Used by labels/buttons so text never escapes the widget or the parent window client area. Advances by display width (CJK-safe).

proc cellbuf_draw_box(buf: CellBuffer, r: Rect, style: Style, frame: FrameStyle)

proc cellbuf_draw_box_glyphs(buf: CellBuffer, r: Rect, style: Style, tl: int, t: int, tr: int, v: int, bl: int, b: int, br: int)

proc draw_box_chars(buf: CellBuffer, r: Rect, style: Style, tl: int, th: int, tr: int, v: int, bl: int, bh: int, br: int)

proc emit_style_for_depth(t: term.Term, st: Style)

proc cellbuf_flush(t: term.Term, front: CellBuffer, back: CellBuffer)


Generated by reefc doc