blob: cc9e7bd9d3591a9d444f12440a7dbcd19e8631af (
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
29
30
31
32
33
|
use ansi_to_tui::ansi_to_text;
use tui::buffer::Buffer;
use tui::layout::Rect;
use tui::text::Text;
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 text: Text = ansi_to_text(self.preview.output.as_str().as_bytes().to_vec()).unwrap();
for (line, y) in text
.lines
.iter()
.skip(self.preview.index)
.zip(area.y..area.y + area.height)
{
buf.set_spans(area.x, y, &line, area.width);
}
}
}
|