-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_term.rs
119 lines (93 loc) · 2.48 KB
/
fake_term.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
use std::collections::VecDeque;
use std::io::Write;
use promptuity::event::*;
use promptuity::{CursorPosition, Error, TermSize, Terminal};
pub struct Term {
output: Vec<u8>,
actions: VecDeque<(KeyCode, KeyModifiers)>,
}
impl Term {
pub fn new(actions: &[(KeyCode, KeyModifiers)]) -> Self {
let actions = VecDeque::from(actions.to_vec());
Self {
output: vec![],
actions,
}
}
pub fn output(&self) -> String {
String::from_utf8(self.output.clone()).unwrap()
}
}
impl Terminal<Vec<u8>> for Term {
fn writer(&mut self) -> &mut Vec<u8> {
self.output.as_mut()
}
fn size(&self) -> Result<TermSize, Error> {
Ok(TermSize::new(80, 40))
}
fn enable_raw(&mut self) -> Result<(), Error> {
Ok(())
}
fn disable_raw(&mut self) -> Result<(), Error> {
Ok(())
}
fn cursor_show(&mut self) -> Result<(), Error> {
Ok(())
}
fn cursor_hide(&mut self) -> Result<(), Error> {
Ok(())
}
fn cursor_pos(&self) -> Result<CursorPosition, Error> {
todo!()
}
fn move_to(&mut self, _: u16, _: u16) -> Result<(), Error> {
Ok(())
}
fn move_column(&mut self, _: u16) -> Result<(), Error> {
Ok(())
}
fn move_next_line(&mut self, _: u16) -> Result<(), Error> {
Ok(())
}
fn move_previous_line(&mut self, _: u16) -> Result<(), Error> {
Ok(())
}
fn scroll_up(&mut self, _: u16) -> Result<(), Error> {
Ok(())
}
fn scroll_down(&mut self, _: u16) -> Result<(), Error> {
Ok(())
}
fn clear(&mut self) -> Result<(), Error> {
Ok(())
}
fn clear_purge(&mut self) -> Result<(), Error> {
Ok(())
}
fn clear_current_line(&mut self) -> Result<(), Error> {
Ok(())
}
fn clear_cursor_up(&mut self) -> Result<(), Error> {
Ok(())
}
fn clear_cursor_down(&mut self) -> Result<(), Error> {
Ok(())
}
fn write(&mut self, value: &str) -> Result<(), Error> {
self.output.write_all(value.as_bytes())?;
Ok(())
}
fn writeln(&mut self, value: &str) -> Result<(), Error> {
for line in value.lines() {
self.write(line)?;
self.write("\n")?;
}
Ok(())
}
fn flush(&mut self) -> Result<(), Error> {
Ok(())
}
fn read_key(&mut self) -> Result<(KeyCode, KeyModifiers), Error> {
Ok(self.actions.pop_front().unwrap())
}
}