highlight_demo/
highlight_demo.rs1use lv_tui::prelude::*;
2use lv_tui_code_highlight::CodeView;
3
4const CODE: &str = r#"fn main() {
5 // A simple greeting
6 let name = "lv-tui";
7 println!("Hello, {}!", name);
8
9 for i in 0..5 {
10 println!("Line {}", i);
11 }
12}
13"#;
14
15struct App { view: CodeView }
16
17impl App {
18 fn new() -> Self { Self { view: CodeView::new(CODE, "rust") } }
19}
20
21impl Component for App {
22 fn render(&self, cx: &mut RenderCx) { self.view.render(cx); }
23 fn event(&mut self, e: &Event, cx: &mut EventCx) {
24 if e.is_key(Key::Char('q')) { cx.quit(); return; }
25 self.view.event(e, cx);
26 }
27 fn layout(&mut self, r: lv_tui::geom::Rect, cx: &mut lv_tui::component::LayoutCx) { self.view.layout(r, cx); }
28 fn measure(&self, c: lv_tui::layout::Constraint, _cx: &mut lv_tui::component::MeasureCx) -> lv_tui::geom::Size {
29 lv_tui::geom::Size { width: c.max.width, height: c.max.height }
30 }
31 fn focusable(&self) -> bool { false }
32}
33
34fn main() -> lv_tui::Result<()> {
35 lv_tui::app::App::new(App::new()).run()
36}