#!/usr/bin/env bash
logo() { echo -e "\x20\x20\e[48;5;34m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\n\e[48;5;34m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\n\e[48;5;34m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\n\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;10m\x20\x20\e[m\e[48;5;10m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;10m\x20\x20\e[m\e[48;5;10m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\n\e[48;5;34m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;10m\x20\x20\e[m\e[48;5;10m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;10m\x20\x20\e[m\e[48;5;10m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\n\e[48;5;34m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\n\e[48;5;34m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\x20\x20\n\e[48;5;34m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;10m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;10m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\x20\x20\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\x20\x20\n\e[48;5;34m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;10m\x20\x20\e[m\e[48;5;10m\x20\x20\e[m\e[48;5;10m\x20\x20\e[m\e[48;5;10m\x20\x20\e[m\e[48;5;10m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;12m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\e[48;5;16m\x20\x20\e[m\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\x20\x20\x20\x20\e[48;5;16m\x20\x20\e[m\x20\x20\x20\x20\x20\x20\n\x20\x20\e[48;5;34m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\e[48;5;34m\x20\x20\e[m\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"; }


# Debian XFCE init and setup
logo
# Check for sudo access
if [[ $(id -u) = 0 ]]; then
    echo "Please run as normal user"
    exit
fi

echo "Please put in password for sudo"
# Must be running as sudo
if [[ $(sudo id -u) != 0 ]]; then
    echo "Sudo authentication failed. Please try again"
    exit
fi

# Get Distro and version

if [ -f /etc/os-release ]; then
    # freedesktop.org and systemd
    . /etc/os-release
    OS=$NAME
    VER=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
    # linuxbase.org
    OS=$(lsb_release -si)
    VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
    # For some versions of Debian/Ubuntu without lsb_release command
    . /etc/lsb-release
    OS=$DISTRIB_ID
    VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
    # Older Debian/Ubuntu/etc.
    OS=Debian
    VER=$(cat /etc/debian_version)
elif [ -f /etc/SuSe-release ]; then
    # Older SuSE/etc.
    ...
elif [ -f /etc/redhat-release ]; then
    # Older Red Hat, CentOS, etc.
    ...
else
    # Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
    OS=$(uname -s)
    VER=$(uname -r)
fi

user_home=$(echo $HOME)
app_version=24110122
init_version=0
tcmeta_key=0
base_repo=https://git.tcmeta.net/kurtis

DEBIAN="Debian GNU/Linux"

start() {
    if [ -f $user_home/.config/vargtools/tcmeta ]; then
        tcmeta_key=$(<$user_home/.config/vargtools/tcmeta)
    else 
        mkdir -p $user_home/.config/vargtools
    fi
    if [ -f /etc/vargtools/init ]; then
        init_version=$(</etc/vargtools/init)
    else
        sudo mkdir -p /etc/vargtools
        sudo echo "0" > /etc/vargtools/init
    fi
    if [ "$init_version" -lt "$app_version" ]; then
    	menuItems=(
    	    "1. Perform Initialisation"
            "Q. Exit                  "
        )
        menuActions=(
            doInit
            quitApp
        )
        menuTitle=" VargTools has not been initalised yet. Proceed?"
        menuWidth=60
        menuLeft=20
        menuHighlight=$DRAW_COL_GREEN
	menuInit
	menuLoop
    else
	vMenuMain
    fi
}

pause() {
    read -n 1 -s -r -p "Press any key to continue"
}

debug() {
    if [ "$1" -eq "DEBUG" ]; then
        read -n 1 -s -r -p "Press any key to continue"
    fi
}

vMenuMain() {
    menuItems=(
        "1. Software"
        "2. System  "
        "3. Settings"
        "Q. Exit    "
    )
    menuActions=(
        vMenuSoftware
        vMenuSystem
        vMenuSettings
        quitApp
    )
    menuTitle=" VargTools"
    menuWidth=60
    menuLeft=20
    menuHighlight=$DRAW_COL_GREEN
    menuInit
    menuLoop
}

vMenuSettings() {
    menuNumberIndex=1
    menuItems=("$menuNumberIndex. Update vargtools")
    menuActions=(updateVargtools)
    # Check if git key has been given
    if ! [ -f $user_home/.config/vargtools/tcmeta ]; then
        menuNumberIndex=$((menuNumberIndex+1))
        menuItems+=("$menuNumberIndex. Set TCMeta Key")
        menuActions+=(setTcmetaKey)
    fi
    menuItems+=("B. Back")
    menuActions+=(vMenuMain)

    menuTitle=" VargTools"
    menuWidth=60
    menuLeft=20
    menuHighlight=$DRAW_COL_GREEN
    menuInit
    menuLoop
}

vMenuSystem() {
    menuNumberIndex=0
    menuItems=()
    menuActions=()
    if [ ! -d "$user_home/.themes/Chicago95" ]; then
        menuNumberIndex=$((menuNumberIndex+1))
        menuItems+=("$menuNumberIndex. Setup Chicago95                 ")
        menuActions+=(installChicago95)
    fi
    if [ -x "$(command -v chromium)" ]; then
        menuNumberIndex=$((menuNumberIndex+1))
        menuItems+=("$menuNumberIndex. Update / Install Chromium Policy")
        menuActions+=(configChromium)
    fi
    if [ -x "$(command -v brave-browser)" ]; then
        menuNumberIndex=$((menuNumberIndex+1))
        menuItems+=("$menuNumberIndex. Update / Install Brave Policy   ")
        menuActions+=(configBrave)
    fi
    if [ -x "$(command -v zen)" ]; then
        menuNumberIndex=$((menuNumberIndex+1))
        menuItems+=("$menuNumberIndex. Update / Install Zen Policy   ")
        menuActions+=(configZen)
    fi
    if [ ! -d "$user_home/.config/vargtools/tcmeta" ]; then
        if [ ! -d "$user_home/.dotfiles" ]; then
            menuNumberIndex=$((menuNumberIndex+1))
            menuItems+=("$menuNumberIndex. Setup dotfiles                  ")
            menuActions+=(setupDotFiles)
        fi
    fi
    menuItems+=("B. Back                ")
    menuActions+=(vMenuMain)
    menuTitle=" VargTools"
    menuWidth=60
    menuLeft=20
    menuHighlight=$DRAW_COL_GREEN
    menuInit
    menuLoop
}

vMenuSoftware() {
    menuNumberIndex=1
    menuItems=("$menuNumberIndex. Install All Software")
    menuActions=(installAll)
    flatpakInstalled=0
    flatpak info "com.valvesoftware.SteamLink" >/dev/null 2>&1 && flatpakInstalled=1
    if [ "$flatpakInstalled" = "0" ]; then
        menuNumberIndex=$((menuNumberIndex+1))
        menuItems+=("$menuNumberIndex. SteamLink")
        menuActions+=(installSteamLink)
    fi
    if ! [ -x "$(command -v chromium)" ]; then
        menuNumberIndex=$((menuNumberIndex+1))
        menuItems+=("$menuNumberIndex. Chromium")
        menuActions+=(setupChromium)
    fi
    if ! [ -x "$(command -v brave-browser)" ]; then
        menuNumberIndex=$((menuNumberIndex+1))
        menuItems+=("$menuNumberIndex. Brave")
        menuActions+=(setupBrave)
    fi
    if ! [ -x "$(command -v zen)" ]; then
        menuNumberIndex=$((menuNumberIndex+1))
        menuItems+=("$menuNumberIndex. Zen")
        menuActions+=(setupZen)
    fi
    if ! [ -x "$(command -v discord)" ]; then
        menuNumberIndex=$((menuNumberIndex+1))
        menuItems+=("$menuNumberIndex. Discord")
        menuActions+=(installDiscord)
    else
        menuNumberIndex=$((menuNumberIndex+1))
        menuItems+=("$menuNumberIndex. Update Discord")
        menuActions+=(installDiscord)
    fi
        
    if ! [ -x "$(command -v subl)" ]; then
        menuNumberIndex=$((menuNumberIndex+1))
        menuItems+=("$menuNumberIndex. Sublime Text Editor & Merge")
        menuActions+=(installSublime)
    fi
    if ! [ -x "$(command -v blueman-manager)" ]; then
        menuNumberIndex=$((menuNumberIndex+1))
        menuItems+=("$menuNumberIndex. Bluetooth")
        menuActions+=(installBluetooth)
    fi
    if ! [ -x "$(command -v appimagelauncherd)" ]; then
        menuNumberIndex=$((menuNumberIndex+1))
        menuItems+=("$menuNumberIndex. AppImageLauncher")
        menuActions+=(installAppimagelauncher)
    fi
    
    menuItems+=("B. Back                ")
    menuActions+=(vMenuMain)
    menuTitle="Vargtools - Software"
    menuWidth=60
    menuLeft=20
    menuHighlight=$DRAW_COL_GREEN
    menuInit
    menuLoop
}

doInit() {
    logo
    if [ "$init_version" -lt 24092720 ]; then
        echo Removing cdrom from apt
        sudo sed -i "/^deb cdrom:/s/^/#/" /etc/apt/sources.list
        sudo apt update
        echo Installing base software
        sudo apt install -y nala
        sudo nala install -y git python3 python3-pip pipx stow btop duf
        echo installing console python apps
        pipx ensurepath
        pipx install thefuck
        pipx install sshch
    fi
    echo "$app_version" | sudo tee /etc/vargtools/init > /dev/null
    echo Should be all upto date now .. press any key to continue
    read -n 1
    vMenuMain
}

updateVargtools() {
    logo
    echo [vargtools] Updating
    sudo wget "$base_repo/vargtools/raw/branch/main/vargtools" -O /usr/local/bin/vargtools
    sudo chmod +x /usr/local/bin/vargtools
    echo [vargtools] Done, restarting
    exec /usr/local/bin/vargtools
}

setTcmetaKey() {
    logo
    echo [TCMeta] please enter the git key
    read -r key
    echo $key | tee $user_home/.config/vargtools/tcmeta > /dev/null
    tcmeta_key=$(<$user_home/.config/vargtools/tcmeta)
    echo [TCMeta] Key Applied
    return 1
}

setupDotFiles() {
    git clone "https://$tcmeta_key@git.tcmeta.net/kurtis/dotfiles.git" $user_home/.dotfiles
    echo "alias dotfiles-update='$user_home/.dotfiles/update-repo'" | tee -a $user_home/.bash_aliases > /dev/null
    echo "alias dotfiles-push='$user_home/.dotfiles/push-repo'" | tee -a $user_home/.bash_aliases > /dev/null
    $user_home/.dotfiles/push-repo
    return 1
}

installChicago95() {
    logo
    echo [Chicago95] Installing prereqs
    wget "https://github.com/MerkeX/Lightdm-webkit2-greeter/releases/download/v2.2.5-1/lightdm-webkit2-greeter_2.2.5-1_amd64.deb" -O /tmp/lightdm-webkit2-greeter.deb
    sudo nala install -y /tmp/lightdm-webkit2-greeter.deb
    rm /tmp/lightdm-webkit2-greeter.deb
    sudo nala install -y xfce4-panel-profiles gnome-session-canberra sox libcanberra-gtk3-module libcanberra-gtk-module dbus-x11 gvfs-backends mugshot
    echo [Chicago95] Downloading theme
    git clone https://github.com/grassmunk/Chicago95.git /tmp/Chicago95
    echo [Chicago95] Installing system wide
    sudo cp -r /tmp/Chicago95/Theme/Chicago95 /usr/share/themes/
    sudo cp -r /tmp/Chicago95/Icons/* /usr/share/icons/
    sudo cp -v /tmp/Chicago95/Fonts/vga_font/LessPerfectDOSVGA.ttf /usr/share/fonts
    sudo cp -r /tmp/Chicago95/Fonts/bitmap/cronyx-cyrillic /usr/share/fonts
    echo [Chicago95] Installing fonts
    sudo mv /etc/fonts/conf.d/70-no-bitmaps.conf /etc/fonts/conf.d/70-no-bitmaps.conf.bak
    sudo fc-cache -fv
    echo [Chicago95] Installing Login Screen
    sudo sed -i 's/\#greeter-session/greeter-session/g' /etc/lightdm/lightdm.conf
    sudo sed -i 's/\#user-session/user-session/g' /etc/lightdm/lightdm.conf
    sudo sed -i -e "s/\(greeter-session *= *\).*/\1lightdm-webkit2-greeter/" /etc/lightdm/lightdm.conf
    sudo sed -i -e "s/\(user-session *= *\).*/\1xfce/" /etc/lightdm/lightdm.conf
    sudo cp -r /tmp/Chicago95/Lightdm/Chicago95 /usr/share/lightdm-webkit/themes/
    echo [Chicago95] Generating Config
    echo "#" | sudo tee /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "# [greeter]" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "# debug_mode          = Greeter theme debug mode." | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "# detect_theme_errors = Provide an option to load a fallback theme when theme errors are detected." | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "# screensaver_timeout = Blank the screen after this many seconds of inactivity." | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "# secure_mode         = Don't allow themes to make remote http requests." | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "# time_format         = A moment.js format string so the greeter can generate localized time for display." | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "# time_language       = Language to use when displaying the time or "auto" to use the system's language." | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "# webkit_theme        = Webkit theme to use." | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "#" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "# NOTE: See moment.js documentation for format string options: http://momentjs.com/docs/#/displaying/format/" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "#" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "[greeter]" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "debug_mode          = false" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "detect_theme_errors = true" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "screensaver_timeout = 300" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "secure_mode         = true" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "time_format         = LT" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "time_language       = auto" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "webkit_theme        = Chicago95" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "#" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "# [branding]" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "# background_images = Path to directory that contains background images for use by themes." | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "# logo              = Path to logo image for use by greeter themes." | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "# user_image        = Default user image/avatar. This is used by themes for users that have no .face image." | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "#" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "# NOTE: Paths must be accessible to the lightdm system user account (so they cannot be anywhere in /home)" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "#" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "[branding]" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "background_images = /usr/share/backgrounds" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "logo              = /usr/share/lightdm-webkit/themes/antergos/img/antergos.png" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "user_image        = /usr/share/lightdm-webkit/themes/antergos/img/antergos-logo-user.png" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo "" | sudo tee -a /etc/lightdm/lightdm-webkit2-greeter.conf > /dev/null
    echo [Chicago95] Installing boot screen
    sudo cp -r /tmp/Chicago95/Plymouth/Chicago95 /usr/share/plymouth/themes/
    sudo cp -r /tmp/Chicago95/Plymouth/RetroTux /usr/share/plymouth/themes/
    sudo plymouth-set-default-theme -R Chicago95
    echo [Chicago95] Modifying grub
    sudo sed -i -e "s/\(GRUB_TIMEOUT *= *\).*/\10/" /etc/default/grub
    sudo sed -i 's/\quiet/quiet splash/g' /etc/default/grub
    sudo sed -i 's/\#GRUB_TERMINAL/GRUB_TERMINAL/g' /etc/default/grub
    echo [Chicago95] Updating Grub
    sudo update-grub2
    echo [Chicago95] Running Client installer
    python3 /tmp/Chicago95/installer.py
    echo [Chicago95] Installing startup sound / wallpapers
    cp "/tmp/Chicago95/Extras/Microsoft Windows 95 Startup Sound.ogg" "$user_home/.themes/Chicago95/misc/Microsoft Windows 95 Startup Sound.ogg"
    mkdir -p $user_home/.config/autostart
    echo "[Desktop Entry]" | tee "$user_home/.config/autostart/Windows Logon Sound.desktop" > /dev/null
    echo "Encoding=UTF-8" | tee -a "$user_home/.config/autostart/Windows Logon Sound.desktop" > /dev/null
    echo "Version=0.9.4" | tee -a "$user_home/.config/autostart/Windows Logon Sound.desktop" > /dev/null
    echo "Type=Application" | tee -a "$user_home/.config/autostart/Windows Logon Sound.desktop" > /dev/null
    echo "Name=Windows Logon Sound" | tee -a "$user_home/.config/autostart/Windows Logon Sound.desktop" > /dev/null
    echo "Comment=Plays the windows 95 logon music" | tee -a "$user_home/.config/autostart/Windows Logon Sound.desktop" > /dev/null
    echo "Exec=play \"$user_home/.themes/Chicago95/misc/Microsoft Windows 95 Startup Sound.ogg\"" | tee -a "$user_home/.config/autostart/Windows Logon Sound.desktop" > /dev/null
    echo "OnlyShowIn=XFCE;" | tee -a "$user_home/.config/autostart/Windows Logon Sound.desktop" > /dev/null
    echo "RunHook=0" | tee -a "$user_home/.config/autostart/Windows Logon Sound.desktop" > /dev/null
    echo "StartupNotify=false" | tee -a "$user_home/.config/autostart/Windows Logon Sound.desktop" > /dev/null
    echo "Terminal=false" | tee -a "$user_home/.config/autostart/Windows Logon Sound.desktop" > /dev/null
    echo "Hidden=false" | tee -a "$user_home/.config/autostart/Windows Logon Sound.desktop" > /dev/null
    git clone https://git.tcmeta.net/kurtis/chicago95-wallpapers.git $user_home/.themes/Chicago95/wallpapers
    echo [Chicago95] Fixing Lock screen
    echo "[User Permissions]" | sudo tee /etc/polkit-1/localauthority/any/10-suspend-user.pkla > /dev/null
    echo "Identity=unix-group:suspenders" | sudo tee -a /etc/polkit-1/localauthority/any/10-suspend-user.pkla > /dev/null
    echo "ResultAny=no" | sudo tee -a /etc/polkit-1/localauthority/any/10-suspend-user.pkla > /dev/null
    echo "ResultInactive=no" | sudo tee -a /etc/polkit-1/localauthority/any/10-suspend-user.pkla > /dev/null
    echo "ResultActive=yes" | sudo tee -a /etc/polkit-1/localauthority/any/10-suspend-user.pkla > /dev/null
    echo [Chigaco95] Setting custom Settings
    xfconf-query -n -t 'string' -c xfce4-keyboard-shortcuts -p "/commands/custom/Super_L" -s xfce4-popup-whiskermenu
    xfconf-query -r -c xfce4-keyboard-shortcuts -p "/commands/custom/<Primary>Escape"
    xfconf-query -c xfwm4 -p "/general/tile_on_move" -s true
    xfconf-query xfconf-query -c xfce4-desktop -p "/backdrop/screen0/monitoreDP-1/workspace0/last-image" -s "$user_home/.themes/Chicago95/wallpapers/clouds.jpg"
    echo [Chicago95] Disabling pc speaker
    echo "blacklist pcspkr" | sudo tee -a /etc/modprobe.d/blacklist.conf > /dev/null
    echo [Chicago95] Okay done
    return 1
}

installDiscord() {
    echo [Discord] Downloading latest version
    wget "https://discord.com/api/download?platform=linux&format=deb" -O /tmp/discord.deb
    echo [Discord] Installing
    sudo nala install -y /tmp/discord.deb
    echo [Discord] Cleaning up
    rm /tmp/discord.deb
    return 1
}

setupChromium() {
    logo
    installChromium
    menuItems=(
    "1. All"
    "2. Webapps Only"
    "3. Personal Config Only"
    "Q. No "
    )
    menuActions=(
        configChromiumAll
        configChromiumWebOnly
        configChromiumExtOnly
        vMenuSoftware
    )
    menuTitle=" Install Chromium Browser Policy?"
    menuWidth=60
    menuLeft=20
    menuHighlight=$DRAW_COL_GREEN
    menuInit
    menuLoop
}

installChromium() {
    echo [Chromium] Installing Chromium
    sudo nala install -y chromium
    return 1
}

configChromiumAll() {
    configChromiumWeb
    configChromiumAll
    vMenuSoftware
}

configChromiumWebOnly() {
    configChromiumWeb
    vMenuSoftware
}

configChromiumExtOnly() {
    configChromiumExt
    vMenuSoftware
}

configChromiumWeb() {
    echo [Chromium] Deploying policy
    sudo mkdir -p /etc/chromium/policies/managed
    sudo chmod -w /etc/chromium/policies/managed
    sudo wget "$base_repo/chromium-policy/raw/branch/main/varg-policy.json" -O /etc/chromium/policies/managed/varg-policy.json
    echo [Chromium] Policy deployed
}

configChromiumExt() {
    echo [Chromium] Deploying policy
    sudo mkdir -p /etc/chromium/policies/managed
    sudo chmod -w /etc/chromium/policies/managed
    sudo wget "$base_repo/chromium-policy/raw/branch/main/varg-policy.json" -O /etc/chromium/policies/managed/varg-policy.json
    echo [Chromium] Policy deployed
}

setupBrave() {
    logo
    installBrave
    menuItems=(
    "1. All"
    "2. Webapps Only"
    "3. Personal Config Only"
    "Q. No"
    )
    menuActions=(
        configBraveAll
        configBraveWebOnly
        configBraveExtOnly
        vMenuSoftware
    )
    menuTitle=" Install Chromium Browser Policy?"
    menuWidth=60
    menuLeft=20
    menuHighlight=$DRAW_COL_GREEN
    menuInit
    menuLoop
}

installBrave() {
    echo [Brave] Adding Repo
    sudo wget "https://brave-browser-apt-release.s3.brave.com/brave-browser-archive-keyring.gpg" -O /usr/share/keyrings/brave-browser-archive-keyring.gpg
    echo "deb [signed-by=/usr/share/keyrings/brave-browser-archive-keyring.gpg] https://brave-browser-apt-release.s3.brave.com/ stable main"|sudo tee /etc/apt/sources.list.d/brave-browser-release.list
    echo [Brave] Installing Brave Browser
    sudo nala update
    sudo nala install -y brave-browser
}

configBraveAll() {
    configBraveWeb
    configBraveAll
    vMenuSoftware
}

configBraveWebOnly() {
    configBraveWeb
    vMenuSoftware
}

configBraveExtOnly() {
    configBraveExt
    vMenuSoftware
}

configBraveWeb() {
    echo [Brave] Deploying policy
    sudo mkdir -p /etc/brave/policies/managed
    sudo chmod -w /etc/brave/policies/managed
    sudo wget "$base_repo/chromium-policy/raw/branch/main/varg-policy.json" -O /etc/brave/policies/managed/varg-policy.json
    echo [Brave] Policy deployed
}

configBraveExt() {
    echo [Brave] Deploying policy
    sudo mkdir -p /etc/brave/policies/managed
    sudo chmod -w /etc/brave/policies/managed
    sudo wget "$base_repo/chromium-policy/raw/branch/main/varg-policy.json" -O /etc/brave/policies/managed/varg-policy.json
    echo [Brave] Policy deployed
}

setupZen() {
    logo
    installZen
    menuItems=(
    "1. Yes"
    "Q. No "
    )
    menuActions=(
        configZen
        setupZen1
    )
    menuTitle=" Install Zen Browser Policy?"
    menuWidth=60
    menuLeft=20
    menuHighlight=$DRAW_COL_GREEN
    menuInit
    menuLoop
}

setupZen1() {
    menuItems=(
    "1. Yes"
    "Q. No "
    )
    menuActions=(
        defaultZen
        vMenuSoftware
    )
    menuTitle=" Make Zen your default browser?"
    menuWidth=60
    menuLeft=20
    menuHighlight=$DRAW_COL_GREEN
    menuInit
    menuLoop
}

configZen() {
    echo [Zen] Deploying policy
    sudo mkdir -p /etc/zen/policies
    sudo chmod -w /etc/zen/policies
    sudo wget "$base_repo/chromium-policy/raw/branch/main/varg-policy-firefox.json" -O /etc/zen/policies/policies.json
    echo [Zen] Policy deployed
    setupZen1
}

installZen() {
    echo [Zen] Installing from tarbal
    wget "https://updates.zen-browser.app/install.sh" -O /tmp/zeninstall.sh
    bash /tmp/zeninstall.sh
    rm /tmp/zeninstall.sh
    echo [Zen] Installed
}

defaultZen() {
    xdg-settings set default-web-browser zen.desktop
    vMenuSoftware
}

installAuto-cpufreq() {
    echo [auto-cpufreq] Downloading
    git clone https://github.com/AdnanHodzic/auto-cpufreq.git /tmp/auto-cpufreq
    cd /tmp/auto-cpufreq
    echo [auto-cpufreq] Installing
    sudo ./auto-cpufreq-installer
}

installAppimagelauncher() {
    wget "https://github.com/TheAssassin/AppImageLauncher/releases/download/v2.2.0/appimagelauncher_2.2.0-travis995.0f91801.bionic_amd64.deb" -O /tmp/appimagelauncher.deb
    sudo nala install -y /tmp/appimagelauncher.deb
    rm /tmp/appimagelauncher.deb
    return 1
}

installSublime() {
    echo [Sublime] Adding Repo
    wget "https://download.sublimetext.com/sublimehq-pub.gpg" -O /tmp/sublimehq-pub-download.gpg
    gpg --no-default-keyring --keyring /tmp/temp-keyring.gpg --import /tmp/sublimehq-pub-download.gpg
    gpg --no-default-keyring --keyring /tmp/temp-keyring.gpg --export --output /tmp/sublimehq-pub.gpg
    sudo mkdir -p /etc/apt/keyrings/
    sudo cp /tmp/sublimehq-pub.gpg /etc/apt/keyrings/sublimehq-pub.gpg
    rm /tmp/sublimehq-pub-download.gpg /tmp/temp-keyring.gpg /tmp/sublimehq-pub.gpg
    echo "deb [signed-by=/etc/apt/keyrings/sublimehq-pub.gpg] https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
    echo [Sublime] Updating Repo
    sudo nala update
    echo [Sublime] Installing
    sudo nala install sublime-text sublime-merge
    return 1
}

installBluetooth() {
    if ! [ -x "$(command -v bluetooth)" ]; then
        echo [Bluetooth] Installing bluetooth stack
        sudo nala install -y bluetooth
    else
        echo [Bluetooth] Bluetooth already installed
    fi
    if ! [ -x "$(command -v blueman)" ]; then
        echo [Bluetooth] Installing blueman
        sudo nala install -y blueman
    else
        echo [Bluetooth] Blueman already installed
    fi
    return 1
}

installFlatPak() {
    if ! [ -x "$(command -v flatpak)" ]; then
        echo [FlatPak] Installing
        sudo nala install -y flatpak
        flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
    else
        echo [FlatPak] Already Installed Installed
    fi
}

installSteamLink() {
    if ! [ -x "$(command -v flatpak)" ]; then
        echo [SteamLink] flatpak not found installing
        installFlatPak
    fi
    flatpakInstalled=0
    sudo flatpak info "com.valvesoftware.SteamLink" >/dev/null 2>&1 && flatpakInstalled=1
    if [ "$flatpakInstalled" = "0" ]; then
        echo [SteamLink] Installing
        sudo flatpak -y install flathub com.valvesoftware.SteamLink  
    fi
    return 1
}

quitApp() {
    return 0
}


#
# Public Functions
#
#   menuInit()
#   menuLoop()
#
#
# Public Variables to Override
#
# Should these get passed into menuInit() rather than be set as global
# script variables?
#
#   menuTop     # Top row of menu (defaults to row 2)
#   menuLeft    # Left offset for menu item text (defaults to column 15)
#   menuWidth   # Width of menu (defaults to 42 columns)
#   menuMargin  # Left offset for menu border (defaults to column 4)
#
#   menuColour      # Colour of menu text (defaults to DRAW_COL_WHITE)
#   menuHighlight   # Highlight colour for menu (defaults to DRAW_COL_GREEN)
#
#   menuTitle   # Title of menu
#   menuFooter  # Footer text of menu
#
#   menuItems   # Array containing menu item text
#   menuActions # Array containing functions to call upon menu item selection
#


# Ensure we are running under bash (will not work under sh or dash etc)
if [ "$BASH_SOURCE" = "" ]; then
    echo "ERROR: bash-menu requires to be running under bash"
    exit 1
fi

# Get script root (as we are sourced from another script, $0 will not be us)
declare -r menuScript=$(readlink -f ${BASH_SOURCE[0]})
menuRoot=$(dirname "$menuScript")

################################
# Private Variables
#
# These should not be overridden
################################
declare -a menuItems
declare -a menuActions

menuHeaderText=""
menuFooterText=""
menuBorderText=""


################################
# Setup Menu
#
# These are defaults which should
# be overridden as required.
################################

# Top of menu (row 2)
menuTop=2

# Left offset for menu items (not border)
menuLeft=15

# Width of menu
menuWidth=42

# Left offset for menu border (not menu items)
menuMargin=4

menuItems[0]="Exit"
menuActions[0]="return 0"

menuItemCount=1
menuLastItem=0

menuColour=$DRAW_COL_WHITE
menuHighlight=$DRAW_COL_GREEN

menuTitle=" Super Bash Menu System"
menuFooter=" Enter=Select, Up/Down=Prev/Next Option"


################################
# Initialise Menu
################################
menuInit() {
    menuItemCount=${#menuItems[@]}
    menuLastItem=$((menuItemCount-1))

    # Ensure header and footer are padded appropriately
    menuHeaderText=`printf "%-${menuWidth}s" "$menuTitle"`
    menuFooterText=`printf "%-${menuWidth}s" "$menuFooter"`

    # Menu (side) borders
    local marginSpaces=$((menuMargin-1))
    local menuSpaces=$((menuWidth-2))
    local leftGap=`printf "%${marginSpaces}s" ""`
    local midGap=`printf "%${menuSpaces}s" ""`
    menuBorderText="${leftGap}x${midGap}x"
}


################################
# Show Menu
################################
menu_Display() {
    local menuSize=$((menuItemCount+2))
    local menuEnd=$((menuSize+menuTop+1))

    drawClear
    drawColour $menuColour $menuHighlight

    # Menu header
    drawHighlightAt $menuTop $menuMargin "$menuHeaderText" 1

    # Menu (side) borders
    for row in $(seq 1 $menuSize); do
        drawSpecial "$menuBorderText" 1
    done

    # Menu footer
    drawHighlightAt $menuEnd $menuMargin "$menuFooterText" 1

    # Menu items
    for item in $(seq 0 $menuLastItem); do
        menu_ClearItem $item
    done
}


################################
# Mark Menu Items
################################

# Ensure menu item is not highlighted
menu_ClearItem() {
    local item=$1
    local top=$((menuTop+item+2))
    local menuText=${menuItems[$item]}

    drawPlainAt $top $menuLeft "$menuText"
}

# Highlight menu item
menu_HighlightItem() {
    local item=$1
    local top=$((menuTop+item+2))
    local menuText=${menuItems[$item]}

    drawHighlightAt $top $menuLeft "$menuText"
}


################################
# Wait for and process user input
################################
menu_HandleInput() {
    local choice=$1

    local after=$((choice+1))
    [[ $after -gt $menuLastItem ]] && after=0

    local before=$((choice-1))
    [[ $before -lt 0 ]] && before=$menuLastItem

    # Clear highlight from prev/next menu items
    menu_ClearItem $before
    menu_ClearItem $after

    # Highlight current menu item
    menu_HighlightItem $choice

    # Get keyboard input
    local key=""
    local extra=""

    read -s -n1 key 2> /dev/null >&2
    while read -s -n1 -t .05 extra 2> /dev/null >&2 ; do
        key="$key$extra"
    done

    # Handle known keys
    local escKey=`echo -en "\033"`
    local upKey=`echo -en "\033[A"`
    local downKey=`echo -en "\033[B"`

    if [[ $key = $upKey ]]; then
        return $before
    elif [[ $key = $downKey ]]; then
        return $after
    elif [[ $key = $escKey ]]; then
        if [[ $choice -eq $menuLastItem ]]; then
            # Pressing Esc while on last menu item will trigger action
            # This is a helper as we assume the last menu option is exit
            key=""
        else
            # Jumping possibly more than 1 (next/prev) item
            menu_ClearItem $choice
            return $menuLastItem
        fi
    elif [[ ${#key} -eq 1 ]]; then
        # See if we wanrt to jump to a menu item
        # by entering the first character
        for index in $(seq 0 $menuLastItem) ; do
            local item=${menuItems[$index]}
            local startChar=${item:0:1}
            if [[ "$key" = "$startChar" ]]; then
                # Jumping possibly more than 1 (next/prev) item
                menu_ClearItem $choice
                return $index
            fi
        done
    fi

    if [[ "$key" = "" ]]; then
        # Notify that Enter key was pressed
        return 255
    fi

    return $choice
}


################################
# Main Menu Loop
################################
menuLoop() {
    local choice=0
    local running=1

    menu_Display

    while [[ $running -eq 1 ]]; do
        # Enable case insensitive matching
        local caseMatch=`shopt -p nocasematch`
        shopt -s nocasematch

        menu_HandleInput $choice
        local newChoice=$?

        # Revert to previous case matching
        $caseMatch

        if [[ $newChoice -eq 255 ]]; then
            # Enter pressed - run menu action
            drawClear
            action=${menuActions[$choice]}
            $action
            running=$?

            # Back from action
            # If we are still running, redraw menu
            [[ $running -eq 1 ]] && menu_Display

        elif [[ $newChoice -lt $menuItemCount ]]; then
            # Update selected menu item
            choice=$newChoice
        fi
    done

    # Cleanup screen
    drawClear
}

#
# Public Functions:
#
#   drawClear()
#   drawColour(colour = DRAW_COL_DEF, bgColour = DRAW_COL_DEF)
#
#   drawPlain(text, newLine = 0)
#   drawSpecial(text, newLine = 0)
#   drawHighlight(text, newLine = 0)
#   drawPlainAt(left, top, text, newLine = 0)
#   drawHighlightAt(left, top, text, newLine = 0)
#
#
# Colours
#
#   DRAW_COL_DEF        # Default colour
#   DRAW_COL_BLACK
#   DRAW_COL_WHITE
#   DRAW_COL_RED
#   DRAW_COL_GREEN
#   DRAW_COL_YELLOW
#   DRAW_COL_BLUE
#   DRAW_COL_GRAY       # Light gray (grey?)
#


# Ensure we are running under bash (will not work under sh or dash etc)
if [ "$BASH_SOURCE" = "" ]; then
    echo "ERROR: bash-draw requires to be running under bash"
    exit 1
fi


DRAW_COL_DEF=39
DRAW_COL_BLACK=30
DRAW_COL_WHITE=97
DRAW_COL_RED=31
DRAW_COL_GREEN=32
DRAW_COL_YELLOW=33
DRAW_COL_BLUE=34
DRAW_COL_GRAY=37


# drawClear()
drawClear() {
    $ESC_WRITE "\033c"
}

# drawColour(colour = DRAW_COL_DEF, bgColour = DRAW_COL_DEF)
drawColour() {
    local colour=$DRAW_COL_DEF
    local bgColour=$((DRAW_COL_DEF+10))

    if [[ ! -z "$1" && "$1" != "" ]]; then
        colour="$1"
    fi

    if [[ ! -z "$2" && "$2" != "" ]]; then
        bgColour="$2"
    fi

    $ESC_ECHO "\033c\033[H\033[J\033[${colour};${bgColour}m\033[J"
}

# drawPlain(text, newLine = 0)
drawPlain() {
    if [[ -z "$2" || "$2" -eq 0 ]]; then
        $ESC_WRITE "$1"
    else
        $ESC_ECHO "$1"
    fi
}

# drawSpecial(text, newLine = 0)
drawSpecial() {
    [[ -z "$2" ]] && newLine=0 || newLine="$2"

    draw_SetDrawMode
    drawPlain "$1" "$newLine"
    draw_SetWriteMode
}

# drawHighlight(text, newLine = 0)
drawHighlight() {
    [[ -z "$2" ]] && newLine=0 || newLine="$2"

    draw_StartHighlight
    drawPlain "$1" "$newLine"
    draw_EndHighlight
}

# drawPlainAt(left, top, text, newLine = 0)
drawPlainAt() {
    [[ -z "$4" ]] && newLine=0 || newLine="$4"

    draw_MoveTo $1 $2
    drawPlain "$3" "$newLine"
}

# drawHighlightAt(left, top, text, newLine = 0)
drawHighlightAt() {
    [[ -z "$4" ]] && newLine=0 || newLine="$4"

    draw_StartHighlight
    drawPlainAt "$1" "$2" "$3" "$newLine"
    draw_EndHighlight
}


# Write escape sequence with no newline
ESC_WRITE='echo -en'

# Write escape sequence adding newline
ESC_ECHO='echo -e'


# Move cursor to specified location
draw_MoveTo() {
    $ESC_WRITE "\033[${1};${2}H"
}

draw_StartHighlight() {
    $ESC_WRITE "\033[7m"
}

draw_EndHighlight() {
    $ESC_WRITE "\033[27m"
}

draw_SetDrawMode() {
    $ESC_WRITE "\033%@\033(0"
}

draw_SetWriteMode() {
    $ESC_WRITE "\033(B"
}

start;
