#!/bin/bash
# set -vex  #debug

PATH=$PATH:/usr/local/lib/inx
. inx_essentials
maybe_switch

fig-block ()
{
    echo -n -e "\033[s"                                # Save cursor position
    for block in $(seq 1 6) ; do tput el ; printf "\n" ; done
    echo -n -e "\033[u"                                # Restore the cursor
}

inx101 ()
{
    bblack ; unbold ; clear ; echo
    byellow 
    fig-block
    bold ; yellow
    figlet -k -t "  INX     101  "
    bblack ; yellow ; echo
    echo -e "  What is INX for, anyway?\n\n"
    white
    echo -e "  It's an evil plot to force you into using arcane incantations on the command line :)\n\n"
    yellow
    echo -e "  Well, actually...\n"
    white
    echo -e "  You can take it at your own pace.\n"
    echo ; yellow
    echo -e "  INX works on at least three levels.\n\n"
    
    printf "  1st Level:" ; white ; printf " Just type numbers and letters from the menus, and have fun.\n\n"
    yellow ; printf "  2nd Level:" ; white ; printf " Do some tutorials, then start using the tools you learn...\n\n"
    yellow ; printf "  3rd Level:" ; white ; printf " Get to the point where you type most commands yourself.\n\n\n"
    echo -e "  You can access \"INX 101\" from the \"Tools\" menu at any time.\n\n\n"
    yellow
    echo "  Hit \"b\" to go back, any other key to continue reading some hints... (recommended)"
    
    read -s -n 1 STARTING
    case $STARTING in
        b|B)
        if [ "$1" != "" ] ; then
            exec $1
        else    
            exec first-screen
	fi    
        ;;
        *)
        white ; clear
        export HEADCOL=yellow \
        TEXTCOL=white \
        BOLDNESS=bold \
        DOCDIR=/usr/local/share/doc/inx \
        DOCSUB=starter  \
        HEADFILE=headings \
        NUMBER=0 \
        DOCNAME=start
        reader
        if [ "$1" != "" ] ; then exec $1 ; else exec first-screen ; fi
        ;;
    esac    
}

welcome ()
{
    bold ; bblack ; white
    clear ; yellow
    figlet $(figlet clue) ; echo
    byellow
    fig-block
    figlet -c "Welcome to INX"

}

bblack ; white ; clear

if ! [ "$1" = "" ] && ! [ "$2" = "" ] ; then # '$2' is a function call, from another menu '$1'
    $2 $1
elif [ -e $HOME/.welcome ] ; then
    : # Don't splash every time we return from the "reader" script etc.
else
    welcome
    touch $HOME/.welcome
    sleep 3
    bblack ; clear
fi 


echo -e "\n\n"
byellow

fig-block
bold ; byellow ; yellow
figlet -t -k "                  INX   "         " Is Not X" "     "
echo 
yellow ; bblack
echo -e "\v\v"
echo
echo -e "\t\t  You probably want to enter \"1\" on your first INX run :)\n\n\n"
echo -e "\t\t  1: Getting Started with INX"
echo -e "\t\t  2: Credits"
echo -e "\t\t  3: Licence (GNU GPL, v.3)"
echo -e "\t\t  4: Choose your preferred default colour scheme."
echo -e "\t\t  5: Advanced Options and Development"
echo -e "\t\t  6: Just give me a command prompt, thanks - I know what to do..."
echo -e "\t\t  7: Guru Mode...\n\n"
echo -e "\v\v\v"

echo -n -e "\033[s"                                # Save cursor position
byellow ; tput el ; printf "\n"
echo -n -e "\033[u"                                # Restore the cursor
byellow ; yellow
echo -e "\t\t  Or just hit any other key to proceed to the INX menu..."

read -s -n 1

case $REPLY in
    1)
    inx101
    ;;
    2)
    bblack ; clear ; echo
    byellow ; yellow
    fig-block
    figlet -k "    Credits"
    bblack ; bold ; yellow 
    echo -e "\n"
    echo -e "    Blame for Bugs and the Whole Crazy INX Idea:\n"
    unbold
    echo -e "    Peter Garrett\n"
    bold ; yellow
    echo -e "    Additional Code Contributors:\n"
    unbold
    echo -e "    Karl Goetz, Dan Mazzei, David Symons\n"
    bold ; yellow
    echo -e "    The INX Team:\n"
    unbold
    echo -e "    Peter Garrett, Roupam Ghosh, Karl Goetz, Andre Mangan,"
    echo -e "    Shelagh Manton, Dan Mazzei, Paul O'Malley, David Symons\n"
    bold ; yellow
    echo -e "    Particular thanks also to:\n"
    unbold
    echo -e "    Melchior Mazzone (site hosting)"
    echo -e "    Karl Goetz (organisation of hosting and mailing list)"
    echo -e "    Andre and Fiona Mangan (hardware, and disc label artwork)"
    echo -e "    Marco Kessler at boinc.ch (European mirror)\n"
    echo -e "    All developers of Free Libre Open Source Software,"
    echo -e "    without whom none of this would be possible.\n"
    echo -e "    And the lurkers in #inx IRC on freenode.net :)\n"
    bold ; yellow
    echo -e "    Any key to return to the initial screen...\n"
    
    read -s -n 1
    exec first-screen    
    ;;
    3)
    bblack ; white ; clear 
    yellow
    cat << EOF

 The "INX Is Not X" code in /usr/local is copyright Peter Garrett 2008
 Portions copyright Karl Goetz, David Symons and Dan Mazzei 2008
 
 The 'plait' and 'plaiter' code is copyright Stephen Jungels 2006 
 (GNU GPL v.2 or later)
 
EOF
    white
    cat << EOGPL  
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 General Public License for more details.
EOGPL
    yellow
    cat << EOREAD 

 You can read the license here if you wish, in the "less" pager.
 Just type "g" for GPL. Any other key to return to the initial screen...
 
EOREAD
    read -s -n 1 GPL
    if [ $GPL = g -o $GPL = G ] ; then
        white
        less /usr/local/share/doc/inx/gpl-3.0.txt
    fi
    exec first-screen
    ;;
    4)
    exec theme
    ;;
    5)
    bblack ; white ; clear
	export HEADCOL=yellow \
	TEXTCOL=white \
	BOLDNESS=bold \
	DOCDIR=/usr/local/share/doc/inx \
	DOCSUB=advanced  \
	HEADFILE=headings \
	NUMBER=0 \
	DOCNAME=advanced
	reader
        exec first-screen
    ;;
    6)
    unbold ; clear ; exit
    ;;
    7)
    guru_mode
    ;;
    *)
    if [ "$1" != "" ] ; then
        exec $1
    else	
        welcome
        sleep 2
        bblack ; clear
        exec inx
    fi	
    ;;
esac


