use promkit_core::{Widget, grapheme::StyledGraphemes};
mod document;
pub use document::Document;
pub mod config;
pub use config::Config;
pub mod jsonz;
use crate::structured::PrettyRender;
#[derive(Clone)]
pub struct State {
pub document: Document,
pub config: Config,
}
impl Widget for State {
fn create_graphemes(&self, width: u16, height: u16) -> StyledGraphemes {
let height = match self.config.lines {
Some(lines) => lines.min(height as usize),
None => height as usize,
};
let rows = self.document.extract_rows_from_current(height);
let formatted_rows = self.config.render_terminal_rows(&rows, width);
StyledGraphemes::from_lines(formatted_rows)
}
}
impl State {
pub fn render_pretty_json(&self) -> String {
self.document.rows().render_pretty(self.config.indent)
}
}