# my_tui_lib.sh

# Function to clear the screen and home cursor
clear_screen() {
    echo -e "\033[2J\033[H"
}

# Function to set cursor position (1-based row, col)
set_cursor() {
    local row=$1
    local col=$2
    echo -e "\033[${row};${col}H"
}

# Function to set foreground color (e.g., "red", "green")
set_color() {
    local color=$1
    case "$color" in
        "red") echo -e "\033[31m";;
        "green") echo -e "\033[32m";;
        "yellow") echo -e "\033[33m";;
        "blue") echo -e "\033[34m";;
        "reset") echo -e "\033[0m";;
        *) echo -e "\033[0m";; # Default to reset
    esac
}

# Function to get terminal width
get_term_width() {
    tput cols
}

# Function to get terminal height
get_term_height() {
    tput lines
}

# Function to draw a box
draw_box() {
    local y=$1
    local x=$2
    local width=$3
    local height=$4

    # Top line
    set_cursor "$y" "$x"
    echo -n "┌$(printf '─%.0s' $(seq 1 $((width-2))))┐"

    # Sides
    for ((i=1; i<height-1; i++)); do
        set_cursor $((y+i)) "$x"
        echo -n "│$(printf ' %.0s' $(seq 1 $((width-2))))│"
    done

    # Bottom line
    set_cursor $((y+height-1)) "$x"
    echo -n "└$(printf '─%.0s' $(seq 1 $((width-2))))┘"
}
