summaryrefslogtreecommitdiffstats
path: root/src/ui/widgets/tui_file_preview.rs
blob: 75e378c968e472b7a23d96173ccf77d73dcfef8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use tui::buffer::Buffer;
use tui::layout::Rect;
use tui::style::{Color, Modifier, Style};
use tui::widgets::Widget;

use crate::fs::JoshutoDirEntry;
use crate::preview::preview_file::FilePreview;

pub struct TuiFilePreview<'a> {
    _entry: &'a JoshutoDirEntry,
    preview: &'a FilePreview,
}

impl<'a> TuiFilePreview<'a> {
    pub fn new(_entry: &'a JoshutoDirEntry, preview: &'a FilePreview) -> Self {
        Self { _entry, preview }
    }
}

impl<'a> Widget for TuiFilePreview<'a> {
    fn render(self, area: Rect, buf: &mut Buffer) {
        let style = Style::default();
        let area_width = area.width as usize;
        for (y, s) in (area.y..area.y + area.height).zip(self.preview.output.as_str().split('\n')) {
            buf.set_stringn(area.x, y, s, area_width, style);
        }
    }
}