Skip to main content

promkit_widgets/
jsonstream.rs

1use promkit_core::{Pane, PaneFactory};
2
3#[path = "jsonstream/jsonstream.rs"]
4mod inner;
5pub use inner::JsonStream;
6pub mod config;
7pub use config::Config;
8pub mod jsonz;
9
10/// Represents the state of a JSON stream within the application.
11///
12/// This struct holds the current JSON stream being processed and provides
13/// methods to interact with and manipulate the stream according to the
14/// application's needs. It also contains a theme configuration for styling
15/// the JSON output.
16#[derive(Clone)]
17pub struct State {
18    /// The current JSON stream being processed.
19    pub stream: JsonStream,
20
21    /// Configuration for rendering and behavior.
22    pub config: Config,
23}
24
25impl PaneFactory for State {
26    fn create_pane(&self, width: u16, height: u16) -> Pane {
27        let height = match self.config.lines {
28            Some(lines) => lines.min(height as usize),
29            None => height as usize,
30        };
31
32        let rows = self.stream.extract_rows_from_current(height);
33        let formatted_rows = self.config.format_for_terminal_display(&rows, width);
34
35        Pane::new(formatted_rows, 0)
36    }
37}