-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcustom_prompt.rs
34 lines (29 loc) · 938 Bytes
/
custom_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
use lineeditor::styled_buffer::StyledBuffer;
use lineeditor::LineEditor;
use lineeditor::LineEditorResult;
use lineeditor::Prompt;
pub struct CurrentPathPrompt {}
impl Prompt for CurrentPathPrompt {
fn prompt(&self) -> StyledBuffer {
let path = if let Ok(current_dir) = std::env::current_dir() {
current_dir.to_string_lossy().to_string()
} else {
"".to_owned()
};
let mut styled_buffer = StyledBuffer::default();
styled_buffer.insert_string(&format!("📁 {}> ", path));
styled_buffer
}
}
fn main() {
let prompt = CurrentPathPrompt {};
let mut line_editor = LineEditor::new(Box::new(prompt));
let bindings = line_editor.keybinding();
bindings.register_common_control_bindings();
match line_editor.read_line() {
Ok(LineEditorResult::Success(line)) => {
println!("Line {}", line);
}
_ => {}
}
}