fixed flags not matching and removed hard terminal requirement

This commit is contained in:
Valerie Wolfe 2024-07-05 10:31:42 -04:00
parent fc326344f2
commit 7cecac36ee
2 changed files with 24 additions and 15 deletions

View file

@ -26,33 +26,47 @@ pub static BLOCK: &str = "█";
pub static UHALF: &str = ""; pub static UHALF: &str = "";
/// prints a provided vec of lines to stdout /// prints a provided vec of lines to stdout
pub fn draw_lines(lines: Vec<String>, state: &State) { pub fn draw_full(lines: Vec<String>) {
let mut stdout = io::stdout().into_raw_mode().unwrap(); let mut stdout = io::stdout().into_raw_mode().unwrap();
// get in position for draw
let count = lines.len() as u16; let count = lines.len() as u16;
for _ in 0..count { write!(stdout, "\n").ok(); } for _ in 0..count { write!(stdout, "\n").ok(); }
write!(stdout, "{}", cursor::Up(count)).ok(); write!(stdout, "{}", cursor::Up(count)).ok();
let hold = state.size == Size::Full; // clear screen and hide cursor
if hold { write!(stdout, "{}{}", cursor::Hide, clear::All).ok(); } write!(stdout, "{}{}", cursor::Hide, clear::All).ok();
// write lines
let down = cursor::Down(1); let down = cursor::Down(1);
for line in lines { for line in lines {
let left = cursor::Left(line.len() as u16); let left = cursor::Left(line.len() as u16);
write!(stdout, "{line}{left}{down}").ok(); write!(stdout, "{line}{left}{down}").ok();
} }
// clear formatting and flush buffer
write!(stdout, "{RESET}{RESET_BG}").ok(); write!(stdout, "{RESET}{RESET_BG}").ok();
stdout.flush().ok(); stdout.flush().ok();
if hold {
// hold for input
let stdin = io::stdin(); let stdin = io::stdin();
for _ in stdin.keys() { break; } for _ in stdin.keys() { break; }
write!(stdout, "{}", clear::All).ok();
} // clear and show cursor
write!(stdout, "{}", cursor::Show).ok(); write!(stdout, "{}{}", clear::All, cursor::Show).ok();
stdout.flush().ok(); stdout.flush().ok();
} }
pub fn draw_lines(lines: Vec<String>, state: &State) {
match state.size {
Size::Full => draw_full(lines),
_ => {
for line in lines { println!("{line}"); }
println!("{RESET}{RESET_BG}");
}
}
}
/// generates lines for foreground colors provided as a vec of strings for the draw_lines method /// generates lines for foreground colors provided as a vec of strings for the draw_lines method
pub fn fg_stripes(colors: Vec<Fg<Rgb>>, width: u16, height: u16) -> Vec<String> { pub fn fg_stripes(colors: Vec<Fg<Rgb>>, width: u16, height: u16) -> Vec<String> {
let width = width as usize; let width = width as usize;

View file

@ -43,8 +43,6 @@ impl Size {
pub struct State { pub struct State {
pub size: Size, pub size: Size,
pub is_terminal: bool, pub is_terminal: bool,
pub flag: Option<String>,
pub variant: Option<String>
} }
impl State { impl State {
@ -58,10 +56,7 @@ impl State {
_ => { error::size_missing(); panic!() } _ => { error::size_missing(); panic!() }
}; };
let flag = args.subcommand().unwrap(); State { size, is_terminal }
let variant = args.subcommand().unwrap();
State { size, is_terminal, flag, variant }
} }
} }