### 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 ttyApp {} {
    # User<->Bash interface / TTY appearance

    Desc "This configuration page will help you to setup screen appearance,"\
    "i.e. screen width and height, bell style, etc."

    ShortDesc "TTY appearance"

    ### TTY related information ###

    Header head1 -text "TTY related information"\
	    -background gray\
	    -help "TTY is an abbreviation for Teletype (tm)Teletype Corp. TTY has"\
	    "come to mean any terminal."

    Label label1 -text "Dimensions of character terminal"\
	    -help "When using a non-character (graphic) terminal--like X windows, these"\
	    "variables are of less interest. Actually the X window system"\
	    "adjust these variables according to the actual size of xterm window."

    Int col -text "Screen width"\
	    -help "Set the screen width. This information is mainly used in connection"\
	    "with character based terminals--not X windows."

    Int lin -text "Screen height"\
	    -help "Set the screen height. This information is mainly used in connection"\
	    "with character based terminals--not X windows."

    Frame frame1 -entries {col lin}\
	    -orient left\
	    -default {80 24}

    CheckBox chkWinSize -text "Automatic update of width/height"\
	    -help "If set, bash checks the window  size  after each command and, if"\
	    "necessary, updates the values of LINES and COLUMNS. (This option is"\
	    "available in Bash version 2.0 only)"\
	    -default 0

    Line line1

    Radio scroll -text "If commandline exceeds screen width..."\
	    -defaultIndex 0\
	    -entryhelp {"wrap onto new line" "Wrap the line onto a new screen line."\
	    "scroll horizontally" "Scroll horizontally to make room for more."}\
	    -help "This option enables you to choose how the commandline"\
	    "will react when you type beyond the right-hand side of the screen."\
	    -packFrame:fill x

    Line line2

    Radio bell -text "Bell type"\
	    -defaultIndex 1\
	    -entryhelp {"none (disabled)" "Never ring the bell."\
	    "audible" "Use computer bell (beep)."\
	    "visible" "Use, if possible, visual bell (flash screen)."}\
	    -help "This option enables you to choose how the command editor"\
	    "will inform you of errors or similar (where bell is used). The audible bell (beep) is"\
	    "default."\
	    -packFrame:fill x

    Line line3

    CheckBox meta -text "Allow 8-bit characters in commandlines"\
	    -default 0\
	    -help "Is Bash to allow eight-bit characters in commands. If you are"\
	    "using characters, which are not included in the \"standard\" a to z, you"\
	    "should enable this option."

    CheckBox convert -text "Convert 8-bit characters to ESC sequences"\
	    -default 1\
	    -help "When the shell encounters eight-bit characters, it will strip"\
	    "the eigth bit, and prefix an ESC character."

    CheckBox output -text "Display 8-bit characters"\
	    -default 0\
	    -help "Display eight-bit characters on terminal."

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

    Change {
	if {$chkWinSize} {
	    Disable frame1
	} {
	    Enable frame1
	}
    }

    PageEnd {
	if {$col < 1 || $lin < 1} {
	    error "Screen dimensions are always nonzero, positive integers."
	}
    }

    Save {
	### TTY related information ###
	if {$chkWinSize || $generateDefault} {
	    print "shopt -[pick $chkWinSize s u] checkwinsize"
	}
	if {($col != 80 || $generateDefault) && $chkWinSize == 0} {
	    print "export COLUMNS=$col"
	}
	if {($lin != 24 || $generateDefault) && $chkWinSize == 0} {
	    print "export LINES=$lin"
	}

	if {$scroll(index) || $generateDefault} {
	    print -file inputrc "set horizontal-scroll-mode [pick $scroll(index) on off]"
	}

	if {$bell(index) != 1 || $generateDefault} {
	    set temp "set bell-style"
	    switch $bell(index) {
		0 {lappend temp "none"}
		1 {lappend temp "audible"}
		2 {lappend temp "visible"}
	    }
	    print -file inputrc $temp
	}

	if {$meta || $generateDefault} {
	    print -file inputrc "set meta-flag [pick $meta on off]"
	}

	if {$convert == 0 || $generateDefault} {
	    print -file inputrc "set convert-meta [pick $convert on off]"
	}

	if {$output || $generateDefault} {
	    print -file inputrc "set output-meta [pick $output on off]"
	}
    }
}

