### Copyright (C) 1996 Per Zacho
### 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 2 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.
###
### You should have received a copy of the GNU General Public License
### along with this program; if not, write to the Free Software
### Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

proc commLine {} {
    # User<->Bash interface / Commandline

    Desc "This configuration page will help you setup options"\
	"concerning the commandline. In particular which editing"\
	"mode is prefered, how to respond to scripts, etc."

    ShortDesc "Commandline"

    ### Shell behavoir ###

    Header head1 -text "Shell behavoir"\
	-background gray\
	-help "What keybindings do you want to use for your shell."

    Radio editmode -text "Select which editor keybindings Bash is to use"\
	-entryhelp {"emacs" "Use emacs keybindings."\
			"vi" "Use vi keybindings."}\
	-help "Choose how Bash is \"look and feel\". These two options"\
	"relate mainly to how the command line editor is to behave."\
	-packFrame:fill x

    Menu keymap -text "Keymap for commandline editor    "\
	-entries {"emacs" "emacs-standard" "emacs-meta" "emacs-ctlx" "vi" "vi-move"\
		      "vi-command" "vi-insert"}\
	-help "Here you can specify how the command line editor will bind keys. The above"\
	"does have influence on this setting. Usually setting the above will do."\
	-width 18\
	-packFrame:fill x

    CheckBox posix -text "Use IEEE 1003.2 Posix shell standard"\
	-default 0\
	-help "Shall Bash emulate the posix shell almost 100%. This mode differs"\
	"mainly in the way command lookup and function handling is done."\
	"It is only in very rare circumstances you would ever have to"\
	"use the posix mode."

    CheckBox interactcom -text "Allow interactive comments"\
	-default 1\
	-help "Is comments allowed in an interactive"\
	"shell. Comments are words beginning with \#, and will cause"\
	"the interpreter to ignore all remaining words on the"\
	"line. (This option is available in Bash version 2.0 only)"

    ### Command/script handling ###

    Header head2 -text "Command/script handling"\
	-background gray\
	-help "Do you want Bash to repeat your commands--useful for debugging scripts."

    CheckBox verb -text "Display shell commands before running them"\
	-default 0\
	-help "Display the shell commands, as they are read."

    CheckBox xtrac -text "Display shell commands after commandline processing"\
	-default 0\
	-help "Display shell command after it has been processed."\
	"In contrast to previous, commands are written as shell"\
	"will execute them (i.e. aliases, variables, etc. are expanded"\
	"to commands, paths, etc). For each level of expansion, Bash"\
	"will print (at default) \"+\", which is Prompt 4."

    CheckBox chkhash -text "Check command hash table, before searching path"\
	-default 0\
	-help "If set, Bash checks that a command found in the hash table exists"\
	"before trying to execute it. If a hashed command no longer exists, a normal"\
	"(and time consuming) path search is performed. (This option is	available"\
	"in Bash version 2.0 only)"


    ### Shell termination ###

    Header head3 -text "Shell termination"\
	-background gray\
	-help "How to terminate your Bash shell when finished."

    Int igneof -text "How many \"CTRL-d\" equals a \"logout\" or \"exit\" command"\
	-default 10\
	-help "You can specify how many consecutive \"CTRL-d\" key sequences equals"\
	"a \"logout\" or \"exit\" command."

    Line line1

    Label label1 -textafter "Bash is able to auto-logout\nif the shell is idle for"\
	"certain number of seconds."\
	-text "    "\
	-help "This option is intended for use with dial-up terminals, but can"\
	"also be used for other purposes (e.g. if you forget to"\
	"logout). If you leave the field blank, or type zero (0),"\
	"the auto-logout feature is disabled."
    
    Int timeout -text "Idle for"\
	-textafter "seconds before auto-logout (0 = disabled)"\
	-default 0\
	-help "This option is intended for use with dial-up terminals, but can"\
	"also be used for other purposes (e.g. if you forget to"\
	"logout). If you leave the field blank, or type zero (0),"\
	"the auto-logout feature is disabled."

    ### Miscellaneous variables ###

    Header head4 -text "Miscellaneous variables"\
	-background gray\
	-help "Location of Bash and your favourite editor."

    File-Dir-Browser editor -text "Location of favourite (default) editor"\
	-exist 1

    foreach elm {frame_editor editor com_editor} {
	Help $elm "Location of your favourite editor. Please remember to write the complete path"\
	    and name of editor. If in doubt, try \"whereis\" command with name of editor."\
	    "Then cut'n'paste information after the colon (:)"
}

    ShowPage {
        if {[set version@bash(index)]} {
	    Enable interactcom
	    Enable chkhash
        } {
	    Disable interactcom
	    Disable chkhash
        }
    }

    Init {
	### Read default values from shell ###
	if {[info exists env(EDITOR)]} {
	    set com_editor $env(EDITOR)
	} {
	    set com_editor "emacs"
	}
    }

    Change {
	if {$editmode(index)} {
	    if {$keymap(index) < 4} {set keymap(index) 4}
	} {
	    if {$keymap(index) > 3} {set keymap(index) 0}
	}
    }

    PageEnd {
	if {$igneof < 0} {error "You have to specify a positive (or zero) number of key sequences to equal \"logout\" or \"exit\""}
    }

    Save {
	### Shell behavoir ###
	if {$editmode(index) || $generateDefault} {
	    print "set -o [pick $editmode(index) vi emacs]"
	    print -file inputrc "set editing-mode [pick $editmode(index) vi emacs]"
	}

	if {$keymap(index) || $generateDefault} {
	    print -file inputrc "set keymap $keymap(name)"
	}
	    
	if {$posix || $generateDefault} {
	    print "set [pick $posix - +]o posix"
	}

	if {($interactcom != 1 || $generateDefault) && [set version@bash(index)]} {
	    print "shopt -[pick $interactcom s u] interactive_comments"
	}

	### Command/script handling ###
	if {$verb || $generateDefault} {
	    print "set [pick $verb - +]o verbose"
	}

	if {$xtrac || $generateDefault} {
	    print "set [pick $xtrac - +]o xtrace"
	}

	if {($chkhash || $generateDefault) && [set version@bash(index)]} {
	    print "shopt -[pick $chkhash s u] checkhash"
	}

	### Shell termination ###
	if {$igneof != 10 || $generateDefault} {
	    if {$igneof != 10} {
		print "export IGNOREEOF=$igneof"
	    } {
		print "set -o ignoreeof"
	    }
	}

	if {$timeout > 0 || $generateDefault} {
	    print "[pick [expr $timeout > 1] "TMOUT=$timeout" "unset TMOUT"]"
	}

	### Miscellaneous variables ###
	if {$editor != "" || $generateDefault} {
	    print "export EDITOR='$editor'"
	}
    }
}









