aboutsummaryrefslogtreecommitdiffstats
path: root/src/linebuf.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/linebuf.rs')
-rw-r--r--src/linebuf.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/linebuf.rs b/src/linebuf.rs
index 1d28549..836cfee 100644
--- a/src/linebuf.rs
+++ b/src/linebuf.rs
@@ -27,6 +27,10 @@ impl LineBuf {
self.post.pop()
}
+ pub fn len(&self) -> usize {
+ self.pre.len() + self.post.len()
+ }
+
pub fn left(&mut self) -> bool {
if let Some(byte) = self.del_left() {
self.post.push(byte);
@@ -64,6 +68,19 @@ impl LineBuf {
self.post = Vec::new();
}
+ pub fn into_bytes(&self) -> Vec<u8> {
+ let mut buf = Vec::with_capacity(self.pre.len() + self.post.len());
+ buf.extend_from_slice(&self.pre);
+ for b in self.post.iter().rev() {
+ buf.push(*b);
+ }
+ buf
+ }
+
+ pub fn distance_from_right_end(&self) -> usize {
+ self.post.len()
+ }
+
/// returns the whole contents of the buffer, and empties it in the process
pub fn dump(&mut self) -> Vec<u8> {
while self.right() {}
@@ -73,12 +90,19 @@ impl LineBuf {
buf
}
+ pub fn clear(&mut self) {
+ self.pre.clear();
+ self.post.clear();
+ self.dirty = false;
+ }
+
/// TODO: kinda ugly that this is here
- pub fn display_post(&self) {
+ pub fn display_post(&self, post: &[u8]) {
for &x in self.post.iter().rev() {
std::io::stdout().write_all(&[x]).unwrap();
}
- move_cursor(Direction::Left, self.post.len());
+ std::io::stdout().write_all(post).unwrap();
+ move_cursor(Direction::Left, self.post.len() + post.len());
std::io::stdout().flush().unwrap();
}
}