mod input;
mod password;
mod selection;
pub use input::Input;
pub use password::Password;
pub use selection::Selection;
pub struct ZenConsoleInput;
impl ZenConsoleInput {
pub fn new() -> Self {
ZenConsoleInput
}
pub fn input(&self) -> Input {
Input::new()
}
pub fn selection(&self) -> Selection {
Selection::new()
}
pub fn password(&self) -> Password {
Password::new()
}
#[cfg(feature = "editor")]
pub(crate) fn edit_in_external_editor(initial_content: &str) -> std::io::Result<String> {
use std::fs::File;
use std::io::{self, Read, Write};
use std::process::Command;
use tempfile::NamedTempFile;
let mut temp_file = NamedTempFile::new()?;
write!(temp_file, "{}", initial_content)?;
let editor = std::env::var("EDITOR").unwrap_or_else(|_| "vi".to_string());
let status = Command::new(editor).arg(temp_file.path()).status()?;
if !status.success() {
return Err(io::Error::new(
io::ErrorKind::Other,
"Editor exited with non-zero status",
));
}
let mut content = String::new();
File::open(temp_file.path())?.read_to_string(&mut content)?;
Ok(content)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_zen_console_input_creation() {
let _zci = ZenConsoleInput::new();
}
}