blob: 35c7bedf76532ff7eb2b21b23ddaeeb0ae8cfb20 (
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
use ratatui::{style::{Style, Stylize}, text::ToSpan, widgets::Widget};
use crate::lua::iobuffer::iobuffer;
use super::statusbar::StatusBar;
#[derive(Default)]
pub struct LogView {
bar: StatusBar,
}
impl LogView {
pub fn new() -> Self {
Self {
bar: StatusBar::new().left(" Log ").left_style(Style::default().on_magenta()),
}
}
}
impl Widget for &mut LogView {
fn render(self, area: ratatui::prelude::Rect, buf: &mut ratatui::prelude::Buffer)
where
Self: Sized,
{
self.bar.render(area, buf);
let inner_area = self.bar.area(area);
let lines = {
let buffer = iobuffer().read().unwrap();
buffer.get()
};
let mut line_area = inner_area;
line_area.height = 1;
line_area.y = inner_area.y + inner_area.height - 1;
for line in lines.lines().rev() {
let line = line.to_span();
line.render(line_area, buf);
line_area.y -= 1;
if !inner_area.contains(line_area.into()) {
break;
}
}
}
}
|