pride/src/draw.rs

49 lines
913 B
Rust
Raw Normal View History

use std::io::{ self, Write };
2023-04-13 15:04:05 -04:00
use termion::{
terminal_size,
clear,
color::{ Fg, Rgb },
cursor,
input::TermRead,
raw::IntoRawMode
2023-04-13 15:04:05 -04:00
};
use crate::color::RESET;
2023-04-13 15:04:05 -04:00
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 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}",
2023-04-13 15:04:05 -04:00
color = colors[index]
).ok();
}
stdout.flush().ok();
for _ in stdin.keys() { break; }
write!(stdout, "{}{}", cursor::Show, clear::All).ok();
stdout.flush().ok();
}