use console::Term;
use std::io::Result;
use std::io::Write;
use std::sync::LazyLock;
use std::sync::Mutex;
static TERM: LazyLock<Mutex<Term>> = LazyLock::new(|| Mutex::new(Term::stdout()));
pub fn get_width() -> Option<u16> {
TERM.lock()
.expect("unable to lock TERM")
.size_checked()
.map(|(_, width)| width)
}
pub fn move_cursor_up(n: usize) -> Result<()> {
TERM.lock().expect("unable to lock TERM").move_cursor_up(n)
}
pub fn clear_line() -> Result<()> {
TERM.lock().expect("unable to lock TERM").clear_line()
}
pub fn write_all(buf: &[u8]) -> Result<()> {
TERM.lock().expect("unable to lock TERM").write_all(buf)
}