1
//! The read-only category CSV pane.
2

            
3
use crate::event::Intent;
4
use tvui::RowWindow;
5

            
6
use crate::scroll;
7

            
8
#[derive(Debug)]
9
pub 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

            
17
impl Csv {
18
    #[must_use]
19
15
    pub fn new(file_name: String, text: String) -> Self {
20
15
        let lines = text.lines().map(str::to_string).collect();
21
15
        Self {
22
15
            text,
23
15
            lines,
24
15
            scroll: RowWindow::default(),
25
15
            file_name,
26
15
        }
27
15
    }
28

            
29
1
    pub fn scroll_by(&self, intent: Intent) {
30
1
        let _ = scroll::apply(&self.scroll, intent);
31
1
    }
32
}