Skip to content

Commit

Permalink
add missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Sep 8, 2024
1 parent 44f213d commit bb3d5c1
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions crates/shell/src/helper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use rustyline::{
highlight::Highlighter, validate::MatchingBracketValidator, Completer, Helper, Hinter,
Validator,
};

use crate::completion;

use std::borrow::Cow::Borrowed;

#[derive(Helper, Completer, Hinter, Validator)]
pub(crate) struct ShellPromptHelper {
#[rustyline(Completer)]
completer: completion::ShellCompleter,

#[rustyline(Validator)]
validator: MatchingBracketValidator,

pub colored_prompt: String,
}

impl Default for ShellPromptHelper {
fn default() -> Self {
Self {
completer: completion::ShellCompleter,
validator: MatchingBracketValidator::new(),
colored_prompt: String::new(),
}
}
}

impl Highlighter for ShellPromptHelper {
fn highlight_prompt<'b, 's: 'b, 'p: 'b>(
&'s self,
prompt: &'p str,
default: bool,
) -> std::borrow::Cow<'b, str> {
if default {
Borrowed(&self.colored_prompt)
} else {
Borrowed(prompt)
}
}
}

0 comments on commit bb3d5c1

Please sign in to comment.