### Copyright (C) 1995-1997 Jesper K. Pedersen
### 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 R widget} {

  CheckBox useTilte \
      -text "Use tilde substitution" \
      -default 1 

  Line line1

  CheckBox trailing \
      -text "Show only the trailing part of the path" 
  
  CheckBox showSkipped \
      -text "Show number of skipped elements" 

  Int dirs \
      -text "Number of directories to see in the path"\
      -default 4 

  FillOutElm cwd \
      -text "current working directory" \
      -entries useTilte line1 trailing showSkipped dirs\
      -show {print \[cwd\]}\
      -save {
        if {$trailing} {
          print "[pick $useTilte {%c} {%C}][pick $showSkipped {0} {}]$dirs"
        } else {
          print [pick $useTilte "%~" "%/"]
        }
      } \
      -change {
        if {$changeElm == "trailing"} {
          if {$trailing} {
            Enable showSkipped dirs
          } else {
            Disable showSkipped dirs
          }
        }
      } \
      -pageEnd {
        if {$trailing && $dirs == ""} {
          error "Entry with text:"\
              "\"Number of directories to see in the path\" is empty"
        }
      }
     
  
  ############################################################
  FillOutElm history \
      -text "the current history event number" \
      -show {print \[history \#\]}\
      -save "print %h" 
  ############################################################
  CheckBox fullHostName \
      -text "Use full host name" 
  
  FillOutElm hostname \
      -text "hostname" \
      -entries fullHostName\
      -show {print \[Host\]} \
      -save {
        print "[pick $fullHostName {%M} {%m}]"
      } 
  ############################################################
  Radio startStop \
      -text "What to do" \
      -entries Start Stop
  Radio Font \
      -text "Which font" \
      -entries {"Standout (inverse video)" Bold Underline Xterm}
  
  FillOutElm fontChange \
      -text "font change" \
      -entries startStop Font \
      -show {
        switch [list $startStop(name) $Font(index)] {
          {Start 0} {print \[standout->}
          {Stop 0} {print <-standout\]}
          {Start 1} {print \[bold->}
          {Stop 1} {print <-bold\]}
          {Start 2} {print \[underline->}
          {Stop 2} {print <-underline\]}
          {Start 3} {print \[XTerm->}
          {Stop 3} {print <-XTerm\]}
        }
      } \
      -save {
        switch [list $startStop(name) $Font(index)] {
          {Start 0} "print %S"
          {Stop 0} "print %s"
          {Start 1} "print %B"
          {Stop 1} "print %b"
          {Start 2} "print %U"
          {Stop 2} "print %u"
          {Start 3} "print \"%{]2;\""
          {Stop 3} "print %}"
        }
      }

  ############################################################
  Radio color \
    -text Color -entries black red green yellow blue magneta cyan white

  FillOutElm colorFill\
    -text color change\
    -entries color\
    -show {print \[$color(name)\]}\
    -save {
      switch $color(index) {
        0 "print {%{[30m%}}"
        1 "print {%{[31m%}}"
        2 "print {%{[32m%}}"
        3 "print {%{[33m%}}"
        4 "print {%{[34m%}}"
        5 "print {%{[35m%}}"
        6 "print {%{[36m%}}"
        7 "print {%{[37m%}}"
      }
    }
        

  ############################################################
  Radio ampm \
      -text "What format" \
      -entries {"Am/PM" "24 hour"} 

  CheckBox  sec \
      -text "Show seconds" 
  
  FillOutElm time \
      -text time \
      -entries ampm sec \
      -show {print \[time\]} \
      -save {
        switch [list $ampm(index) $sec] {
          {0 0} {print %t}
          {0 1} {print %p}
          {1 0} {print %T}
          {1 1} {print %P}
        }
      } 
  ############################################################
  Radio wmy \
      -text "What information" \
      -entries Day Month Year 

  Line line2 

  Radio dayType \
      -text Format of day \
      -entries {"Week day (like Wed)" "day in month (like 07)"}

  Line line3

  Radio monthType \
      -text Format of month \
      -entries {"Month name (like Jun)" "Month number (like 06)"}

  Line line4
  Radio yearType \
      -text "Format of Year" \
      -entries {"two digits (like 95)" "four digits (like 1995)"}

  Line line5
  
  FillOutElm date \
      -text date \
      -entries wmy line2 dayType line3 monthType line4 yearType line5 \
      -change {
        if {$changeElm == "wmy"} {
          switch $wmy(index) {
            0 {Enable dayType;Disable monthType yearType}
            1 {Enable monthType; Disable dayType yearType}
            2 {Enable yearType; Disable dayType monthType}
          }
        }
      } \
      -show {
        switch $wmy(index) {
          0 {print \[Day\]}
          1 {print \[Month\]}
          2 {print \[Year\]}
        }
      } \
      -save {
        switch $wmy(index) {
          0 {print [pick $dayType(index) {%D} {%d}]}
          1 {print [pick $monthType(index) {%W} {%w}]}
          2 {print [pick $yearType(index) {%Y} {%y}]}
        }
      }  
  ############################################################
  FillOutElm user \
      -text user name \
      -show {print \[user\]} \
      -save {print %n} 
  ############################################################
  FillOutElm percent \
      -text a percent sign \
      -show {print \[%\]} \
      -save {print %%} 
  
  ############################################################
  FillOutElm tty \
      -text "the shell's tty" \
      -show {print \[tty\]} \
      -save {print %l} 
  ############################################################
  FillOutElm returnCode \
      -text "last return code" \
      -show {print \[Return Code\]} \
      -save "print %?" 
  ############################################################
  if {$R != ""} {
    set text [lindex $R 0]
    set show [lindex $R 1]
    set help [lindex $R 2]
    FillOutElm R \
        -text $text \
        -show "print \\\[$show\\\]" \
        -save "print %R" \
        -help $help
  }
  ############################################################
  FillOutElm clear \
      -text "clear to end of line/display" \
      -show {print \[Clear\]} \
      -save "print %L" 
  ############################################################
  Entry extraopt \
      -text "Extra options" 
      
  FillOutElm extra \
      -text "extra escape options" \
      -entries extraopt \
      -show {print \[extra opt\]} \
      -save {print %\{$extraopt%\}}
  ############################################################
  FillOutElm superUser \
      -text "Super user char" \
      -show {print "\[Super Char\]"}\
      -save {print "%\#"} 

  ############################################################
  set help [lindex $widget 1]
  set text [lindex $widget 0]
  FillOut prompt \
    -text $text \
    -entries cwd history hostname fontChange colorFill time date user \
    percent tty\
    returnCode [pick "\{$R\} == {}" {} R] clear extra superUser\
    -default $default \
    -listbox:width 50 -listbox:height [pick "\{$R\} == {}" 13 14] \
    -help [join $help] \
    -packFrame:anchor c


  ################################ Help ################################
  Help useTilte \
      "If you select this, your home directory will be represented by"\
      "\"~\" and other users' home directories represented by \"~user\""
  
  Help trailing \
      "if you select this, the path will cut down to only the last"\
      "elements"
  
  Help showSkipped \
      "If you select this option, the number of skipped element"\
      "will be shown in the prompt like this: /<1>local/etc/httpd/cgi-bin"

  Help dirs \
      "this is the number of dirs to show, like this:\n"\
      "current dir = /a/b/c/d this option = 2\n"\
      "prompt = c/d"
   
  Help history \
      "The history event number can be used to re-invoke"\
      "earlier commands. To invoke the command with history event number"\
      "7 type \"!7\""

  Help fullHostName \
      "if you use full host name a machine called \"salieri.imada.sdu.dk\""\
      "will be prompted as \"salieri.imada.sdu.dk\", otherwise it will just"\
      "be prompted as \"salieri\""
  
  Help hostname \
      "This is the name of the machine the shell is running on."
  
  Help startStop "Here you select whether you wish to start or stop the"\
    "formating option. You should insert both a start and a stop"\
    "formater!"

  EntryHelp Font Bold "This option will make the text bold face"
  EntryHelp Font Underline "This option will make the text underlined"
  EntryHelp Font Xterm "This option will bring the text into the xterm"\
    "menu title bar. You should not use this together with others of"\
    "the font options, or any of the color options."

  Help colorFill "This lets you change the color of the prompt. You should"\
    "remember to change it back to black at the end, otherwise the"\
    "command line will be type set in the given color!"

  Help color "Select the color you wish to change to."

  Help fontChange \
      "This lets you change the font on the line. It is very useful"\
      "when you want some part of the prompt to be extra visible\n" \
      "In addition, you have the chance to set the title of an XTerm"\
      "window."
  
  Help ampm \
      "Here you can configure whether the time shall be in AM/PM"\
      "format or in 24 hour format"
  
  Help sec \
      "Will you see the seconds too in your prompt or only"\
      "the hour and minute"
  
  Help time \
      "This gives you the time in the prompt"
  
  Help date \
      "This gives you the date in the prompt"

  Help user \
      "This is expanded to the current user."
  
  Help percent \
      "This is just a percent sign. Do not type one yourself"\
      "because the percent sign is a special character to the prompt."

  Help tty \
      "This is the tty the shell is running in."
  
  Help returnCode \
      "This is the return code of the program, which finished just"\
      "before the prompt is shown."
  
  Help clear \
      "Clears from the end of the prompt to end of the"\
      "display or the end of line"
  
  Help extra \
      "This is for extra option to termcap"

  Help superUser \
      "This expands to \">\" for an ordinary user, and \"\#\""\
      "for a super user (root). Or the chars specified in prompt/general."

}
