split/
split.rs

1//! Show how split views can be used.
2
3use tuit::prelude::*;
4use tuit::std::stdout_render::StdoutRenderer;
5use tuit::style::{Ansi4, Colour};
6use tuit::terminal::{ConstantSize, ViewSplit};
7use tuit::widgets::builtins::{Sweeper, Text};
8
9fn main() {
10    let mut terminal: ConstantSize<50, 20> = ConstantSize::new();
11
12    let yellow = Sweeper::of_colour(Colour::Ansi16(Ansi4::Yellow));
13    let magenta = Sweeper::of_colour(Colour::Ansi16(Ansi4::Magenta));
14    let blue = Sweeper::of_colour(Colour::Ansi16(Ansi4::Blue)).with_shrink(2);
15
16    let long_left_text = Text::new(
17        "Here's some really long text that will probably, or at least I hope, wrap around when drawn on the left side of the terminal! It even has some extra padding to add space! Wow, isn't that cool!?"
18    ).with_shrink(2);
19    let short_right_text = Text::new("The guy next to me is too loud...").with_shrink(2);
20
21    let mut split = ViewSplit::new(&mut terminal);
22
23    let mut right = split.split_right_mut();
24    yellow.drawn(&mut right).ok();
25    blue.drawn(&mut right).ok();
26    short_right_text.drawn(&mut right).ok();
27
28    let mut left = split.split_left_mut();
29    magenta.drawn(&mut left).ok();
30    blue.drawn(&mut left).ok();
31    long_left_text.drawn(&mut left).ok();
32
33    terminal
34        .display(StdoutRenderer::default())
35        .expect("Can't fail");
36}