1use crate::{
2 Ed,
3 ui::UI,
4 ui::UILock,
5};
6use super::Result;
7
8#[derive(Debug, PartialEq)]
10pub struct Print {
11 pub text: Vec<String>,
13 pub n: bool,
15 pub l: bool,
17}
18
19pub struct MockUI {
21 pub prints_history: Vec<Print>,
22}
23
24impl UI for MockUI {
25 fn print_message(
26 &mut self,
27 data: &str,
28 ) -> Result<()> {
29 self.prints_history.push(
30 Print{
31 text: vec![data.to_owned()],
32 n: false,
33 l: false,
34 }
35 );
36 Ok(())
37 }
38
39 fn print_command_documentation(&mut self) -> Result<()> {
40 self.print_message(crate::messages::COMMAND_DOCUMENTATION)
41 }
42
43 fn print_selection(
44 &mut self,
45 ed: &Ed,
46 selection: (usize, usize),
47 numbered: bool,
48 literal: bool,
49 ) -> Result<()> {
50 self.prints_history.push(
51 Print{
52 text: ed.history.current().get_lines(selection)?
53 .map(|s| s.to_string())
54 .collect()
55 ,
56 n: numbered,
57 l: literal,
58 }
59 );
60 Ok(())
61 }
62
63 fn get_command(
64 &mut self,
65 _ed: &Ed,
66 _prefix: Option<char>,
67 ) -> Result<String> {
68 panic!("get_command not implemented on mock ui")
69 }
70
71 fn get_input(
72 &mut self,
73 _ed: &Ed,
74 _terminator: char,
75 #[cfg(feature = "initial_input_data")]
76 _initial_buffer: Option<Vec<String>>
77 ) -> Result<Vec<String>> {
78 panic!("get_input not implemented on mock ui")
79 }
80
81 fn lock_ui(&mut self) -> UILock<'_> {
82 UILock::new(self)
83 }
84 fn unlock_ui(&mut self){}
85}