From 8bb48f89b2efa45c82a7dd64bb15e3f3ce6a084e Mon Sep 17 00:00:00 2001 From: fdai7381 Date: Mon, 16 Jan 2023 21:58:16 +0100 Subject: [PATCH] feat: add simple prompt --- src/main.rs | 8 +++++++- src/prompt.rs | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/prompt.rs diff --git a/src/main.rs b/src/main.rs index ce2ebde..935329e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,17 @@ +mod prompt; + use rustyline::error::ReadlineError; use rustyline::{Editor, Result}; +use crate::prompt::Prompt; + fn main() -> Result<()> { let mut rl = Editor::<()>::new()?; + let mut prompt = Prompt::new(); + loop { - let readline = rl.readline("» "); + let readline = rl.readline(&prompt.get_prompt()); match readline { Ok(line) => { diff --git a/src/prompt.rs b/src/prompt.rs new file mode 100644 index 0000000..c5fabb9 --- /dev/null +++ b/src/prompt.rs @@ -0,0 +1,11 @@ +pub struct Prompt {} + +impl Prompt { + pub fn new() -> Self { + Self {} + } + + pub fn get_prompt(&mut self) -> String { + format!("» ") + } +}