diff options
Diffstat (limited to 'rprt-engine/src/buffer.rs')
| -rw-r--r-- | rprt-engine/src/buffer.rs | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/rprt-engine/src/buffer.rs b/rprt-engine/src/buffer.rs index f2c6e0f..ab97c44 100644 --- a/rprt-engine/src/buffer.rs +++ b/rprt-engine/src/buffer.rs @@ -4,14 +4,39 @@ use std::process::Command; use std::time::{SystemTime, UNIX_EPOCH}; pub type BufferID = usize; + +#[derive(Debug)] +pub enum BufferState { + Modified, + Unmodified, +} + +#[derive(Debug)] pub struct Buffer { pub content: String, pub name: String, + pub state: BufferState, + pub read_only: bool, + pub ephemeral: bool, } impl Buffer { pub fn new(name: String, content: String) -> Self { - Self { name, content } + Self { + name, + content, + state: BufferState::Unmodified, + read_only: false, + ephemeral: false, + } + } + + pub fn max_pos(&self) -> usize { + self.content.len() + } + + pub fn valid_pos(&self, pos: usize) -> bool { + pos <= self.max_pos() } fn generate_shell_name(command: &str) -> String { @@ -40,6 +65,12 @@ impl Buffer { Err(e) => format!("Command failed: {}", e), }; - Self { name, content } + Self { + name, + content, + read_only: true, + state: BufferState::Unmodified, + ephemeral: true, + } } } |
