Skip to main content

html_view/
main.rs

1//! The [`Html`] view on its own: a whole HTML fragment as the screen.
2//!
3//! ```bash
4//! cargo run -p tuika-html --example html_view # a real terminal (q quits)
5//! ```
6//!
7//! The companion example, `html_markdown`, shows the *boundary* — HTML blocks
8//! inside a markdown document. This one shows the **component**: no markdown
9//! anywhere, `Html` placed in a layout exactly like `Markdown` would be, fitting
10//! its content to whatever width the pane gives it.
11
12use tuika::prelude::*;
13use tuika::testing::{grid, render};
14use tuika_html::Html;
15
16/// Shared with the demo generator so the recording cannot drift from the app.
17const PAGE: &str = include_str!("page.html");
18
19fn scene() -> Element {
20    let page = Boxed::new(element(Html::new(PAGE)))
21        .title(" ada.html ")
22        .padding(Padding::symmetric(2, 1));
23    let hints = KeyHints::new([("q", "quit")]);
24    view! {
25        col(padding = Padding::all(1), gap = 1) {
26            grow(1) { node(page) }
27            fixed(1) { node(hints) }
28        }
29    }
30}
31
32fn main() -> std::io::Result<()> {
33    let theme = Theme::default();
34    if std::env::args().any(|a| a == "--dump") {
35        for line in grid(&render(scene().as_ref(), 78, 44, &theme)).lines() {
36            println!("{}", line.trim_end());
37        }
38        return Ok(());
39    }
40
41    let runner = Runner::new(RunnerConfig::default());
42    runner.run(
43        &theme,
44        from_fn(
45            &mut (),
46            |(), _frame| scene(),
47            |(), signal| match signal {
48                Signal::Event(Event::Key(key))
49                    if matches!(key.code, KeyCode::Char('q') | KeyCode::Esc) =>
50                {
51                    UpdateResult::Exit
52                }
53                _ => UpdateResult::Clean,
54            },
55        ),
56    )
57}