small software-rendered rust tty
add ICH?
bendn 9 months ago
parent e1f58bd · commit 4b755a0
-rw-r--r--src/main.rs7
-rw-r--r--src/term.rs9
-rw-r--r--src/term/cells.rs20
3 files changed, 30 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index b0f907f..fadd92b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -136,6 +136,7 @@ fn main() -> Result<()> {
Period => b".",
Slash if shifting => b"?",
Slash => b"/",
+ Backslash if shifting => b"|",
Backslash => b"\\",
Backspace => b"",
Equal if shifting => b"+",
@@ -194,8 +195,10 @@ fn main() -> Result<()> {
}
});
- sleep(Duration::from_millis(100));
- w.update();
+ while w.get_size().0 < 20 || w.get_size().0 > 5000 {
+ sleep(Duration::from_millis(10));
+ w.update();
+ }
let ppem = 20.0;
let (fw, fh) = render::dims(&FONT, ppem);
let cols = (w.get_size().0 as f32 / fw).floor() as u16 - 1;
diff --git a/src/term.rs b/src/term.rs
index 9130beb..f59597b 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -243,6 +243,15 @@ impl Terminal {
}
Control(ControlFunction {
start: b'[',
+ params: [p],
+ end: b'@',
+ ..
+ }) => {
+ let count = p.value_or(1);
+ self.cells.insert_chars(count, self.cursor);
+ }
+ Control(ControlFunction {
+ start: b'[',
params: [x],
end: b'X',
..
diff --git a/src/term/cells.rs b/src/term/cells.rs
index 66b163c..99a887f 100644
--- a/src/term/cells.rs
+++ b/src/term/cells.rs
@@ -11,7 +11,7 @@ pub struct Style {
pub flags: u8,
}
use std::default::Default::default;
-use std::iter::{repeat, repeat_n};
+use std::iter::{empty, repeat, repeat_n};
use crate::colors;
impl std::default::Default for Style {
@@ -57,10 +57,14 @@ impl Cells {
self.size.0
}
#[track_caller]
+ fn at(&mut self, (x, y): (u16, u16)) -> usize {
+ self.offset() + ((y - 1) * self.c() + x - 1) as usize
+ }
+ #[track_caller]
pub fn get_at(&mut self, (x, y): (u16, u16)) -> &mut Cell {
- let w = self.c();
assert!(x < self.c() && y < self.r(), "out of bounds");
- &mut self.cells()[((y - 1) * w + x - 1) as usize]
+ let i = self.at((x, y));
+ &mut self.cells[i]
}
pub fn rows(&mut self) -> impl Iterator<Item = &mut [Cell]> {
let w = self.c();
@@ -72,7 +76,7 @@ impl Cells {
[(row as usize - 1) * w as usize..row as usize * w as usize]
}
pub fn past(&mut self, (x, row): (u16, u16)) -> &mut [Cell] {
- &mut self.rows().nth(row as usize - 1).unwrap()[x as usize..]
+ &mut self.rows().nth(row as usize - 1).unwrap()[x as usize - 1..]
}
pub fn grow(&mut self, by: u16) {
self.row += by;
@@ -82,6 +86,14 @@ impl Cells {
));
}
+ pub fn insert_chars(&mut self, characters: u16, (x, y): (u16, u16)) {
+ let s = &mut self.row(y)[x as usize - 1..];
+ s.rotate_right(characters as usize);
+ s[..characters as usize].fill(Cell::default());
+ let w = self.c();
+ self.row(y)[w as usize - characters as usize..]
+ .fill(Cell::default());
+ }
pub fn insert_lines(&mut self, lines: u16, below: u16) {
let c = self.c();
let o = self.offset();