more work on vi line editing

This commit is contained in:
2025-05-20 02:55:41 -04:00
parent b30de3232b
commit 25534d4cd9
4 changed files with 519 additions and 152 deletions

View File

@@ -92,6 +92,25 @@ impl Terminal {
}
KeyEvent(KeyCode::Null, ModKeys::empty())
}
pub fn cursor_pos(&self) -> (usize, usize) {
self.write("\x1b[6n");
let mut buf = [0u8;32];
let n = self.read_byte(&mut buf);
let response = std::str::from_utf8(&buf[..n]).unwrap_or("");
let mut row = 0;
let mut col = 0;
if let Some(caps) = response.strip_prefix("\x1b[").and_then(|s| s.strip_suffix("R")) {
let mut parts = caps.split(';');
if let (Some(rowstr), Some(colstr)) = (parts.next(), parts.next()) {
row = rowstr.parse().unwrap_or(1);
col = colstr.parse().unwrap_or(1);
}
}
(row,col)
}
}
impl Default for Terminal {