leo_interpreter/
dialoguer_input.rs1use super::ui::{Ui, UserData};
18
19use colored::*;
20
21pub struct DialoguerUi {
22 history: dialoguer::BasicHistory,
23}
24
25impl DialoguerUi {
26 pub fn new() -> Self {
27 DialoguerUi { history: dialoguer::BasicHistory::new() }
28 }
29}
30
31impl Ui for DialoguerUi {
32 fn display_user_data(&mut self, data: &UserData<'_>) {
33 if let Some(result) = data.result {
34 println!("{}: {}", "Result".bold(), result.bright_cyan());
35 }
36 println!("{}", data.message);
37 if let Some(highlight_span) = data.highlight {
38 let first = data.code.get(0..highlight_span.0).expect("spans should be valid");
39 let second = data.code.get(highlight_span.0..highlight_span.1).expect("spans should be valid");
40 let third = data.code.get(highlight_span.1..).expect("spans should be valid");
41 println!("{first}{}{third}", second.red());
42 } else {
43 println!("{}", data.code);
44 }
45
46 for (i, future) in data.futures.iter().enumerate() {
47 println!("{i:>4}: {future}");
48 }
49
50 for (i, watchpoint) in data.watchpoints.iter().enumerate() {
51 println!("{i:>4}: {watchpoint}");
52 }
53 }
54
55 fn receive_user_input(&mut self) -> String {
56 dialoguer::Input::with_theme(&dialoguer::theme::ColorfulTheme::default())
57 .with_prompt("Command?")
58 .history_with(&mut self.history)
59 .interact_text()
60 .unwrap()
61 }
62}