independant_editor/
independant_editor.rs

1use std::{fs, path::PathBuf, str::FromStr, thread::sleep, time::Duration};
2
3use open_editor::EditorCallBuilder;
4
5/// This example is not very practical with TUI editors but it shows how to
6/// spawn an editor and do other stuff.
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    let filename = PathBuf::from_str("./test")?;
9
10    // Spawn editor without waiting
11    EditorCallBuilder::new()
12        .wait_for_editor(false)
13        .open_file(&filename)?;
14
15    println!("Editor launched. Press Ctrl+C to stop.\n");
16
17    loop {
18        let contents = fs::read_to_string(&filename).unwrap_or_default();
19
20        println!("--- Content of {} ---\n{}\n", filename.display(), contents);
21
22        sleep(Duration::from_secs(1));
23    }
24}