gnuplot_wrapper/
gnuplot.rsuse std::process::{Child, Command, Stdio};
use crate::{
process::{gnuplot_live_process::GnuplotLiveProcess, gnuplot_process::GnuplotProcess, gnuplot_script_process::GnuplorScriptProcess},
script::Script,
};
pub struct Gnuplot {
command: Command,
}
impl Gnuplot {
pub fn new() -> Self {
return Self::new_with_path_str("gnuplot");
}
pub fn new_with_path_str(path: &str) -> Self {
let mut command: Command = Command::new(path.to_string());
command.arg("-p");
return Gnuplot { command: command };
}
pub fn new_with_path(path: &String) -> Self {
return Self::new_with_path_str(&path);
}
pub fn run_live(&mut self) -> GnuplotLiveProcess {
let child: Child = self
.command
.stdin(Stdio::piped())
.spawn()
.expect("Error when running gnuplot");
return GnuplotLiveProcess::new(child);
}
pub fn execute_script(&mut self, script: Script) -> GnuplorScriptProcess {
let path = script.get_path().ok_or("Script is not saved!").unwrap();
let child: Child = self
.command
.arg(path)
.spawn()
.expect("Error when running gnuplot");
return GnuplorScriptProcess::new(child);
}
}