aboutsummaryrefslogtreecommitdiff
path: root/vendor/vt100/src/cell.rs
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-04-05 16:24:20 +0300
committerCan Celik <ogulcancelik@gmail.com>2026-04-05 16:38:50 +0300
commitb2e6929aa8199574565fd4adf1e631c68d479e6c (patch)
tree99964965fe84f9ea31a0dec7ede2393631dc7f50 /vendor/vt100/src/cell.rs
parent822c3b9e2d1edb7481fa558497dd33c7f5dca9ee (diff)
refactor: remove vt100 backend and make ghostty default
Diffstat (limited to 'vendor/vt100/src/cell.rs')
-rw-r--r--vendor/vt100/src/cell.rs179
1 files changed, 0 insertions, 179 deletions
diff --git a/vendor/vt100/src/cell.rs b/vendor/vt100/src/cell.rs
deleted file mode 100644
index c000cf30..00000000
--- a/vendor/vt100/src/cell.rs
+++ /dev/null
@@ -1,179 +0,0 @@
-use unicode_width::UnicodeWidthChar as _;
-
-// chosen to make the size of the cell struct 32 bytes
-const CONTENT_BYTES: usize = 22;
-
-const IS_WIDE: u8 = 0b1000_0000;
-const IS_WIDE_CONTINUATION: u8 = 0b0100_0000;
-const LEN_BITS: u8 = 0b0001_1111;
-
-/// Represents a single terminal cell.
-#[derive(Clone, Debug, Eq)]
-pub struct Cell {
- contents: [u8; CONTENT_BYTES],
- len: u8,
- attrs: crate::attrs::Attrs,
-}
-const _: () = assert!(std::mem::size_of::<Cell>() == 32);
-
-impl PartialEq<Self> for Cell {
- fn eq(&self, other: &Self) -> bool {
- if self.len != other.len {
- return false;
- }
- if self.attrs != other.attrs {
- return false;
- }
- let len = self.len();
- self.contents[..len] == other.contents[..len]
- }
-}
-
-impl Cell {
- pub(crate) fn new() -> Self {
- Self {
- contents: Default::default(),
- len: 0,
- attrs: crate::attrs::Attrs::default(),
- }
- }
-
- fn len(&self) -> usize {
- usize::from(self.len & LEN_BITS)
- }
-
- pub(crate) fn set(&mut self, c: char, a: crate::attrs::Attrs) {
- self.len = 0;
- self.append_char(0, c);
- // strings in this context should always be an arbitrary character
- // followed by zero or more zero-width characters, so we should only
- // have to look at the first character
- self.set_wide(c.width().unwrap_or(1) > 1);
- self.attrs = a;
- }
-
- pub(crate) fn append(&mut self, c: char) {
- let len = self.len();
- if len >= CONTENT_BYTES - 4 {
- return;
- }
- if len == 0 {
- self.contents[0] = b' ';
- self.len += 1;
- }
-
- // we already checked that we have space for another codepoint
- self.append_char(self.len(), c);
- }
-
- // Writes bytes representing c at start
- // Requires caller to verify start <= CODEPOINTS_IN_CELL * 4
- fn append_char(&mut self, start: usize, c: char) {
- c.encode_utf8(&mut self.contents[start..]);
- self.len += u8::try_from(c.len_utf8()).unwrap();
- }
-
- pub(crate) fn clear(&mut self, attrs: crate::attrs::Attrs) {
- self.len = 0;
- self.attrs = attrs;
- }
-
- /// Returns the text contents of the cell.
- ///
- /// Can include multiple unicode characters if combining characters are
- /// used, but will contain at most one character with a non-zero character
- /// width.
- // Since contents has been constructed by appending chars encoded as UTF-8 it will be valid UTF-8
- #[allow(clippy::missing_panics_doc)]
- #[must_use]
- pub fn contents(&self) -> &str {
- std::str::from_utf8(&self.contents[..self.len()]).unwrap()
- }
-
- /// Returns whether the cell contains any text data.
- #[must_use]
- pub fn has_contents(&self) -> bool {
- self.len() > 0
- }
-
- /// Returns whether the text data in the cell represents a wide character.
- #[must_use]
- pub fn is_wide(&self) -> bool {
- self.len & IS_WIDE != 0
- }
-
- /// Returns whether the cell contains the second half of a wide character
- /// (in other words, whether the previous cell in the row contains a wide
- /// character)
- #[must_use]
- pub fn is_wide_continuation(&self) -> bool {
- self.len & IS_WIDE_CONTINUATION != 0
- }
-
- fn set_wide(&mut self, wide: bool) {
- if wide {
- self.len |= IS_WIDE;
- } else {
- self.len &= !IS_WIDE;
- }
- }
-
- pub(crate) fn set_wide_continuation(&mut self, wide: bool) {
- if wide {
- self.len |= IS_WIDE_CONTINUATION;
- } else {
- self.len &= !IS_WIDE_CONTINUATION;
- }
- }
-
- pub(crate) fn attrs(&self) -> &crate::attrs::Attrs {
- &self.attrs
- }
-
- /// Returns the foreground color of the cell.
- #[must_use]
- pub fn fgcolor(&self) -> crate::Color {
- self.attrs.fgcolor
- }
-
- /// Returns the background color of the cell.
- #[must_use]
- pub fn bgcolor(&self) -> crate::Color {
- self.attrs.bgcolor
- }
-
- /// Returns whether the cell should be rendered with the bold text
- /// attribute.
- #[must_use]
- pub fn bold(&self) -> bool {
- self.attrs.bold()
- }
-
- /// Returns whether the cell should be rendered with the dim text
- /// attribute.
- #[must_use]
- pub fn dim(&self) -> bool {
- self.attrs.dim()
- }
-
- /// Returns whether the cell should be rendered with the italic text
- /// attribute.
- #[must_use]
- pub fn italic(&self) -> bool {
- self.attrs.italic()
- }
-
- /// Returns whether the cell should be rendered with the underlined text
- /// attribute.
- #[must_use]
- pub fn underline(&self) -> bool {
- self.attrs.underline()
- }
-
- /// Returns whether the cell should be rendered with the inverse text
- /// attribute.
- #[must_use]
- pub fn inverse(&self) -> bool {
- self.attrs.inverse()
- }
-}