termo 0.16.0

yet another terminal ui framework
Documentation
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(unused_must_use)]
#![allow(unused_mut)]
#![allow(unused_assignments)]

#[macro_use]
pub mod show;
pub mod ask;
pub mod colors;
pub mod divider;
pub mod progress;
pub mod prompt;

pub use colors::*;

// ╭─ {header} ──────────── __
// |       ____ ___  ____  / /_____
// |      / __ `__ \/ __ \/ __/ __ \
// |     / / / / / / /_/ / /_/ /_/ /
// |    /_/ /_/ /_/\____/\__/\____/
// |
// ╰─╮─[white] {subtitle} [/]─[yellow] {tail} ─"#;
//  ─╯

#[macro_use]
#[allow(unused_macros)]
#[macro_export]
pub use termo_gen::display;

pub mod tree {
    use crate::colors::*;
    use std::fmt::Debug;

    pub fn vec<T>(v: &Vec<T>)
    where
        T: Debug,
    {
        let mut i = 0;
        for item in v {
            println!(
                "{}╭── {}{}{}{}{} ──╮{}",
                GREEN, BOLD, YELLOW, i, RESET, GREEN, RESET
            );
            println!("{:?}", item);
            i += 1;
        }
    }
}

pub use cursor::*;
pub mod cursor {
    use crate::colors::*;
    use std::fmt::Debug;

    // Move up
    pub fn up(n: usize) {
        print!("{}[{}A", 27 as char, n);
    }

    // Move down
    pub fn down(n: usize) {
        print!("{}[{}B", 27 as char, n);
    }

    // Move right
    pub fn right(n: usize) {
        print!("{}[{}C", 27 as char, n);
    }

    // Move left
    pub fn left(n: usize) {
        print!("{}[{}D", 27 as char, n);
    }

    // Move to start of line
    pub fn start() {
        print!("{}[H", 27 as char); // Go to home position
    }

    // Move to end of line - This needs a different approach
    pub fn end() {
        print!("{}[F", 27 as char); // Go to home position
        print!("{}[K", 27 as char); // Clear line
    }

    // Move the cursor to the specified position relative to the current position
    // -1 is up, 1 is down and 0 is current position
    pub fn move_to(x: i32, y: i32) {
        let (cx, cy) = get_pos();
        if x < 0 {
            left(x.abs() as usize);
        } else if x > 0 {
            right(x as usize);
        }

        if y < 0 {
            up(y.abs() as usize);
        } else if y > 0 {
            down(y as usize);
        }
    }

    // Move the cursor to the specified position (coordinates)
    pub fn move_to_abs(x: u16, y: u16) {
        print!("{}[{};{}H", 27 as char, y + 1, x + 1);
    }

    // Place text at the specified position (coordinates)
    pub fn place(x: i32, y: i32, text: impl Into<String>) {
        let (cx, cy) = get_pos();
        move_to(x, y);
        print!("{}", text.into());
        move_to_abs(cx, cy);
    }

    pub fn get_pos() -> (u16, u16) {
        let pos = crossterm::cursor::position().unwrap();
        (pos.0, pos.1)
    }
}