mod ansi;
mod layout;
#[cfg(test)]
mod layout_tests;
mod navigation;
mod render;
mod run;
mod sgr;
mod wrap;
use crate::TxtViewConfig;
#[derive(Debug, Clone)]
pub struct TxtView {
lines: Vec<String>,
display: Vec<String>,
offset: usize,
max_offset: usize,
config: TxtViewConfig,
dragging: bool,
drag_grab_offset: usize,
display_geometry: Option<(usize, usize)>,
#[cfg(test)]
rebuild_count: usize,
}
impl TxtView {
pub fn new(input: impl AsRef<str>) -> Self {
let lines: Vec<String> = input.as_ref().lines().map(String::from).collect();
let mut view = TxtView {
lines,
display: Vec::new(),
offset: 0,
max_offset: 0,
config: TxtViewConfig::default(),
dragging: false,
drag_grab_offset: 0,
display_geometry: None,
#[cfg(test)]
rebuild_count: 0,
};
view.refresh_bounds();
view
}
#[must_use]
pub fn with_config(mut self, config: TxtViewConfig) -> Self {
self.config = config;
self.refresh_bounds();
self
}
pub fn line_count(&self) -> usize {
self.lines.len()
}
pub fn config(&self) -> &TxtViewConfig {
&self.config
}
}