#!/bin/bash
PATH=$PATH:/usr/local/lib/inx
. inx_essentials
maybe_switch

function f-office ()
{
bold
clear
echo
fig-col
figlet "  inx""  ""office"
echo
head-col
echo "  A few applications for office and organisation."
info-col
echo
echo "  1: Calendar         (calcurse)"
echo "  2: Spreadsheet      (sc)"
echo "  3: Calculator       (wcalc)"
echo "  4: Reference        (reference)"
echo
head-col
echo "  Editor Choices"
info-col
echo
echo "  5: Nano             (nano)"
echo "  6: MC Editor        (mcedit)"
echo "  7: Vim              (vim)"
echo "  8: Jed (mini-emacs) (jed)"
head-col
echo
echo "  \"Tabbed\" Office Session"
echo
info-col
echo "  9: GNU Screen Office (CTRL + A \  to quit)"
echo
fig-col
echo "  f: Flip colours"
echo "  m: INX main menu"
echo "  w: Net and Web menu."
echo "  x: Give me a command prompt."
info-col
echo
f-ttynum
read -s -n 1
case $REPLY in

	1)
	f-sup
	clear
	calcurse
	f-office
	;;
	2)
	f-sup
	clear
	sc
	f-office
	;;
	3)
	calculator ()
	    {
	    clear
	    fig-col
	    figlet "  Calculator"
	    echo
	    info-col
	    echo "  1: Run calculator	(wcalc)"
	    echo "  2: Calculator help	(wcalc -H | less)"
	    echo
	    fig-col
	    echo "  Hit any other key to return to the \"office\" menu."
	    info-col
	    read -s -n 1 CALC
	    case $CALC in
		    1)
		    f-sup
		    clear
		    white ; bold
		    wcalc
		    calculator
		    ;;
		    2)
		    wcalc -H | less
		    calculator
		    ;;
		    *)
		    f-office
		    ;;
	    esac
	    }
	calculator
	;;
	4)
        entry () 
            { 
            echo ; bold
            yellow ; echo -e "\n  Enter your search terms:" 
            white ; echo  
            printf "  "
            read
            }
        ref_function ()
            {
            unbold ; clear ; bold
            fig-col
            figlet -k -t "  Reference"
            head-col
            echo -e "\n  Look something up...\n"
            info-col
            echo "  1: On Wikipedia (text browser - elinks)"
            echo "  2: On Wikipedia (graphical browser - xlinks2)"
            echo "  3: On dict.org  (dictionary - 'dict' in the 'less' pager)"
            echo
            head-col
            echo "  m: Main menu"
            echo "  w: Net & Web menu"
            echo
	    fig-col
            echo "  Hit any other key to return to the \"office\" menu."		
            unbold
            read -s -n 1 REF
            case $REF in
                1)
                entry
                wiki "$REPLY"
                ref_function
                ;;
                2)
                if [ "$TERM" != linux ] && [ "$DISPLAY" = "" ] ; then
	            white ; bold
	            echo -e "\n  Sorry, the graphical browser does not run from Screen or dvtm."
		    sleep 5
		    ref_function
	        fi
                entry	    
                wikig "$REPLY"
                ref_function
                ;;
                3)
                entry    
                dict "$REPLY" | less
                ref_function
                ;;
                m|M)
                exec menu
                ;;
                w|W)
                exec netinx
                ;;
                *)
                f-office
                ;;
            esac 	
            }
        ref_function
	;;
	5)
	f-sup
	nano
	f-office
	;;
	6)
	f-sup
	mcedit
	f-office
	;;
	7)
	f-sup
	vim
	f-office
	;;
	8)
	f-sup
	jed
	f-office
	;;
	9)
	f-sup
        screen -S office -c $HOME/.screenrc-office
        exec office
	;;
	m)
	exec menu
	;;
	w)
	exec netinx
	;;
	f)
	switch
	f-office
	;;
	x)
	clear
	f-prompt
	;;
	*)
	f-office
	;;
esac
}

f-office
