]>
git.proxmox.com Git - cargo.git/blob - vendor/termion-1.5.1/examples/rainbow.rs
3 use termion
::event
::Key
;
4 use termion
::input
::TermRead
;
5 use termion
::raw
::IntoRawMode
;
6 use std
::io
::{Write, stdout, stdin}
;
8 fn rainbow
<W
: Write
>(stdout
: &mut W
, blue
: u8) {
11 termion
::cursor
::Goto(1, 1),
18 let green
= green
* 4;
21 termion
::color
::Bg(termion
::color
::Rgb(red
, green
, blue
)))
24 write
!(stdout
, "\n\r").unwrap();
27 writeln
!(stdout
, "{}b = {}", termion
::style
::Reset
, blue
).unwrap();
32 let mut stdout
= stdout().into_raw_mode().unwrap();
35 "{}{}{}Use the up/down arrow keys to change the blue in the rainbow.",
37 termion
::cursor
::Goto(1, 1),
38 termion
::cursor
::Hide
)
43 for c
in stdin
.keys() {
46 blue
= blue
.saturating_add(4);
47 rainbow(&mut stdout
, blue
);
50 blue
= blue
.saturating_sub(4);
51 rainbow(&mut stdout
, blue
);
53 Key
::Char('q'
) => break,
56 stdout
.flush().unwrap();
59 write
!(stdout
, "{}", termion
::cursor
::Show
).unwrap();