Skip to main content

tui/modal/
csv.rs

1//! The read-only category CSV pane.
2
3use crate::event::Intent;
4use tvui::RowWindow;
5
6use crate::scroll;
7
8#[derive(Debug)]
9pub struct Csv {
10    pub text: String,
11    pub lines: Vec<String>,
12    pub scroll: RowWindow,
13    /// File name offered by the save prompt.
14    pub file_name: String,
15}
16
17impl Csv {
18    #[must_use]
19    pub fn new(file_name: String, text: String) -> Self {
20        let lines = text.lines().map(str::to_string).collect();
21        Self {
22            text,
23            lines,
24            scroll: RowWindow::default(),
25            file_name,
26        }
27    }
28
29    pub fn scroll_by(&self, intent: Intent) {
30        let _ = scroll::apply(&self.scroll, intent);
31    }
32}