Sign in

    moui_tui

    Terminal cell model: colors, attributes, rows and a damage-tracked screen buffer

    moui
    tui
    terminal
    cell-buffer
    damage
    Download zip
    Author
    Version
    0.1.1
    License
    Apache-2.0
    Last updated
    9 hours ago
    Downloads
    3

    wzzc-dev/moui_tui does not have a README file

    Cell

    pub(all) struct Cell {
    ch : String
    width : Int
    attrs : CellAttrs
    } derive(Eq,
    Debug
    )

    单元格:一个字符(宽字符占两格,第二格为 continuation,ch 为空)。

    Cell::equal

    fn Cell::equal(Cell, Cell) -> Bool

    Cell::not_equal

    fn Cell::not_equal(x : Cell, y : Cell) -> Bool

    Cell::to_repr

    CellAttrs

    pub(all) struct CellAttrs {
    fg : TermColor
    bg : TermColor
    bold : Bool
    dim : Bool
    italic : Bool
    underline : Bool
    reverse : Bool
    } derive(Eq,
    Debug
    )

    单元格属性(SGR 状态)。

    CellAttrs::default

    fn CellAttrs::default() -> CellAttrs

    CellAttrs::equal

    fn CellAttrs::equal(CellAttrs, CellAttrs) -> Bool

    CellAttrs::not_equal

    fn CellAttrs::not_equal(x : CellAttrs, y : CellAttrs) -> Bool

    Damage

    pub(all) struct Damage {
    full : Bool
    rows : Array[Int]
    } derive(Eq,
    Debug
    )

    一次呈现所需的最小脏信息:整屏重建,或按行增量。 rows 升序去重;由 TermScreen::take_damage 产出并随即清零。

    Damage::equal

    fn Damage::equal(Damage, Damage) -> Bool

    Damage::is_empty

    fn Damage::is_empty(self : Damage) -> Bool

    Damage::not_equal

    fn Damage::not_equal(x : Damage, y : Damage) -> Bool

    Damage::to_repr

    TermColor

    pub(all) enum TermColor {
    Default
    Indexed(Int)
    Rgb(Int, Int, Int)
    } derive(Eq,
    Debug
    )

    终端颜色:默认色、256 索引色、真彩色 RGB。

    TermColor::equal

    fn TermColor::equal(TermColor, TermColor) -> Bool

    TermColor::not_equal

    fn TermColor::not_equal(x : TermColor, y : TermColor) -> Bool

    TermRow

    pub(all) struct TermRow {
    cells : Array[Cell]
    }

    屏幕上一行。

    TermRow::new

    fn TermRow::new(cols : Int, attrs : CellAttrs) -> TermRow

    TermRow::runs

    fn TermRow::runs(self : TermRow) -> Array[(String, Int, CellAttrs)]

    行内按连续相同属性合并的渲染 run:(文本, 占列数, 属性)。 continuation 单元格(width == 0)不产生文本。

    TermRow::text

    fn TermRow::text(self : TermRow) -> String

    行文本(去掉尾部空白),供测试与标题提取使用。

    TermScreen

    pub struct TermScreen {
    // private fields
    }

    终端屏幕模型:可视区 + 回看缓冲 + 光标 + 滚动区域 + 脏行增量。 只有单元格内容变化才标脏;光标移动、SGR 属性与滚动区域设置不算画面变化, 因此呈现器按 take_damage 输出即可覆盖残影,又不会重绘未变的行。

    TermScreen::backspace

    fn TermScreen::backspace(self : TermScreen) -> Unit

    TermScreen::carriage_return

    fn TermScreen::carriage_return(self : TermScreen) -> Unit

    TermScreen::clear_all

    fn TermScreen::clear_all(self : TermScreen) -> Unit

    清空屏幕与回看缓冲。

    TermScreen::cols

    fn TermScreen::cols(self : TermScreen) -> Int

    TermScreen::current_attrs

    fn TermScreen::current_attrs(self : TermScreen) -> CellAttrs

    TermScreen::cursor_col

    fn TermScreen::cursor_col(self : TermScreen) -> Int

    TermScreen::cursor_column

    fn TermScreen::cursor_column(self : TermScreen, col : Int) -> Unit

    光标列定位(1-based)。

    TermScreen::cursor_down

    fn TermScreen::cursor_down(self : TermScreen, n : Int) -> Unit

    光标下移 n 行(不越过滚动区域底部)。

    TermScreen::cursor_left

    fn TermScreen::cursor_left(self : TermScreen, n : Int) -> Unit

    TermScreen::cursor_line

    fn TermScreen::cursor_line(self : TermScreen, row : Int) -> Unit

    光标行定位(1-based)。

    TermScreen::cursor_position

    fn TermScreen::cursor_position(self : TermScreen, row : Int, col : Int) -> Unit

    光标定位(row/col 均为 1-based)。

    TermScreen::cursor_right

    fn TermScreen::cursor_right(self : TermScreen, n : Int) -> Unit

    TermScreen::cursor_row

    fn TermScreen::cursor_row(self : TermScreen) -> Int

    TermScreen::cursor_up

    fn TermScreen::cursor_up(self : TermScreen, n : Int) -> Unit

    光标上移 n 行(不越过滚动区域顶部)。

    TermScreen::cursor_visible

    fn TermScreen::cursor_visible(self : TermScreen) -> Bool

    TermScreen::delete_chars

    fn TermScreen::delete_chars(self : TermScreen, n : Int) -> Unit

    删除光标处起 n 个字符(行内左移)。

    TermScreen::delete_lines

    fn TermScreen::delete_lines(self : TermScreen, n : Int) -> Unit

    删除光标行起的 n 行(区域内),顶部行进入回看缓冲。

    TermScreen::erase_cells

    fn TermScreen::erase_cells(self : TermScreen, y : Int, from : Int, to : Int, attrs : CellAttrs) -> Unit

    把第 y 行的 [from, to) 列擦成空白(越界裁剪),保持 attrs 的底色。

    TermScreen::erase_chars

    fn TermScreen::erase_chars(self : TermScreen, n : Int) -> Unit

    擦除光标处起 n 个字符(置空白,不移动)。

    TermScreen::erase_in_display

    fn TermScreen::erase_in_display(self : TermScreen, mode : Int) -> Unit

    清除显示:0 = 光标到末尾,1 = 开头到光标,2 = 整屏,3 = 整屏 + 回看。

    TermScreen::erase_in_line

    fn TermScreen::erase_in_line(self : TermScreen, mode : Int) -> Unit

    清除行:0 = 光标到行尾,1 = 行首到光标,2 = 整行。

    TermScreen::insert_chars

    fn TermScreen::insert_chars(self : TermScreen, n : Int) -> Unit

    光标处插入 n 个空白格(行内右移)。

    TermScreen::insert_lines

    fn TermScreen::insert_lines(self : TermScreen, n : Int) -> Unit

    光标行插入 n 个空行(区域内),底部行进入回看缓冲。

    TermScreen::line_at

    fn TermScreen::line_at(self : TermScreen, idx : Int) -> TermRow

    取第 idx 行(0 = 最早的回看行;total_lines - rows 起为可视区)。

    TermScreen::linefeed

    fn TermScreen::linefeed(self : TermScreen) -> Unit

    LF / VT / FF / IND:光标下移,在滚动区域底部时向上滚动。

    TermScreen::new

    fn TermScreen::new(cols : Int, rows : Int) -> TermScreen

    TermScreen::print_char

    fn TermScreen::print_char(self : TermScreen, ch : String, width : Int) -> Unit

    光标处写入字符;处理自动换行与宽字符(右半格填 continuation)。

    TermScreen::put

    fn TermScreen::put(self : TermScreen, y : Int, x : Int, ch : String, width : Int, attrs : CellAttrs) -> Bool

    直接写入第 y 行第 x 列,不移动光标 —— 投影器按量化盒定位单元格。 越界或宽字符放不下时返回 false,调用方据此记降级诊断。

    TermScreen::reset

    fn TermScreen::reset(self : TermScreen) -> Unit

    重置到初始状态(保留尺寸)。

    TermScreen::resize

    fn TermScreen::resize(self : TermScreen, new_cols : Int, new_rows : Int) -> Unit

    调整尺寸;行/列变化尽量保留内容,缩小后的行进入回看缓冲。 尺寸变化会让所有行的列位置失效,因此整屏标脏。

    TermScreen::restore_cursor

    fn TermScreen::restore_cursor(self : TermScreen) -> Unit

    TermScreen::reverse_index

    fn TermScreen::reverse_index(self : TermScreen) -> Unit

    RI:光标上移,在滚动区域顶部时向下滚动。

    TermScreen::revision

    fn TermScreen::revision(self : TermScreen) -> Int

    缓冲区代数:任何内容变化都会递增,呈现器用它跳过无变化的帧。

    TermScreen::rows

    fn TermScreen::rows(self : TermScreen) -> Int

    TermScreen::save_cursor

    fn TermScreen::save_cursor(self : TermScreen) -> Unit

    TermScreen::scroll_down

    fn TermScreen::scroll_down(self : TermScreen, n : Int) -> Unit

    滚动区域内向下滚动 n 行,底部行进入回看缓冲头部。

    TermScreen::scroll_up

    fn TermScreen::scroll_up(self : TermScreen, n : Int) -> Unit

    滚动区域内向上滚动 n 行,顶部行进入回看缓冲。

    TermScreen::set_auto_wrap

    fn TermScreen::set_auto_wrap(self : TermScreen, v : Bool) -> Unit

    DECAWM:关闭自动换行后,超宽字符停在最后一列而不是滚到新行。

    TermScreen::set_current_attrs

    fn TermScreen::set_current_attrs(self : TermScreen, attrs : CellAttrs) -> Unit

    TermScreen::set_cursor_visible

    fn TermScreen::set_cursor_visible(self : TermScreen, v : Bool) -> Unit

    TermScreen::set_scroll_region

    fn TermScreen::set_scroll_region(self : TermScreen, top : Int, bottom : Int) -> Unit

    设置滚动区域(top/bottom 为 1-based)。

    TermScreen::set_scrollback_limit

    fn TermScreen::set_scrollback_limit(self : TermScreen, limit : Int) -> Unit

    TermScreen::set_title

    fn TermScreen::set_title(self : TermScreen, title : String) -> Unit

    TermScreen::tab

    fn TermScreen::tab(self : TermScreen) -> Unit

    TermScreen::take_damage

    fn TermScreen::take_damage(self : TermScreen) -> Damage

    取出并清零脏区:整屏重建,或升序去重的脏行。

    TermScreen::title

    fn TermScreen::title(self : TermScreen) -> String

    TermScreen::total_lines

    fn TermScreen::total_lines(self : TermScreen) -> Int

    回看行数 + 可视行数。

    attrs_with

    fn attrs_with(attrs : CellAttrs, fg? : TermColor?, bg? : TermColor?, bold? : Bool?, dim? : Bool?, italic? : Bool?, underline? : Bool?, reverse? : Bool?) -> CellAttrs

    复制属性并替换部分字段(SGR 序列用)。

    attrs_with_fg

    fn attrs_with_fg(attrs : CellAttrs, fg : TermColor) -> CellAttrs

    复制属性并替换前景色。

    blank_cell

    fn blank_cell(attrs : CellAttrs) -> Cell

    continuation_cell

    fn continuation_cell(attrs : CellAttrs) -> Cell

    宽字符右半格:width == 0 让它不产生文本,只继承底色。

    trim_trailing_spaces

    fn trim_trailing_spaces(s : String) -> String

    去掉字符串尾部空格(终端行文本用)。

    unicode_width

    fn unicode_width(ch : String) -> Int

    简化 wcwidth:ASCII 1,常见宽字符区间 2,其余 1。 组合符未合并进基字符格,按 1 计(投影器不区分带符与基符)。