custom_prompt/
custom_prompt.rs

1use lineeditor::styled_buffer::StyledBuffer;
2use lineeditor::LineEditor;
3use lineeditor::LineEditorResult;
4use lineeditor::Prompt;
5
6pub struct CurrentPathPrompt {}
7
8impl Prompt for CurrentPathPrompt {
9    fn prompt(&self) -> StyledBuffer {
10        let path = if let Ok(current_dir) = std::env::current_dir() {
11            current_dir.to_string_lossy().to_string()
12        } else {
13            "".to_owned()
14        };
15        let mut styled_buffer = StyledBuffer::default();
16        styled_buffer.insert_string(&format!("📁 {}> ", path));
17        styled_buffer
18    }
19}
20
21fn main() {
22    let prompt = CurrentPathPrompt {};
23    let mut line_editor = LineEditor::new(Box::new(prompt));
24
25    let bindings = line_editor.keybinding();
26    bindings.register_common_control_bindings();
27
28    match line_editor.read_line() {
29        Ok(LineEditorResult::Success(line)) => {
30            println!("Line {}", line);
31        }
32        _ => {}
33    }
34}