egui_simple_term 0.1.0

A small embeddable terminal widget for egui: a colored prompt, line editing, command history, and a scrollable output backlog.
Documentation
use crate::CellGroup;
use alloc::boxed::Box;

/// One visual line in the terminal backlog.
///
/// A line is either a single run ([`Full`](Self::Full)) or a sequence of runs
/// ([`Segs`](Self::Segs)); each run is a [`CellGroup`] of same-colored characters.
///
/// `Full` is the common case — a whole line in one color, e.g. output. `Segs`
/// models a line that mixes styles, e.g. the input line's differently-colored
/// prompt and typed text.
pub enum Line {
    /// A single run spanning the whole line.
    Full(CellGroup),
    /// Several runs laid out left to right.
    Segs(Box<[CellGroup]>),
}

impl Line {
    /// View the line as its runs, regardless of variant.
    pub fn as_slice(&self) -> &[CellGroup] {
        match self {
            Self::Full(g) => core::slice::from_ref(g),
            Self::Segs(gs) => &gs,
        }
    }

    /// Total number of characters in the line (sum over all runs).
    pub fn len(&self) -> usize {
        self.as_slice().iter().map(CellGroup::len).sum()
    }
}