Move prompt render functionality into a separate module
This commit is contained in:
parent
628da27122
commit
9033bc38bb
15
src/cli.rs
15
src/cli.rs
|
@ -8,11 +8,11 @@ use crate::commands::plugin::{PluginCommand, PluginSink};
|
|||
use crate::commands::whole_stream_command;
|
||||
use crate::context::Context;
|
||||
crate use crate::errors::ShellError;
|
||||
use crate::git::current_branch;
|
||||
use crate::object::Value;
|
||||
use crate::parser::registry::Signature;
|
||||
use crate::parser::{hir, CallNode, Pipeline, PipelineElement, TokenNode};
|
||||
use crate::prelude::*;
|
||||
use crate::prompt::Prompt;
|
||||
|
||||
use log::{debug, trace};
|
||||
use regex::Regex;
|
||||
|
@ -226,27 +226,18 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
|
|||
})
|
||||
.expect("Error setting Ctrl-C handler");
|
||||
let mut ctrlcbreak = false;
|
||||
let prompt = Prompt::new();
|
||||
loop {
|
||||
if ctrl_c.load(Ordering::SeqCst) {
|
||||
ctrl_c.store(false, Ordering::SeqCst);
|
||||
continue;
|
||||
}
|
||||
|
||||
let cwd = context.shell_manager.path();
|
||||
|
||||
rl.set_helper(Some(crate::shell::Helper::new(
|
||||
context.shell_manager.clone(),
|
||||
)));
|
||||
|
||||
let readline = rl.readline(&format!(
|
||||
"{}{}> ",
|
||||
cwd,
|
||||
match current_branch() {
|
||||
Some(s) => format!("({})", s),
|
||||
None => "".to_string(),
|
||||
}
|
||||
));
|
||||
|
||||
let readline = rl.readline(&prompt.render(&context));
|
||||
match process_line(readline, &mut context).await {
|
||||
LineResult::Success(line) => {
|
||||
rl.add_history_entry(line.clone());
|
||||
|
|
|
@ -21,6 +21,7 @@ mod git;
|
|||
mod object;
|
||||
mod parser;
|
||||
mod plugin;
|
||||
mod prompt;
|
||||
mod shell;
|
||||
mod stream;
|
||||
mod traits;
|
||||
|
|
21
src/prompt.rs
Normal file
21
src/prompt.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
use crate::git::current_branch;
|
||||
use crate::prelude::*;
|
||||
|
||||
pub struct Prompt;
|
||||
|
||||
impl Prompt {
|
||||
pub fn new() -> Self {
|
||||
Prompt {}
|
||||
}
|
||||
|
||||
pub fn render(&self, context: &Context) -> String {
|
||||
format!(
|
||||
"{}{}> ",
|
||||
context.shell_manager.path(),
|
||||
match current_branch() {
|
||||
Some(s) => format!("({})", s),
|
||||
None => "".to_string(),
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user