aboutsummaryrefslogtreecommitdiff
path: root/rprt-engine/src/buffer.rs
diff options
context:
space:
mode:
authortslil <tslil@posteo.de>2025-10-19 18:42:21 +0100
committertslil <tslil@posteo.de>2025-10-19 19:23:49 +0100
commitdad36ca43f02fed93b51733308a2b440838b5943 (patch)
tree378e1e7cb64eefe8bfd8d9fd77d8f9603560537f /rprt-engine/src/buffer.rs
parent3a13599095b1aaf69f949447251124a03bdf03a9 (diff)
Porting over EditorState
Diffstat (limited to 'rprt-engine/src/buffer.rs')
-rw-r--r--rprt-engine/src/buffer.rs35
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,
+ }
}
}