use anyhow::{Context, Result, ensure}; use std::{io::Write, process::Command}; pub fn open(lines: &[String]) -> Result<()> { let editor = std::env::var("EDITOR").unwrap_or_else(|_| "vi".into()); let args = shell_words::split(&editor).context("Invalid quoting in EDITOR")?; ensure!( !args.is_empty(), "EDITOR is empty; configure an editor command" ); let mut snapshot = tempfile::Builder::new() .prefix("roentgen-logs-") .suffix(".txt") .tempfile()?; for line in lines { writeln!(snapshot, "{}", crate::model::display_text(line))?; } snapshot.flush()?; let status = Command::new(&args[0]) .args(&args[1..]) .arg(snapshot.path()) .status() .context("Could not launch EDITOR")?; ensure!(status.success(), "Editor exited unsuccessfully"); Ok(()) }