2024-01-24 19:50:18 +00:00
|
|
|
//! # [Ratatui] Logo example
|
|
|
|
//!
|
|
|
|
//! The latest version of this example is available in the [examples] folder in the repository.
|
|
|
|
//!
|
|
|
|
//! Please note that the examples are designed to be run against the `main` branch of the Github
|
|
|
|
//! repository. This means that you may not be able to compile with the latest release version on
|
|
|
|
//! crates.io, or the one that you have installed locally.
|
|
|
|
//!
|
|
|
|
//! See the [examples readme] for more information on finding examples that match the version of the
|
|
|
|
//! library you are using.
|
|
|
|
//!
|
|
|
|
//! [Ratatui]: https://github.com/ratatui-org/ratatui
|
|
|
|
//! [examples]: https://github.com/ratatui-org/ratatui/blob/main/examples
|
|
|
|
//! [examples readme]: https://github.com/ratatui-org/ratatui/blob/main/examples/README.md
|
|
|
|
|
2023-12-14 02:25:21 +00:00
|
|
|
use std::{
|
|
|
|
io::{self, stdout},
|
|
|
|
thread::sleep,
|
|
|
|
time::Duration,
|
|
|
|
};
|
|
|
|
|
|
|
|
use crossterm::terminal::{disable_raw_mode, enable_raw_mode};
|
|
|
|
use indoc::indoc;
|
|
|
|
use itertools::izip;
|
2024-03-02 09:06:53 +00:00
|
|
|
use ratatui::{prelude::*, widgets::Paragraph};
|
2023-12-14 02:25:21 +00:00
|
|
|
|
|
|
|
/// A fun example of using half block characters to draw a logo
|
2024-03-02 09:06:53 +00:00
|
|
|
#[allow(clippy::many_single_char_names)]
|
|
|
|
fn logo() -> String {
|
2023-12-14 02:25:21 +00:00
|
|
|
let r = indoc! {"
|
|
|
|
▄▄▄
|
|
|
|
█▄▄▀
|
|
|
|
█ █
|
2024-03-02 09:06:53 +00:00
|
|
|
"};
|
2023-12-14 02:25:21 +00:00
|
|
|
let a = indoc! {"
|
|
|
|
▄▄
|
|
|
|
█▄▄█
|
|
|
|
█ █
|
2024-03-02 09:06:53 +00:00
|
|
|
"};
|
2023-12-14 02:25:21 +00:00
|
|
|
let t = indoc! {"
|
|
|
|
▄▄▄
|
|
|
|
█
|
|
|
|
█
|
2024-03-02 09:06:53 +00:00
|
|
|
"};
|
2023-12-14 02:25:21 +00:00
|
|
|
let u = indoc! {"
|
|
|
|
▄ ▄
|
|
|
|
█ █
|
|
|
|
▀▄▄▀
|
2024-03-02 09:06:53 +00:00
|
|
|
"};
|
2023-12-14 02:25:21 +00:00
|
|
|
let i = indoc! {"
|
|
|
|
▄
|
|
|
|
█
|
|
|
|
█
|
2024-03-02 09:06:53 +00:00
|
|
|
"};
|
|
|
|
izip!(r.lines(), a.lines(), t.lines(), u.lines(), i.lines())
|
|
|
|
.map(|(r, a, t, u, i)| format!("{r:5}{a:5}{t:4}{a:5}{t:4}{u:5}{i:5}"))
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.join("\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() -> io::Result<()> {
|
2023-12-14 02:25:21 +00:00
|
|
|
let mut terminal = init()?;
|
|
|
|
terminal.draw(|frame| {
|
2024-03-02 09:06:53 +00:00
|
|
|
frame.render_widget(Paragraph::new(logo()), frame.size());
|
2023-12-14 02:25:21 +00:00
|
|
|
})?;
|
|
|
|
sleep(Duration::from_secs(5));
|
|
|
|
restore()?;
|
|
|
|
println!();
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2024-03-02 09:06:53 +00:00
|
|
|
fn init() -> io::Result<Terminal<impl Backend>> {
|
2023-12-14 02:25:21 +00:00
|
|
|
enable_raw_mode()?;
|
|
|
|
let options = TerminalOptions {
|
|
|
|
viewport: Viewport::Inline(3),
|
|
|
|
};
|
|
|
|
Terminal::with_options(CrosstermBackend::new(stdout()), options)
|
|
|
|
}
|
|
|
|
|
2024-03-02 09:06:53 +00:00
|
|
|
fn restore() -> io::Result<()> {
|
2023-12-14 02:25:21 +00:00
|
|
|
disable_raw_mode()?;
|
|
|
|
Ok(())
|
|
|
|
}
|