blob: 258718eb797d2cef603e3a745786049db665ccde (
plain) (
blame)
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
|
use textmode::Textmode as _;
pub struct Repl {
prompt: String,
input_line: String,
}
impl Repl {
pub fn new() -> Self {
Self {
prompt: "$ ".into(),
input_line: "".into(),
}
}
pub fn input(&self) -> String {
self.input_line.clone()
}
pub fn add_input(&mut self, s: &str) {
self.input_line.push_str(s);
}
pub fn backspace(&mut self) {
self.input_line.pop();
}
pub fn clear_input(&mut self) {
self.input_line.clear();
}
pub fn lines(&self) -> usize {
1 // XXX handle wrapping, multiline prompts
}
pub async fn render(
&self,
out: &mut textmode::Output,
) -> anyhow::Result<()> {
out.move_to(23, 0);
out.write_str(&self.prompt);
out.write_str(&self.input_line);
Ok(())
}
}
|