1mod input;
8mod password;
9mod selection;
10
11pub use input::Input;
12pub use password::Password;
13pub use selection::Selection;
14
15pub struct ZenConsoleInput;
19
20impl ZenConsoleInput {
21 pub fn new() -> Self {
23 ZenConsoleInput
24 }
25
26 pub fn input(&self) -> Input {
28 Input::new()
29 }
30
31 pub fn selection(&self) -> Selection {
33 Selection::new()
34 }
35
36 pub fn password(&self) -> Password {
38 Password::new()
39 }
40
41 #[cfg(feature = "editor")]
45 pub(crate) fn edit_in_external_editor(initial_content: &str) -> std::io::Result<String> {
46 use std::fs::File;
47 use std::io::{self, Read, Write};
48 use std::process::Command;
49 use tempfile::NamedTempFile;
50
51 let mut temp_file = NamedTempFile::new()?;
52 write!(temp_file, "{}", initial_content)?;
53
54 let editor = std::env::var("EDITOR").unwrap_or_else(|_| "vi".to_string());
55 let status = Command::new(editor).arg(temp_file.path()).status()?;
56
57 if !status.success() {
58 return Err(io::Error::new(
59 io::ErrorKind::Other,
60 "Editor exited with non-zero status",
61 ));
62 }
63
64 let mut content = String::new();
65 File::open(temp_file.path())?.read_to_string(&mut content)?;
66 Ok(content)
67 }
68}
69
70#[cfg(test)]
71mod tests {
72 use super::*;
73
74 #[test]
75 fn test_zen_console_input_creation() {
76 let _zci = ZenConsoleInput::new();
77 }
78}