2023-06-19 19:21:05 -04:00
|
|
|
use std::io::{ self, Write };
|
2023-04-13 15:04:05 -04:00
|
|
|
|
|
|
|
use termion::{
|
|
|
|
terminal_size,
|
|
|
|
|
|
|
|
clear,
|
|
|
|
cursor,
|
|
|
|
input::TermRead,
|
2023-06-19 19:21:05 -04:00
|
|
|
raw::IntoRawMode
|
2023-04-13 15:04:05 -04:00
|
|
|
};
|
|
|
|
|
2023-06-19 20:08:05 -04:00
|
|
|
use crate::color::{ RESET, Colors };
|
2023-04-13 15:04:05 -04:00
|
|
|
use crate::flag::BLOCK;
|
|
|
|
|
2023-06-19 20:08:05 -04:00
|
|
|
pub fn full(colors: Colors) {
|
2023-04-13 15:04:05 -04:00
|
|
|
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,
|
2023-06-19 19:21:05 -04:00
|
|
|
"{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();
|
|
|
|
}
|
|
|
|
|
2023-06-19 20:08:05 -04:00
|
|
|
pub fn small(colors: Colors) {
|
|
|
|
let mut stdout = io::stdout();
|
|
|
|
|
|
|
|
let count = colors.len();
|
|
|
|
let width = count * 3;
|
|
|
|
|
|
|
|
let stripe = BLOCK.repeat(width);
|
|
|
|
|
|
|
|
for color in colors {
|
|
|
|
println!("{color}{stripe}");
|
|
|
|
}
|
|
|
|
print!("{RESET}");
|
|
|
|
stdout.flush().ok();
|
|
|
|
}
|
2023-04-13 15:04:05 -04:00
|
|
|
|