mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-06 09:56:34 +00:00
defining some terms, prepare to have helpers for active vs history
This commit is contained in:
@@ -1,5 +1,14 @@
|
|||||||
//! Screen represents the internal storage for a terminal screen, including
|
//! Screen represents the internal storage for a terminal screen, including
|
||||||
//! scrollback. This is implemented as a single continuous ring buffer.
|
//! scrollback. This is implemented as a single continuous ring buffer.
|
||||||
|
//!
|
||||||
|
//! Definitions:
|
||||||
|
//!
|
||||||
|
//! * Active - The area that is the current edit-able screen.
|
||||||
|
//! * History - The area that contains lines from prior input.
|
||||||
|
//! * Display - The area that is currently visible to the user. If the
|
||||||
|
//! user is scrolled all the way down (latest) then the display
|
||||||
|
//! is equivalent to the active area.
|
||||||
|
//!
|
||||||
const Screen = @This();
|
const Screen = @This();
|
||||||
|
|
||||||
// FUTURE: Today this is implemented as a single contiguous ring buffer.
|
// FUTURE: Today this is implemented as a single contiguous ring buffer.
|
||||||
@@ -123,7 +132,7 @@ pub fn getVisible(self: Screen) []Cell {
|
|||||||
return self.storage;
|
return self.storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a single row by index (0-indexed).
|
/// Get a single row in the active area by index (0-indexed).
|
||||||
pub fn getRow(self: Screen, idx: usize) Row {
|
pub fn getRow(self: Screen, idx: usize) Row {
|
||||||
// Get the index of the first byte of the the row at index.
|
// Get the index of the first byte of the the row at index.
|
||||||
const real_idx = self.rowIndex(idx);
|
const real_idx = self.rowIndex(idx);
|
||||||
@@ -132,7 +141,7 @@ pub fn getRow(self: Screen, idx: usize) Row {
|
|||||||
return self.storage[real_idx .. real_idx + self.cols];
|
return self.storage[real_idx .. real_idx + self.cols];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a single cell in the visible area. row and col are 0-indexed.
|
/// Get a single cell in the active area. row and col are 0-indexed.
|
||||||
pub fn getCell(self: Screen, row: usize, col: usize) *Cell {
|
pub fn getCell(self: Screen, row: usize, col: usize) *Cell {
|
||||||
assert(row < self.rows);
|
assert(row < self.rows);
|
||||||
assert(col < self.cols);
|
assert(col < self.cols);
|
||||||
@@ -142,7 +151,7 @@ pub fn getCell(self: Screen, row: usize, col: usize) *Cell {
|
|||||||
|
|
||||||
/// Returns the index for the given row (0-indexed) into the underlying
|
/// Returns the index for the given row (0-indexed) into the underlying
|
||||||
/// storage array.
|
/// storage array.
|
||||||
pub fn rowIndex(self: Screen, idx: usize) usize {
|
fn rowIndex(self: Screen, idx: usize) usize {
|
||||||
assert(idx < self.rows);
|
assert(idx < self.rows);
|
||||||
const val = (self.top + self.visible_offset + idx) * self.cols;
|
const val = (self.top + self.visible_offset + idx) * self.cols;
|
||||||
if (val < self.storage.len) return val;
|
if (val < self.storage.len) return val;
|
||||||
|
Reference in New Issue
Block a user