First cut of the terminal core memory model from ZIG/src/terminal: size, point, style, hyperlink, ref_counted_set, page and PageList. Design (see docs/rewrite/ARCHITECTURE.md decisions 2-4): - Cell/Row are 8-byte u64 wrappers with Zig's exact bit offsets. - Page owns row/cell Vecs plus style set, grapheme and hyperlink maps; Page::layout reproduces Ghostty's byte-size formula on 64-bit Linux so scrollback-limit pruning matches. - PageList keeps nodes in a generation-checked slab with a free list and list-owned tracked pins addressed by handles. This is explicitly partial (docs/rewrite/notes/ghostty-terminal- pagelist.md): 151/202 PageList tests ported; reflow rebuilds a snapshot instead of Zig's incremental ReflowCursor; point<->pin conversion walks from the list head (no active/viewport caches); RefCountedSet doesn't reproduce probe-dependent ID reuse. A follow-up pass finishes parity. Test Plan: - cargo test -p ghostty-terminal (239 tests)
66 lines
2.0 KiB
Rust
66 lines
2.0 KiB
Rust
//! Coordinates relative to the active area, viewport, screen, or history.
|
|
/// Reference frame for a terminal coordinate.
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
|
pub enum Tag {
|
|
/// Editable bottommost screen area, including unwritten rows.
|
|
Active,
|
|
/// Visible area, including user scrolling.
|
|
Viewport,
|
|
/// Entire screen including scrollback.
|
|
Screen,
|
|
/// Scrollback preceding the active area.
|
|
History,
|
|
}
|
|
/// An x/y coordinate; history may exceed a single page's row count.
|
|
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash)]
|
|
pub struct Coordinate {
|
|
/// Column.
|
|
pub x: u16,
|
|
/// Row relative to the point's reference frame.
|
|
pub y: u32,
|
|
}
|
|
impl Coordinate {
|
|
/// Compare both coordinates.
|
|
pub fn eql(self, other: Self) -> bool {
|
|
self == other
|
|
}
|
|
}
|
|
/// A coordinate with its reference frame.
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
|
pub enum Point {
|
|
/// Editable screen coordinate.
|
|
Active(Coordinate),
|
|
/// Visible viewport coordinate.
|
|
Viewport(Coordinate),
|
|
/// Whole-screen coordinate.
|
|
Screen(Coordinate),
|
|
/// Scrollback coordinate.
|
|
History(Coordinate),
|
|
}
|
|
impl Point {
|
|
/// Construct a point in a given frame.
|
|
pub const fn new(tag: Tag, coord: Coordinate) -> Self {
|
|
match tag {
|
|
Tag::Active => Self::Active(coord),
|
|
Tag::Viewport => Self::Viewport(coord),
|
|
Tag::Screen => Self::Screen(coord),
|
|
Tag::History => Self::History(coord),
|
|
}
|
|
}
|
|
/// Extract its coordinate.
|
|
pub const fn coord(self) -> Coordinate {
|
|
match self {
|
|
Self::Active(v) | Self::Viewport(v) | Self::Screen(v) | Self::History(v) => v,
|
|
}
|
|
}
|
|
/// Extract its reference frame.
|
|
pub const fn tag(self) -> Tag {
|
|
match self {
|
|
Self::Active(_) => Tag::Active,
|
|
Self::Viewport(_) => Tag::Viewport,
|
|
Self::Screen(_) => Tag::Screen,
|
|
Self::History(_) => Tag::History,
|
|
}
|
|
}
|
|
}
|