Files
ghostty-rs/crates/ghostty-terminal/src/size.rs
T
ddidderr b9ac54e794 feat(terminal): port page memory model (partial PageList)
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)
2026-10-11 22:12:31 +02:00

45 lines
1.2 KiB
Rust

//! Integer widths and safe logical offsets used by terminal pages.
use std::marker::PhantomData;
/// Maximum addressable page size.
pub const MAX_PAGE_SIZE: u32 = u32::MAX;
/// Byte offset within a page.
pub type OffsetInt = u32;
/// Number of cells in a grid dimension.
pub type CellCountInt = u16;
/// Style capacity and identifiers.
pub type StyleCountInt = u16;
/// Hyperlink capacity and identifiers.
pub type HyperlinkCountInt = u16;
/// Bytes of grapheme storage.
pub type GraphemeBytesInt = u32;
/// Bytes of string storage.
pub type StringBytesInt = u32;
/// A typed logical byte offset; never converted to a raw pointer.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[repr(transparent)]
pub struct Offset<T> {
offset: u32,
marker: PhantomData<fn() -> T>,
}
impl<T> Offset<T> {
/// Construct a logical byte offset.
pub const fn new(offset: u32) -> Self {
Self {
offset,
marker: PhantomData,
}
}
/// Return the byte displacement.
pub const fn offset(self) -> u32 {
self.offset
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn offset() {
assert_eq!(std::mem::size_of::<Offset<u8>>(), 4);
}
}