diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2019-12-13 19:24:22 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-12-13 19:24:22 +0100 |
commit | fd1cacded7523724e57a2bec2dfaf0a867dabdf7 (patch) | |
tree | 515b0f8ed3b93d1e31fec9a3ceb0d4162838b6fc /src/edit.rs | |
parent | b8e15051ff6a845b252a8f86f8a17ccad87b4336 (diff) | |
parent | b3dc95542b7a0aca38e9b196d30f25f7defecf1b (diff) |
Merge branch 'extract-libical'
Diffstat (limited to 'src/edit.rs')
-rw-r--r-- | src/edit.rs | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/src/edit.rs b/src/edit.rs deleted file mode 100644 index c1e94e7..0000000 --- a/src/edit.rs +++ /dev/null @@ -1,46 +0,0 @@ -use std::env; -use std::fs; -use std::path::Path; -use std::process::Command; - -use crate::khline::KhLine; -use crate::KhResult; -use crate::utils::stdioutils; - -pub fn edit_loop(path: &Path) -> KhResult<()> { - loop { - edit_file(path)?; - let edited_cal = KhLine::new(path, None).to_cal()?; - if let Some(errors) = edited_cal.check_for_errors() { - if !ask_continue_editing(&errors) { - return Err("editing aborted by user")?; - } - } else { - return Ok(()); - } - } -} - -fn edit_file(path: &Path) -> KhResult<()> { - if cfg!(test) { return Ok(()) }; - - let editor = env::var("EDITOR").unwrap_or_else(|_| "vim".to_string()); - - Command::new(&editor) - .arg(path.as_os_str()) - .stdin(fs::File::open("/dev/tty").unwrap()) - .status()?; - - Ok(()) -} - -fn ask_continue_editing(error: &[String]) -> bool { - println!("Calendar contains errors:\n{}", error.join("\n")); - println!("Continue editing? y/n:"); - - match stdioutils::read_single_char_from_stdin().unwrap() { - 'y' => true, - _ => false - } -} - |