diff options
Diffstat (limited to 'src/repl.rs')
-rw-r--r-- | src/repl.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/repl.rs b/src/repl.rs new file mode 100644 index 0000000..258718e --- /dev/null +++ b/src/repl.rs @@ -0,0 +1,45 @@ +use textmode::Textmode as _; + +pub struct Repl { + prompt: String, + input_line: String, +} + +impl Repl { + pub fn new() -> Self { + Self { + prompt: "$ ".into(), + input_line: "".into(), + } + } + + pub fn input(&self) -> String { + self.input_line.clone() + } + + pub fn add_input(&mut self, s: &str) { + self.input_line.push_str(s); + } + + pub fn backspace(&mut self) { + self.input_line.pop(); + } + + pub fn clear_input(&mut self) { + self.input_line.clear(); + } + + pub fn lines(&self) -> usize { + 1 // XXX handle wrapping, multiline prompts + } + + pub async fn render( + &self, + out: &mut textmode::Output, + ) -> anyhow::Result<()> { + out.move_to(23, 0); + out.write_str(&self.prompt); + out.write_str(&self.input_line); + Ok(()) + } +} |