small software-rendered rust tty
btop capable
| -rw-r--r-- | Cargo.toml | 10 | ||||
| -rw-r--r-- | src/main.rs | 3 | ||||
| -rw-r--r-- | src/render.rs | 2 | ||||
| -rw-r--r-- | src/term.rs | 16 | ||||
| -rw-r--r-- | src/term/cells.rs | 12 |
5 files changed, 29 insertions, 14 deletions
@@ -7,7 +7,9 @@ edition = "2024" anstream = "0.6.18" anyhow = "1.0.98" atools = "0.1.6" -chumsky = { git = "https://github.com/zesterer/chumsky", version = "0.11.0", features = ["nightly"] } +chumsky = { git = "https://github.com/zesterer/chumsky", version = "0.11.0", features = [ + "nightly", +] } color-hex = "0.2.0" ctlfun = { git = "https://github.com/bend-n/ctlfun" } fimg = { git = "https://github.com/bend-n/fimg" } @@ -17,3 +19,9 @@ minifb = "0.28.0" nix = { version = "0.30.1", features = ["process", "term"] } parking_lot = "0.12.3" swash = "0.2.4" + +[profile.release] +debug = 2 +opt-level = 3 +lto = "thin" +incremental = true diff --git a/src/main.rs b/src/main.rs index 1ac0044..4f2245a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -200,7 +200,7 @@ fn main() -> Result<()> { let (fw, fh) = render::dims(&FONT, ppem); let cols = (w.get_size().0 as f32 / fw).floor() as u16 - 1; let rows = (w.get_size().1 as f32 / fh).floor() as u16 - 1; - dbg!(rows, cols); + println!("{}x{}", rows, cols); let mut t = Terminal::new((cols, rows), false); unsafe { let x = winsize { @@ -225,6 +225,7 @@ fn main() -> Result<()> { t.rx(char, pty.as_fd()); } } + // dbg!(t.cells.get_at((1, 1))); let i = render::render(&mut t, w.get_size(), ppem); let x = Image::<Box<[u32]>, 1>::from(i.as_ref()); w.update_with_buffer(x.buffer(), w.get_size().0, w.get_size().1)?; diff --git a/src/render.rs b/src/render.rs index 1ae2793..35ba979 100644 --- a/src/render.rs +++ b/src/render.rs @@ -119,7 +119,7 @@ pub fn render( unsafe { i.as_mut().overlay_at( &cell, - 4 + ((x.cursor.0) as f32 * sz) as u32, + 4 + ((x.cursor.0 - 1) as f32 * sz) as u32, (x.cursor.1 as f32 * (ppem * 1.25)) as u32 - 20, ) }; diff --git a/src/term.rs b/src/term.rs index b6e1fe6..2196618 100644 --- a/src/term.rs +++ b/src/term.rs @@ -56,7 +56,6 @@ impl Terminal { match self.p.parse_byte(x) { Continue => {} Char(x) => { - self.cursor.0 += 1; if self.cursor.0 >= self.cells.c() { println!("overflow"); self.cursor.0 = 1; @@ -72,10 +71,11 @@ impl Terminal { c.letter = Some(x); c.style = self.style; eprintln!( - "@ {} (mx {w}) c={}", - self.cursor.0, + "@ {:?} (mx {w}) c={}", + self.cursor, c.letter.unwrap() ); + self.cursor.0 += 1; } Control(ControlFunction { start: b'', @@ -236,7 +236,7 @@ impl Terminal { }) => { super::write( pty, - format!("\x1b[{};{}R", self.cells.r(), self.cells.c()) + format!("\x1b[{};{}R", self.cursor.1, self.cursor.0) .as_bytes(), ) .unwrap(); @@ -303,6 +303,14 @@ impl Terminal { } Control(ControlFunction { start: b'[', + params: [y, x], + end: b'f', + .. + }) => { + self.cursor = (x.value_or(1) as _, y.value_or(1)); + } + Control(ControlFunction { + start: b'[', params: [Value(n)], end: b'h' | b'l', .. diff --git a/src/term/cells.rs b/src/term/cells.rs index 033a534..66b163c 100644 --- a/src/term/cells.rs +++ b/src/term/cells.rs @@ -4,7 +4,7 @@ pub struct Cells { pub cells: Vec<Cell>, pub row: u16, } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] pub struct Style { pub bg: [u8; 3], pub color: [u8; 3], @@ -24,7 +24,7 @@ impl std::default::Default for Style { } } -#[derive(Clone, Copy, Default)] +#[derive(Clone, Copy, Default, Debug)] pub struct Cell { pub style: Style, pub letter: Option<char>, @@ -32,12 +32,10 @@ pub struct Cell { impl Cells { pub fn new((c, r): (u16, u16)) -> Self { + let (c, r) = (c + 1, r + 1); Self { - size: (c + 1, r + 1), - cells: vec![ - Cell::default(); - (c as usize + 1) * (r as usize + 1) - ], + size: (c, r), + cells: vec![Cell::default(); (c as usize) * (r as usize)], row: 0, } } |