gnuplot_wrapper/process/
gnuplot_live_process.rs

1use std::{io::Write, process::Child};
2
3use crate::{figure::Figure, process::gnuplot_process::GnuplotProcess};
4
5pub struct GnuplotLiveProcess {
6    child: Child
7}
8
9impl GnuplotProcess for GnuplotLiveProcess {
10    fn new(child: Child) -> Self {
11        return GnuplotLiveProcess { child: child };
12    }
13
14    fn wait(&mut self) {
15        self.child.wait().unwrap();
16    }
17}
18
19impl GnuplotLiveProcess {
20    pub fn write(&mut self, command: &str) {
21        self.child.stdin.as_mut().unwrap().write_fmt(format_args!("{}\n", command)).unwrap();
22    }
23
24    pub fn plot_figure(&mut self, figure: Figure) {
25        let lines = figure.compile();
26        for line in lines {
27            self.write(line.as_str());
28        }
29        figure.clear();
30    }
31}