gooey/presentation/
headless.rs

1//! A no-op backend
2
3use log;
4use crate::Tree;
5use crate::tree::NodeId;
6use crate::interface::{view, View};
7use super::{Graphics, Presentation};
8
9/// A presentation implementation where display values are ignored.
10///
11/// Input is read in lines from stdin-- `control::Input::Text (line)` is the
12/// only input event ever generated.
13#[derive(Default)]
14pub struct Headless { }
15impl Graphics     for Headless { }
16impl Presentation for Headless {
17  fn with_root (_ : View, _ : NodeId) -> Self {
18    Self::default()
19  }
20  /// Ignores display values and reads lines from stdin.
21  ///
22  /// Panics if input buffer is non-empty.
23  fn get_input (&mut self,
24    input_buffer : &mut Vec <view::Input>
25  ) {
26    log::trace!("update...");
27    debug_assert!(input_buffer.is_empty());
28    let mut line = String::new();
29    let _ = std::io::stdin().read_line (&mut line).unwrap();
30    input_buffer.push (view::input::Text::String (line).into());
31    log::trace!("...update");
32  }
33
34  fn display_view <V : AsRef <View>> (&mut self,
35    _view_tree      : &Tree <V>,
36    _display_values : std::vec::Drain <(NodeId, view::Display)>
37  ) { /* headless */ }
38}