pub struct TerminalCell {
pub text: String,
pub style: TerminalStyle,
pub width: CellWidth,
pub hyperlink: Option<TerminalHyperlinkId>,
}Expand description
One styled cell in the terminal grid.
Fields are public and deserialization is unchecked, so callers can create inconsistent text/width pairs. State/screen mutation APIs preserve the leading/trailing convention when used normally.
§Examples
use ailloli_ui_terminal_core::{CellWidth, TerminalCell};
let cell = TerminalCell::default();
assert_eq!((cell.text.as_str(), cell.width), (" ", CellWidth::Narrow));Fields§
§text: StringRendered grapheme text; a trailing wide cell normally uses "".
style: TerminalStyleForeground, background, and SGR attributes.
width: CellWidthGrid-column occupancy marker.
hyperlink: Option<TerminalHyperlinkId>Active OSC 8 hyperlink, or None when the cell is not linked.
Implementations§
Source§impl TerminalCell
impl TerminalCell
Sourcepub fn blank(style: TerminalStyle) -> Self
pub fn blank(style: TerminalStyle) -> Self
Creates one narrow space with the supplied style and no hyperlink.
§Examples
use ailloli_ui_terminal_core::{TerminalCell, TerminalStyle};
assert!(TerminalCell::blank(TerminalStyle::default()).is_blank());Sourcepub fn narrow(text: impl Into<String>, style: TerminalStyle) -> Self
pub fn narrow(text: impl Into<String>, style: TerminalStyle) -> Self
Creates a narrow cell, storing text verbatim without width validation.
Empty or multi-character strings are accepted.
§Examples
use ailloli_ui_terminal_core::{CellWidth, TerminalCell, TerminalStyle};
let cell = TerminalCell::narrow("A", TerminalStyle::default());
assert_eq!((cell.text.as_str(), cell.width), ("A", CellWidth::Narrow));Sourcepub fn wide_leading(text: impl Into<String>, style: TerminalStyle) -> Self
pub fn wide_leading(text: impl Into<String>, style: TerminalStyle) -> Self
Creates the text-bearing first half of a wide cell pair.
The caller is responsible for supplying genuinely two-column text and a
matching Self::wide_trailing cell.
§Examples
use ailloli_ui_terminal_core::{CellWidth, TerminalCell, TerminalStyle};
let cell = TerminalCell::wide_leading("界", TerminalStyle::default());
assert_eq!(cell.width, CellWidth::WideLeading);Sourcepub fn wide_trailing(style: TerminalStyle) -> Self
pub fn wide_trailing(style: TerminalStyle) -> Self
Creates the empty second half of a wide cell pair.
§Examples
use ailloli_ui_terminal_core::{CellWidth, TerminalCell, TerminalStyle};
let cell = TerminalCell::wide_trailing(TerminalStyle::default());
assert!(cell.text.is_empty() && cell.width == CellWidth::WideTrailing);Sourcepub fn hyperlink(self, hyperlink: Option<TerminalHyperlinkId>) -> Self
pub fn hyperlink(self, hyperlink: Option<TerminalHyperlinkId>) -> Self
Replaces the optional hyperlink and returns the updated cell.
Passing None clears a previous link.
§Examples
use ailloli_ui_terminal_core::{TerminalCell, TerminalHyperlinkId, TerminalStyle};
let cell = TerminalCell::narrow("docs", TerminalStyle::default())
.hyperlink(Some(TerminalHyperlinkId(7)));
assert_eq!(cell.hyperlink, Some(TerminalHyperlinkId(7)));Sourcepub fn is_blank(&self) -> bool
pub fn is_blank(&self) -> bool
Returns true only for an exact narrow single-space cell.
Style and hyperlink do not affect the result.
§Examples
use ailloli_ui_terminal_core::{TerminalCell, TerminalStyle};
assert!(TerminalCell::default().is_blank());
assert!(!TerminalCell::narrow("", TerminalStyle::default()).is_blank());Trait Implementations§
Source§impl Clone for TerminalCell
impl Clone for TerminalCell
Source§fn clone(&self) -> TerminalCell
fn clone(&self) -> TerminalCell
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more