use crossterm::{
cursor::{MoveToColumn, MoveUp},
execute,
terminal::{Clear, ClearType, size},
};
use std::io::Result;
use std::io::{Write, stdout};
#[allow(dead_code)]
pub fn get_width() -> Option<u16> {
size().ok().map(|(w, _)| w)
}
pub fn move_cursor_up(n: u16) -> Result<()> {
execute!(stdout(), MoveUp(n))
}
pub fn clear_line() -> Result<()> {
execute!(stdout(), Clear(ClearType::CurrentLine))?;
execute!(stdout(), MoveToColumn(0))
}
pub fn write_all(buf: &[u8]) -> Result<()> {
stdout().write_all(buf)?;
stdout().flush()?;
execute!(stdout(), MoveToColumn(0))?;
Ok(())
}