small software-rendered rust tty
-rw-r--r--src/main.rs3
-rw-r--r--src/term.rs38
2 files changed, 40 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index de5cd0f..66585e4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -34,7 +34,7 @@ fn spawn(shell: &str) -> Result<OwnedFd> {
match x {
ForkptyResult::Child => {
let sh =
- Command::new(shell).env("TERM", "vt100").spawn()?.wait();
+ Command::new(shell).env("TERM", "xterm").spawn()?.wait();
// std::thread::sleep(Duration::from_millis(5000));
// exit(0);
@@ -183,6 +183,7 @@ fn main() -> Result<()> {
dbg!(rows, cols);
let mut t = Terminal {
style: Default::default(),
+ saved_cursor: (1, 1),
cursor: (1, 1),
size: (cols, rows),
row: 0,
diff --git a/src/term.rs b/src/term.rs
index 125fca4..e858c5c 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -7,6 +7,7 @@ use ctlfun::{ControlFunction, TerminalInputParser};
pub struct Terminal {
pub style: Style,
pub cursor: (u16, u16),
+ pub saved_cursor: (u16, u16),
pub size: (u16, u16),
pub cells: Vec<Cell>,
@@ -43,6 +44,12 @@ pub struct Cell {
}
impl Terminal {
+ fn decsc(&mut self) {
+ self.saved_cursor = self.cursor;
+ }
+ fn decrc(&mut self) {
+ self.cursor = self.saved_cursor;
+ }
#[implicit_fn::implicit_fn]
pub fn rx(&mut self, x: u8) {
match self.p.parse_byte(x) {
@@ -192,6 +199,37 @@ impl Terminal {
}) => {
self.cursor.1 += 1;
}
+ Control(
+ ControlFunction {
+ start: b'\x1b',
+ params: [],
+ end: b'7',
+ ..
+ }
+ | ControlFunction {
+ start: b'[',
+ end: b's',
+ ..
+ },
+ ) => {
+ self.decsc();
+ }
+ Control(
+ ControlFunction {
+ start: b'\x1b',
+ params: [],
+ end: b'8',
+ ..
+ }
+ | ControlFunction {
+ start: b'[',
+ end: b'u',
+ ..
+ },
+ ) => {
+ self.decrc();
+ }
+
Control(ControlFunction {
start: b'\x1b',
params: [],