diff --git a/src/draw.rs b/src/draw.rs index bc4df9c..49cd3b6 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -26,33 +26,47 @@ pub static BLOCK: &str = "█"; pub static UHALF: &str = "▀"; /// prints a provided vec of lines to stdout -pub fn draw_lines(lines: Vec, state: &State) { +pub fn draw_full(lines: Vec) { let mut stdout = io::stdout().into_raw_mode().unwrap(); + // get in position for draw let count = lines.len() as u16; for _ in 0..count { write!(stdout, "\n").ok(); } write!(stdout, "{}", cursor::Up(count)).ok(); - let hold = state.size == Size::Full; - if hold { write!(stdout, "{}{}", cursor::Hide, clear::All).ok(); } + // clear screen and hide cursor + write!(stdout, "{}{}", cursor::Hide, clear::All).ok(); + // write lines let down = cursor::Down(1); for line in lines { let left = cursor::Left(line.len() as u16); write!(stdout, "{line}{left}{down}").ok(); } + // clear formatting and flush buffer write!(stdout, "{RESET}{RESET_BG}").ok(); stdout.flush().ok(); - if hold { - let stdin = io::stdin(); - for _ in stdin.keys() { break; } - write!(stdout, "{}", clear::All).ok(); - } - write!(stdout, "{}", cursor::Show).ok(); + + // hold for input + let stdin = io::stdin(); + for _ in stdin.keys() { break; } + + // clear and show cursor + write!(stdout, "{}{}", clear::All, cursor::Show).ok(); stdout.flush().ok(); } +pub fn draw_lines(lines: Vec, 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 pub fn fg_stripes(colors: Vec>, width: u16, height: u16) -> Vec { let width = width as usize; diff --git a/src/state.rs b/src/state.rs index e86cec5..0950b4c 100644 --- a/src/state.rs +++ b/src/state.rs @@ -43,8 +43,6 @@ impl Size { pub struct State { pub size: Size, pub is_terminal: bool, - pub flag: Option, - pub variant: Option } impl State { @@ -58,10 +56,7 @@ impl State { _ => { error::size_missing(); panic!() } }; - let flag = args.subcommand().unwrap(); - let variant = args.subcommand().unwrap(); - - State { size, is_terminal, flag, variant } + State { size, is_terminal } } }