summaryrefslogtreecommitdiffstats
path: root/src/edit.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/edit.rs')
-rw-r--r--src/edit.rs46
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
- }
-}
-