forked from jacklund/repl-rs
-
Notifications
You must be signed in to change notification settings - Fork 15
/
prompt.rs
56 lines (50 loc) · 1.56 KB
/
prompt.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use reedline::{DefaultPrompt, Prompt, PromptEditMode, PromptHistorySearch};
use std::borrow::Cow;
#[derive(Clone)]
pub struct ReplPrompt {
default: DefaultPrompt,
prefix: String,
}
impl Prompt for ReplPrompt {
/// Use prefix as render prompt
fn render_prompt_left(&self) -> Cow<str> {
{
Cow::Borrowed(&self.prefix)
}
}
// call default impl
fn render_prompt_right(&self) -> Cow<str> {
self.default.render_prompt_right()
}
fn render_prompt_indicator(&self, edit_mode: PromptEditMode) -> Cow<str> {
self.default.render_prompt_indicator(edit_mode)
}
fn render_prompt_multiline_indicator(&self) -> Cow<str> {
self.default.render_prompt_multiline_indicator()
}
fn render_prompt_history_search_indicator(
&self,
history_search: PromptHistorySearch,
) -> Cow<str> {
self.default
.render_prompt_history_search_indicator(history_search)
}
}
impl Default for ReplPrompt {
fn default() -> Self {
ReplPrompt::new("repl")
}
}
impl ReplPrompt {
/// Constructor for the default prompt, which takes the amount of spaces required between the left and right-hand sides of the prompt
pub fn new(left_prompt: &str) -> ReplPrompt {
ReplPrompt {
prefix: left_prompt.to_string(),
default: DefaultPrompt::default(),
}
}
#[allow(dead_code)]
pub fn update_prefix(&mut self, prefix: &str) {
self.prefix = prefix.to_string();
}
}