Browse Source

feat: add simple prompt

main
fdai7381 2 years ago
committed by fdai7451
parent
commit
e13863afbf
  1. 8
      src/main.rs
  2. 11
      src/prompt.rs

8
src/main.rs

@ -1,11 +1,17 @@
mod prompt;
use rustyline::error::ReadlineError; use rustyline::error::ReadlineError;
use rustyline::{Editor, Result}; use rustyline::{Editor, Result};
use crate::prompt::Prompt;
fn main() -> Result<()> { fn main() -> Result<()> {
let mut rl = Editor::<()>::new()?; let mut rl = Editor::<()>::new()?;
let mut prompt = Prompt::new();
loop { loop {
let readline = rl.readline("» ");
let readline = rl.readline(&prompt.get_prompt());
match readline { match readline {
Ok(line) => { Ok(line) => {

11
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!("» ")
}
}
Loading…
Cancel
Save