
maybe_switch ()
{
    if [ "$THEME" = "" ] ; then
        switch
    else
        $THEME
	theme_track
    fi
}    

function f-escape ()
{

# Help, get me out of here!

read -n 1
case "$REPLY" in

	m)
	exec menu
	;;
	x)
	f-prompt
	;;
	*)
	;;
esac
}

function f-sup ()
{
# Startup info ... so people know something is happening if it takes a while
head-col
echo
echo "  Starting up, please wait........"
white
}

f-ttynum ()
{
# Print the tty number on the right edge of the screen. GNU screen|dvtm doesn't need this with INX defaults

if [ $TERM = linux ] ; then
    unbold 
    let END=$COLUMNS-5
    printf %${END}s " " ; tty | cut -d/ -f3
    white ; bold
fi

}
	
function f-prompt ()
{
	cyan ; bold 
	echo
	printf "Aarrrgh "\!" "
	yellow
	printf "You typed  "
	cyan 
	printf "X"
	yellow
	printf " ...  "
	cyan 
	printf "INX Is Not X "\!"   "
	printf "\n\n"
	white
	printf "So: - here is your command prompt..."
	echo
	echo "Type: \"inx\" or \"menu\" then hit <enter> , or just hit ctrl+d, to return to the inx script."
	echo
	unbold
	exit 0
}

line_erase () { printf "\r" ; tput el ; printf "\r" ; }

# Define some colour schemes...

standard () 
{	
    fig-col ()  { bold ; magenta ; }
    head-col () { bold ; cyan ; }
    info-col () { bold ; white ; }
    bcol ()     { bmagenta ; }
}

gringold ()
{
    fig-col ()  { bold ; green ; }
    head-col () { bold ; yellow ; }
    info-col () { bold ; white ; }
    bcol ()     { bgreen ; }
}

understated ()
{
    fig-col ()  { bold ; white ; }
    head-col () { unbold ; yellow ; }
    info-col () { unbold ; white ; }
    bcol ()     {  : ; }
}

trad ()
{
    fig-col ()  { bold ; yellow ; }
    head-col () { bold ; white ; }
    info-col () { unbold ; white ; }
    bcol ()     { bblack ; }
}

mono ()
{
    fig-col ()  { unbold ; white ; }
    head-col () { bold ; white ; }
    info-col () { unbold ; white ; }
    bcol ()     { bblack ; }
}

cool ()
{
    fig-col ()  { bold ; cyan ; }
    head-col () { bold ; white ; }
    info-col () { unbold ; cyan ; }
    bcol ()     { bblue ; }
}

uncool ()
{
    fig-col ()  { bold ; yellow ; }
    head-col () { bold ; red ; }
    info-col () { bold ; yellow ; }
    bcol ()     { bred ; }
}

ice ()
{
    fig-col ()  { bold ; cyan ; }
    head-col () { bold ; white ; }
    info-col () { unbold ; white ; }
    bcol ()     { bcyan ; }
}

glowcave ()
{
    fig-col ()  { bold ; blue ; }
    head-col () { bold ; cyan ; }
    info-col () { bold ; white ; }
    bcol ()     { bblue ; }
}

tabloid ()
{
    fig-col ()  { bold ; red ; }
    head-col () { bold ; white ; }
    info-col () { unbold ; white ; }
    bcol ()     { bred ; }
}

# Theme switch function...

switch ()
{
    case "$THEME" in

	gringold)
	export THEME="standard"
	standard
	;;
	standard)
	export THEME="mono"
	mono
	;;
	mono)
	export THEME="cool"
	cool
	;;
	cool)
	export THEME="glowcave"
	glowcave
	;;
	glowcave)
	export THEME="ice"
	ice
	;;
	ice)
	export THEME="uncool"
	uncool
	;;
	uncool)
	export THEME="trad"
	trad
	;;
	trad)
	export THEME="understated"
	understated
	;;
	understated)
	export THEME="tabloid"
	tabloid
	;;
	tabloid)
	export THEME="gringold"
	gringold
	;;
	*)
	if [ -s $HOME/.default_theme ] ; then
	    export THEME=$(cat $HOME/.default_theme)
	    $THEME
	elif [ -z $THEME ] ; then
	    export THEME="gringold"
	    gringold
	else
	    export THEME
	    $THEME
	fi        
	;;
    esac

theme_track
}

show_mounts ()
{
# Display mounted usb devices, or stuff in /media, /mnt or sshfs mounts.
info-col
echo
MNT=$(grep /mnt /etc/mtab | grep -v sshfs | cut -d" " -f2) 
MEDIA=$(grep /media /etc/mtab | grep -v sshfs | cut -d" " -f2)
SSHFS=$(grep sshfs /etc/mtab | cut -d" " -f2)
if egrep "(media|mnt|sshfs)" /etc/mtab > /dev/null 2>&1 ; then
    echo -e "  File system(s) currently mounted at:\n"

    display_mountpoints ()
        {
        if [ -n "$TEST" ] ; then 
            if [ "$TEST" != "$SSHFS" ] ; then 
                for each in $(echo "$TEST") ; do printf "  $each  " ; done
#                printf "\n" # Optional, uses extra line.
            else
                info-col ; printf "  sshfs:" ; head-col
                for each in $(echo "$TEST" | cut -d'/' -f 5) ; do printf "  $each  " ; done
            fi
            printf "\n"
        fi
        }
		bold
        head-col
        TEST=$MNT
        display_mountpoints
        fig-col
        TEST=$MEDIA
        display_mountpoints
        echo
        TEST=$SSHFS
        display_mountpoints
	
fi
}

# Colours in tput format

# Foreground colours
black ()   { tput setaf 0 ; }
red ()     { tput setaf 1 ; }
green ()   { tput setaf 2 ; }
yellow ()  { tput setaf 3 ; }
blue ()    { tput setaf 4 ; }
magenta () { tput setaf 5 ; }
cyan ()    { tput setaf 6 ; }
white ()   { tput setaf 7 ; }

bold ()    { tput bold ; }
unbold ()  { tput sgr0 ; }

# Background colours

bblack ()   { tput setab 0 ; }
bred ()     { tput setab 1 ; }
bgreen ()   { tput setab 2 ; }
byellow ()  { tput setab 3 ; }
bblue ()    { tput setab 4 ; }
bmagenta () { tput setab 5 ; }
bcyan ()    { tput setab 6 ; }
bwhite ()   { tput setab 7 ; }

# Approximate appropriate themes for mocp and irssi (some moc themes
# are *cough* unreadably bad

theme_track ()
{
case $THEME in
    gringold)
    sed -i 's/theme = .*/theme = "default"; };/' $HOME/.irssi/config
    sed -i 's/^Theme = .*/Theme = greengold/' $HOME/.moc/config            
    ;;
    tabloid)
    sed -i 's/theme = .*/theme = "colorless"; };/' $HOME/.irssi/config 
    sed -i 's/^Theme = .*/Theme = black_theme/' $HOME/.moc/config        
    ;;
    trad)
    # Use defaults (there's yellow in this, so...)
    sed -i 's/theme = .*/theme = "default"; };/' $HOME/.irssi/config
    sed -i 's/^Theme = .*/Theme = black_theme/' $HOME/.moc/config        
    ;;
    uncool)
    sed -i 's/theme = .*/theme = "default"; };/' $HOME/.irssi/config
    sed -i 's/^Theme = .*/Theme = moca_theme/' $HOME/.moc/config    
    ;;
    ice)
    sed -i 's/theme = .*/theme = "blue"; };/' $HOME/.irssi/config 
    sed -i 's/^Theme = .*/Theme = darkdot_theme/' $HOME/.moc/config        
    ;;
    glowcave)
    sed -i 's/theme = .*/theme = "blue"; };/' $HOME/.irssi/config     
    sed -i 's/^Theme = .*/Theme = transparent-background/' $HOME/.moc/config        
    ;;
    understated)
    sed -i 's/theme = .*/theme = "colorless"; };/' $HOME/.irssi/config     
    sed -i 's/^Theme = .*/Theme = black_theme/' $HOME/.moc/config        
    ;;
    standard)
    sed -i 's/theme = .*/theme = "blue"; };/' $HOME/.irssi/config
    sed -i 's/^Theme = .*/Theme = moca_theme/' $HOME/.moc/config        
    ;;
    mono)
    sed -i 's/theme = .*/theme = "colorless"; };/' $HOME/.irssi/config     
    sed -i 's/^Theme = .*/Theme = black_theme/' $HOME/.moc/config        
    ;;
    cool)
    sed -i 's/theme = .*/theme = "blue"; };/' $HOME/.irssi/config     
    sed -i 's/^Theme = .*/Theme = darkdot_theme/' $HOME/.moc/config        
    ;;
    *)
    sed -i 's/theme = .*/theme = "default"; };/' $HOME/.irssi/config
    sed -i 's/^Theme = .*/Theme = greengold/' $HOME/.moc/config            
    ;;
esac
}

