pride/src/draw.rs

53 lines
923 B
Rust
Raw Normal View History

2023-04-13 15:04:05 -04:00
use std::{
io,
io::Write
};
use termion::{
terminal_size,
clear,
color::{ Fg, Rgb },
cursor,
input::TermRead,
raw::IntoRawMode,
style
};
use crate::flag::BLOCK;
pub fn draw(colors: &[Fg<Rgb>]) {
let mut stdout = io::stdout().into_raw_mode().unwrap();
let stdin = io::stdin();
let count = colors.len();
let (width, height) = terminal_size().unwrap();
let thresh = height as usize / count;
write!(stdout, "{}{}", cursor::Hide, clear::All).ok();
stdout.flush().ok();
let stripe = BLOCK.repeat(width as usize);
let reset = style::Reset;
let mut index = 0;
for n in 0..(height as usize) {
if n != 0 && n % thresh == 0 {
index += 1;
if index >= count { break; }
}
write!(
stdout,
"{color}{stripe}{reset}",
color = colors[index]
).ok();
}
stdout.flush().ok();
for _ in stdin.keys() { break; }
write!(stdout, "{}{}", cursor::Show, clear::All).ok();
stdout.flush().ok();
}