fixed flags not matching and removed hard terminal requirement
This commit is contained in:
parent
fc326344f2
commit
7cecac36ee
2 changed files with 24 additions and 15 deletions
32
src/draw.rs
32
src/draw.rs
|
@ -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 {
|
|
||||||
let stdin = io::stdin();
|
// hold for input
|
||||||
for _ in stdin.keys() { break; }
|
let stdin = io::stdin();
|
||||||
write!(stdout, "{}", clear::All).ok();
|
for _ in stdin.keys() { break; }
|
||||||
}
|
|
||||||
write!(stdout, "{}", cursor::Show).ok();
|
// clear and show cursor
|
||||||
|
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;
|
||||||
|
|
|
@ -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 }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue