basic_gradient/
basic_gradient.rs1use colorgrad::{Color, GradientBuilder};
2use crossterm::event::{self, *};
3use std::io;
4use tui_gradient_block::{
5 types::G,
6 handle_args, structs::border_symbols::SegmentSet,
7};
8fn main() -> io::Result<()> {
9 let arg = handle_args!();
10 let style = SegmentSet::from_ratatui_set(arg);
11 let mut terminal = ratatui::init();
12 let app_result = run(&mut terminal, style);
13 ratatui::restore();
14 app_result
15}
16fn solid(col: (u8, u8, u8)) -> G {
17 Box::new(
18 GradientBuilder::new()
19 .colors(&[Color::from_rgba8(col.0, col.1, col.2, 1)])
20 .build::<colorgrad::LinearGradient>()
21 .unwrap(),
22 )
23}
24fn run(
25 terminal: &mut ratatui::DefaultTerminal,
26 set: SegmentSet,
27) -> io::Result<()> {
28 use tui_gradient_block::gradient_block::GradientBlock;
29 let block = GradientBlock::new()
30 .with_set(set)
31 .left_gradient(solid((48, 174, 209)))
32 .bottom_gradient(solid((48, 174, 209)))
33 .top_gradient(Box::new(
34 GradientBuilder::new()
35 .colors(&[
36 Color::from_rgba8(48, 174, 209, 1),
37 Color::from_rgba8(225, 22, 247, 1),
38 ])
39 .build::<colorgrad::LinearGradient>()
40 .unwrap(),
41 ))
42 .right_gradient(Box::new(
43 GradientBuilder::new()
44 .colors(&[
45 Color::from_rgba8(225, 22, 247, 1),
46 Color::from_rgba8(48, 174, 209, 1),
47 ])
48 .build::<colorgrad::LinearGradient>()
49 .unwrap(),
50 ));
51
52 loop {
53 terminal.draw(|f| f.render_widget(&block, f.area()))?;
54 let event = event::read()?;
55
56 if let Event::Key(key_event) = event {
57 if key_event.kind == KeyEventKind::Press {
58 if let KeyCode::Char('q') = key_event.code {
59 break Ok(());
60 }
61 }
62 }
63 }
64}