### Copyright (C) 1996,97 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 promptWidget {default texthelp} {

    ### Time ###
    FillOutElm time -text "Current time"\
	    -show {print "<23:59:59>"}\
	    -save {print "\\t"}\
	    -help "Print the current time in 24 hour format. Time is only updated when a"\
	    "new prompt is issued."

    ### Date ###
    FillOutElm date -text "Current date"\
	    -show {print "<Wed July 17>"}\
	    -save {print "\\d"}\
	    -help "Print the date as \"Weekday Month Date\". Date is only updated when a"\
	    "new prompt is issued."

    ### Shell ###
    FillOutElm shell -text "Name of shell"\
	    -show {print "<bash>"}\
	    -save {print "\\s"}\
	    -help "Print the name of shell--usually \"bash\". The name is extracted from the"\
	    "basename (the portion following the final slash) of \$0 (the commandline which"\
	    "invoked the shell)."

    ### User ###
    FillOutElm user -text "Username"\
	    -show {print "<user>"}\
	    -save {print "\\u"}\
	    -help "Print the name of current user."

    ### Host ###
    FillOutElm host -text "Hostname"\
	    -show {print "<host>"}\
	    -save {print "\\h"}\
	    -help "Print the name of host."

    ### Directory ###
    Radio dirType -text "How much directory information to print?"\
	    -entryhelp {"entire directory" "Print the entire working directory."\
	    "basename of directory" "Print only the trailing part of current working directory."}\
	    -help "You can specify how much directory information to include when prompting."\
	    "Basename of directory is the portion following the final slash.\n"\
	    "Example: the basename of \"/usr/local/lib\" is \"lib\"."

    FillOutElm dir -text "Current working directory"\
	    -entries dirType\
	    -show {if {$dirType(index)} {print "<lib>"} {print "</usr/local/lib>"}}\
	    -save {if {$dirType(index)} {print "\\W"} {print "\\w"}}\
	    -help "Print the entire or basename of current working directory."

    ### History ###
    FillOutElm hist -text "History number"\
	    -show {print "<hist\#>"}\
	    -save {print "\\!"}\
	    -help "Print the history number of the command."

    ### Command ###
    FillOutElm comm -text "Command number"\
	    -show {print "<command\#>"}\
	    -save {print "\\\#"}\
	    -help "Print the command number of the command."

    ### Super user ###
    FillOutElm supusr -text "Super user char"\
	    -show {print "<\$>"}\
	    -save {print "\\$"}\
	    -help "Print a \$ for an ordinary user and a \# for a super user (root)."

    ### Newline ###
    FillOutElm newline -text "Newline"\
	    -show {print "\266"}\
	    -save {print "\\n"}\
	    -help "Force following information to wrap onto a new line."

    ### Special char ###
    Label label1 -text "Print a special character"\
	    -help "You can specify a character to display by its octal number."

    CheckBox backsl -text "Print a backslash"\
	    -default 0

    Entry specharEnt -text "Character number (octal)"\
	    -width 4\
	    -default "000"\
	    -help "Enter the octal number of character to display."\
	    "Remember to add prefix zeros if necessary."

    FillOutElm spechar -text "Special character"\
	    -entries label1 backsl specharEnt\
	    -show {if {$backsl} {print "<\\>"} {print "<\\$specharEnt>"}}\
	    -save {if {$backsl} {print "\\\\"} {print "\\$specharEnt"}}\
	    -change {if {$backsl} {Disable specharEnt} {Enable specharEnt}}\
	    -pageEnd {if {[string length $specharEnt] != 3 && [expr $backsl == 0]} {error "The octal number has an illegal size. It must be three ciffers wide."}}\
	    -help "Enter the octal number of character."\
	    "Remember to add prefix zeros if necessary."

    ### Colors ###
    set colorlistFG {"current color" "black" "darkgray" "red" "light red" "green" "light green"\
	    "brown" "yellow" "blue" "light blue" "purple" "light purple" "cyan" "light cyan"\
	    "light gray" "white"}

    set colorlistBG {"current color" "black" "red" "green" "brown" "blue" "purple" "cyan" "gray"}
    
    Header header1 -text "Colors"\
	    -background gray

    CheckBox defaultCol -text "Change to default colors and attributes"\
	    -default 1\
	    -help "Change to the default color settings."

    Line line1

    Label label2 -text "Character attributes"\
	    -anchor center

    CheckBox underline -text "Underlined"\
	    -help "Apply underline to characters."\
	    -anchor center\
	    -pack:fill x

    CheckBox flashing -text "Flashing (blinking)"\
	    -help "Make characters flash."\
	    -anchor center\
	    -pack:fill x

    Frame frame1 -entries {underline flashing}\
	    -orient left


    Line line2

    Menu foreground -text "Foreground color"\
	    -entries $colorlistFG\
	    -help "Choose which color for text (foreground)."\
	    -width 10\
	    -defaultIndex 15

    Menu background -text "Background color"\
	    -entries $colorlistBG\
	    -help "Choose which color to use under characters (background)."\
	    -width 10\
	    -defaultIndex 1

    Frame frame2 -entries {foreground background}\
	    -orient left

    FillOutElm colors -text "Colors"\
	    -entries {header1 defaultCol line1 label2 frame1 line2 frame2}\
	    -init {Disable label2; Disable frame1; Disable frame2}\
	    -change {if {$defaultCol} {Disable label2; Disable frame1; Disable frame2} {Enable label2; Enable frame1; Enable frame2}}\
	    -show {
	      set temp ""
	      if {$defaultCol} {
	        append temp "color default"
	      } {
	        if {$underline} {
		  append temp "underline,"
	        }
	        if {$flashing} {
		  append temp "flashing,"
	        }
	        if {$foreground(index)} {
		  append temp "fg:$foreground(name),"
	        }
	        if {$background(index)} {
		  append temp "bg:$background(name)"
	        }
	      }
	      set temp [string trim $temp ","]
	      if {$temp != ""} {
	        print "<$temp>"
                }
	    }\
	    -save {
	      set ansicodeFG {"current color" "30" "1;30" "31" "1;31" "32" "1;32" "33" "1;33"\
		      "34" "1;34" "35" "1;35" "36" "1;36" "37" "1;37"}
	      set ansicodeBG {"current color" "40" "41" "42" "43" "44" "45" "46" "47"}
	      set temp ""
	      if {$defaultCol} {
	        append temp "0"
	      } {
	        if {$underline} {
		  append temp "4;"
	        }
	        if {$flashing} {
		  append temp "5;"
	        }
	        if {$foreground(index)} {
		  append temp "[lindex $ansicodeFG $foreground(index)];"
	        }
	        if {$background(index)} {
		  append temp "[lindex $ansicodeBG $background(index)]"
	        }
	      }
	      set temp [string trim $temp ";"]
	      if {$temp != ""} {
		  print "\\\[\\033\[${temp}m\\\]"
                }
	    }\
	    -help "Choose colors for prompt. Not all terminals support colors--to make use"\
	    "of this option, you must choose a terminal that is ISO6429 (VT100/ANSI) compatible."

    ### TTY codes ###
    Entry extra -text "Non-printing characters"\
	    -help "Codes to send to the TTY. These codes could alter screen colors, clear rest"\
	    "of the commandline, or the entire screen. Codes here depend on what kind of"\
	    "terminal you use--most common is the VT100 or compatible."

    FillOutElm ttycode -text "Non-printing characters"\
	    -entries extra\
	    -help "Codes to send to the TTY. These codes could alter screen colors, clear rest"\
	    "of the commandline, or the entire screen. Codes here depend on what kind of"\
	    "terminal you use--most common is the VT100 or compatible."

    ### FillOut ###
    set help [lindex $texthelp 1]
    set text [lindex $texthelp 0]
    set elem {time date shell user host dir hist comm supusr newline spechar colors ttycode}

    Header head1 -text $text\
	    -background gray\
	    -help "Setup of $text."
    
    FillOut prompt -text ""\
	    -entries $elem\
	    -default $default\
	    -listbox:width 50\
	    -listbox:height [llength $elem]\
	    -help [join $help]\
	    -packFrame:anchor center
}

