small software-rendered rust tty
add more absolute positioning sequences and fix representation
bendn 9 months ago
parent f3849f1 · commit 2b48401
-rw-r--r--.gitignore3
-rw-r--r--src/term.rs106
-rw-r--r--x1
3 files changed, 81 insertions, 29 deletions
diff --git a/.gitignore b/.gitignore
index ffa3bbd..a1922f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
-Cargo.lock \ No newline at end of file
+Cargo.lock
+x \ No newline at end of file
diff --git a/src/term.rs b/src/term.rs
index 8e98039..bf6a78c 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -28,7 +28,10 @@ impl Terminal {
cursor: (1, 1),
size: sz,
row: 0,
- cells: vec![Cell::default(); c as usize * r as usize],
+ cells: vec![
+ Cell::default();
+ (c as usize + 1) * (r as usize + 1)
+ ],
p: default(),
mode: Mode::Normal,
@@ -88,7 +91,7 @@ impl Terminal {
self.cursor.0 = 1;
self.cursor.1 += 1;
}
- while self.cursor.1 >= self.size.1 {
+ while self.cursor.1 > self.size.1 {
println!("newline");
self.cursor.1 -= 1;
// self.cells
@@ -100,15 +103,15 @@ impl Terminal {
self.size.0 as usize,
));
}
- assert!(
- self.cells.len()
- == self.row * self.size.0 as usize
- + self.size.0 as usize * self.size.1 as usize
- );
- assert!(
- self.cells[self.row * self.size.0 as usize..].len()
- == self.size.0 as usize * self.size.1 as usize
- );
+ // assert!(
+ // self.cells.len()
+ // == self.row * self.size.0 as usize
+ // + self.size.0 as usize * self.size.1 as usize
+ // );
+ // assert!(
+ // self.cells[self.row * self.size.0 as usize..].len()
+ // == self.size.0 as usize * self.size.1 as usize
+ // );
// dbg!(self.cursor);
let c = &mut self.cells[self.row * self.size.0 as usize..]
// y*w+x
@@ -116,8 +119,9 @@ impl Terminal {
as usize];
c.letter = Some(x);
c.style = self.style;
+ dbg!(x);
}
- Control(ControlFunction { start: 8, .. }) => {
+ Control(ControlFunction { start: b'', .. }) => {
self.cursor.0 -= 1;
}
Control(ControlFunction {
@@ -196,6 +200,38 @@ impl Terminal {
}
Control(ControlFunction {
start: b'[',
+ params: [Value(y), Value(x)],
+ end: b'H',
+ ..
+ }) => {
+ self.cursor = (*x, *y);
+ }
+ Control(ControlFunction {
+ start: b'[',
+ params: [Default],
+ end: b'H',
+ ..
+ }) => {
+ self.cursor = (1, 1);
+ }
+ Control(ControlFunction {
+ start: b'[',
+ params: [Value(y)],
+ end: b'd',
+ ..
+ }) => {
+ self.cursor.1 = *y;
+ }
+ Control(ControlFunction {
+ start: b'[',
+ params: [Value(x)],
+ end: b'G',
+ ..
+ }) => {
+ self.cursor.0 = *x;
+ }
+ Control(ControlFunction {
+ start: b'[',
end: b'H',
..
}) => {
@@ -294,21 +330,37 @@ impl Terminal {
..
}) => {}
Control(x) => {
- dbg!(x);
- println!(
- "{} {:?} {} {}",
- x.start as char,
- x.params
- .iter()
- .map(|x| match x {
- ctlfun::Parameter::Default =>
- "default".to_string(),
- ctlfun::Parameter::Value(x) => x.to_string(),
- })
- .collect::<Vec<_>>(),
- String::from_utf8_lossy(&x.bytes),
- x.end as char,
- );
+ if x.start == b'[' {
+ println!(
+ "CSI {:?} {}",
+ x.params
+ .iter()
+ .map(|x| match x {
+ ctlfun::Parameter::Default =>
+ "default".to_string(),
+ ctlfun::Parameter::Value(x) =>
+ x.to_string(),
+ })
+ .collect::<Vec<_>>(),
+ x.end as char,
+ )
+ } else {
+ println!(
+ "{} {:?} {} {}",
+ x.start as char,
+ x.params
+ .iter()
+ .map(|x| match x {
+ ctlfun::Parameter::Default =>
+ "default".to_string(),
+ ctlfun::Parameter::Value(x) =>
+ x.to_string(),
+ })
+ .collect::<Vec<_>>(),
+ String::from_utf8_lossy(&x.bytes),
+ x.end as char,
+ );
+ }
}
_ => unreachable!(),
}
diff --git a/x b/x
deleted file mode 100644
index 7ff190c..0000000
--- a/x
+++ /dev/null
@@ -1 +0,0 @@
-]0;os@klunk:~/pattypan[?2004h[os@klunk pattypan]$  [os@klunk pattypan]$ q�d \ No newline at end of file