aboutsummaryrefslogtreecommitdiffstats
path: root/src/linebuf.rs
diff options
context:
space:
mode:
authorJonas Maier <>2026-03-05 10:27:10 +0100
committerJonas Maier <>2026-03-05 10:27:10 +0100
commit50fc850f165482a8304681e85a70ffb41dba731d (patch)
tree37d163a5433f6e78eaff116fa09fc09213ecd364 /src/linebuf.rs
parentd62649f0aed0daca805d716819db32d5e9263865 (diff)
downloadpish-50fc850f165482a8304681e85a70ffb41dba731d.tar.gz
allow editing of prev command with backspace
Diffstat (limited to 'src/linebuf.rs')
-rw-r--r--src/linebuf.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/linebuf.rs b/src/linebuf.rs
index 15a8182..1d28549 100644
--- a/src/linebuf.rs
+++ b/src/linebuf.rs
@@ -4,6 +4,7 @@ use std::io::Write;
pub struct LineBuf {
pre: Vec<u8>,
post: Vec<u8>,
+ dirty: bool,
}
#[allow(unused)]
@@ -12,14 +13,17 @@ impl LineBuf {
Self {
pre: Vec::new(),
post: Vec::new(),
+ dirty: false,
}
}
pub fn del_left(&mut self) -> Option<u8> {
+ self.dirty = true;
self.pre.pop()
}
pub fn del_right(&mut self) -> Option<u8> {
+ self.dirty = true;
self.post.pop()
}
@@ -42,6 +46,7 @@ impl LineBuf {
}
pub fn add(&mut self, chr: u8) {
+ self.dirty = true;
self.pre.push(chr);
}
@@ -49,6 +54,10 @@ impl LineBuf {
self.pre.is_empty() && self.post.is_empty()
}
+ pub fn is_dirty(&self) -> bool {
+ self.dirty
+ }
+
/// sets content all to the left
pub fn set_content(&mut self, buf: Vec<u8>) {
self.pre = buf;
@@ -60,6 +69,7 @@ impl LineBuf {
while self.right() {}
let mut buf = Vec::new();
core::mem::swap(&mut self.pre, &mut buf);
+ self.dirty = false;
buf
}