feat: implement max scrollback in debug view

This commit is contained in:
Gabriele Musco 2023-10-11 23:56:21 +02:00
commit cdf3c2fa13
No known key found for this signature in database
GPG key ID: 1068D795C80E51DE

View file

@ -48,6 +48,8 @@ pub struct DebugView {
pub struct DebugViewInit {}
const MAX_SCROLLBACK: i32 = 2000;
#[relm4::component(pub)]
impl SimpleComponent for DebugView {
type Init = DebugViewInit;
@ -209,6 +211,12 @@ impl SimpleComponent for DebugView {
textview.scroll_mark_onscreen(&end_mark);
});
}
while self.textbuf.line_count() > MAX_SCROLLBACK {
let mut start = self.textbuf.start_iter();
let mut end = self.textbuf.start_iter();
end.forward_line();
self.textbuf.delete(&mut start, &mut end);
}
}
Self::Input::ClearLog => {
self.textbuf.set_text("");