terminal
[!NOTE]
terminal info
references:
- list info
$ terminfo -f $ terminfo -W
reset terminal
[!NOTE]
$ stty sane
# or
$ stty echo
# or
$ reset
# or
$ tset
tput
[!NOTE]
- tput
- * tput: Portable Terminal Control
- controlling
CAPNAME DESCRIPTION scSave the cursor position rcRestore the cursor position homeMove the cursor to upper left corner (0,0) cup <row> <col>Move the cursor to position row, col cud1Move the cursor down 1 line cuu1Move the cursor up 1 line civisSet to cursor to be invisible cnormSet the cursor to its normal state
CAPNAME DESCRIPTION boldStart bold text smulStart underlined text rmulEnd underlined text revStart reverse video blinkStart blinking text invisStart invisible text smsoStart “standout” mode rmsoEnd “standout” mode sgr0Turn off all attributes setaf <value>Set foreground color setab <value>Set background color
VALUE COLOR 0Black 1Red 2Green 3Yellow 4Blue 5Magenta 6Cyan 7White 8Not used 9Reset to default color
CAPNAME DESCRIPTION smcupSave screen contents rmcupRestore screen contents elClear from the cursor to the end of the line el1Clear from the cursor to the beginning of the line edClear from the cursor to the end of the screen clearClear the entire screen and home the cursor
- cursor action:
Name Termcap Equiv. Description civisviMake cursor invisible cvvisvsMake cursor very visible cnormveMake cursor normal (undo cvvis' &civis)'cufRIMove cursor right #1 spaces (P*) cuf1ndMove cursor right one space cubLEMove cursor left #1 spaces (P) cub1leMove cursor left one space cuuUPMove cursor up #1 lines (P*) cuu1upMove cursor up one line cudDOMove cursor down #1 lines (P*) cud1doMove cursor down one line cupcmMove cursor to row #1, column #2 of screen (P) mrcupCMMove cursor to row #1, column #2 of memory (P) vpacvMove cursor to row #1 (P) hpachMove cursor to column #1 (P) homehoHome cursor (if no `cup') hdhdMove cursor down one-half line huhuMove cursor up one-half line scscSave cursor position rcrcRestore cursor to position of last `sc' sgr0meTurn off all attributes llllGo to last line, first column (if no cup)
move sequence to top
$ tput home # or $ tput cup 0 0 # or $ tput cup %py %px >/dev/ttyshow info
$ tput -T screen longname VT 100/ANSI X3.64 virtual terminal $ tput longname xterm with 256 colors $ echo "Rows=$(tput lines) Cols=$(tput cols)" Rows=30 Cols=104set cursor
# invisible $ tput civis # normal $ tput cnormtext color
for fg_color in {0..255}; do set_foreground=$(tput setaf $fg_color) for bg_color in {0..7}; do set_background=$(tput setab $bg_color) echo -n $set_background$set_foreground printf ' F:%s B:%s ' $fg_color $bg_color done echo $(tput sgr0) donePS1
[!NOTE|label:references:]
red=$(tput setaf 1) green=$(tput setaf 2) blue=$(tput setaf 4) reset=$(tput sgr0) PS1='\[$red\]\u\[$reset\]@\[$green\]\h\[$reset\]:\[$blue\]\w\[$reset\]\$ '
shows tput processing in one invocation
$ tput -S <<! clear cup 10 10 bold ! # or $ tput -S <<EOF sc cup $line $column rev EOF %p1%d;%p2%dHprint in center of line
COLUMNS=`tput cols` export COLUMNS # Get screen width. echo "$@" | awk ' { spaces = ('$COLUMNS' - length) / 2 while (spaces-- > 0) printf (" ") print }'print in center of terminal
COLUMNS=`tput cols` LINES=`tput lines` line=`expr $LINES / 2` column=`expr \( $COLUMNS - 6 \) / 2` tput sc tput cup $line $column tput rev echo 'Hello, World' tput sgr0 tput rctput_menu: script for clean screenBG_BLUE="$(tput setab 4)" BG_BLACK="$(tput setab 0)" FG_GREEN="$(tput setaf 2)" FG_WHITE="$(tput setaf 7)" # save screen tput smcup # display menu until selection == 0 while [[ $REPLY != 0 ]]; do echo -n ${BG_BLUE}${FG_WHITE} clear cat <<- _EOF_ Please Select: 1. Display Hostname and Uptime 2. Display Disk Space 3. Display Home Space Utilization 0. Quit _EOF_ read -p "Enter selection [0-3] > " selection # clear area beneath menu tput cup 10 0 echo -n ${BG_BLACK}${FG_GREEN} tput ed tput cup 11 0 # act on selection case $selection in 1) echo "Hostname: $HOSTNAME" uptime ;; 2) df -h ;; 3) if [[ $(id -u) -eq 0 ]]; then echo "Home Space Utilization (All Users)" du -sh /home/* 2> /dev/null else echo "Home Space Utilization ($USER)" du -s $HOME/* 2> /dev/null | sort -nr fi ;; 0) break ;; *) echo "Invalid entry." ;; esac printf "\n\npress any key to continue." read -n 1 done # restore screen tput rmcup echo "Program terminated."now
[!NOTE]

1.9.3.1 -- now date time #!/usr/bin/env bash dataColumn=1 timeColumn=27 tput sc # save cursor position. #--------- DATE ------------------------------------------------------------- tput rc # restore saved cursor position. cal | tr -cd '\11\12\15\40\60-\136\140-\176' > /tmp/terminal calLineCnt=1 Today=$(date +"%e") printf "\033[32m" # color green -- see list above. while IFS= read -r Cal; do printf "%s" "$Cal" if [[ $calLineCnt -gt 2 ]] ; then tput cub 22 # see if today is on current line & invert background for (( j=0 ; j <= 18 ; j += 3 )) ; do Test=${Cal:$j:2} # Current day on calendar line if [[ "$Test" == "$Today" ]] ; then printf "\033[7m" # reverse: [7m printf "%s" "$Today" printf "\033[0m" # normal: [0m printf "\033[32m" # color green -- see list above. tput cuf 1 else tput cuf 3 fi done fi tput cud1 # down one line tput cuf $dataColumn # move 27 columns right calLineCnt=$((++calLineCnt)) done < /tmp/terminal printf "\033[00m" # color -- bright white (default) echo "" tput rc # restore saved cursor position. #-------- TIME -------------------------------------------------------------- tput sc # save cursor position. tput cuu 7 # move up 9 lines tput cuf $timeColumn # move 49 columns right if hash toilet 2>/dev/null; then # if has toilet date +"%I:%M %P" | toilet -f future > /tmp/terminal elif hash figlet 2>/dev/null; then # if has figlet date +"%I:%M %P" | figlet > /tmp/terminal else date +"%I:%M %P" > /tmp/terminal fi while IFS= read -r Time; do printf "\033[01;36m" # color cyan printf "%s" "$Time" tput cud1 # Up one line tput cuf $timeColumn # Move 49 columns right done < /tmp/terminal tput rc # Restore saved cursor position. exit 0
stty
[!NOTE|label:references:]
- 19.2 stty: Print or change terminal characteristics
- Shell does not show typed-in commands, what do I do to fix it?
- stty : set or display terminal options
- Linux in a Nutshell.pdf
- man pages section 1: User Commands: stty (1g)
- Local Modes
OPTION COMMENTS echoEchoes every character typed. -echoDoes not echo characters. echoctlEchoes control characters as ^X (Ctrl-X), where X is the character given by adding 100 octal to the code of the control character. -echoctlDoes not echo control characters as ^X (Ctrl-X). echoeEchoes the ERASE character as the "backspace space backspace" string. -echoeDoes not echo the ERASE character, just backspace. echokEchoes a NL character after a KILL character. -echokDoes not echo a NL character after a KILL character. echokeEchoes the KILL character by erasing each character on the output line. -echokeJust echoes the KILL character. echonlEchoes the NL character. -echonlDoes not echo the NL character. echoprtEchoes erased characters backwards with / (slash) and \ (backslash). -echoprtDoes not echo erased characters backwards with / (slash) and \ (backslash). icanonEnables canonical input (canonical input allows input-line editing with the ERASE and KILL characters). See the discussion about canonical mode input in Line Discipline Module (ldterm) AIX Version 4.3 Communications Programming Concepts. -icanonDisables canonical input. iextenSpecifies that implementation-defined functions shall be recognized from the input data. Recognition of the following control characters requires iexten to be set: eol2, dsusp, reprint, discard, werase, lnext. The functions associated with these modes also require iexten to be set: imaxbel, echoke, echoprt, and echoctl. -iextenSpecifies that implementation-defined functions shall not be recognized from the input data. isigEnables the checking of characters against the special control characters INTR, SUSP and QUIT special control characters. -isigDisables the checking of characters against the special control characters INTR, SUSP and QUIT special control characters. noflshDoes not clear buffers after INTR, SUSP, or QUIT control characters. -noflshClears buffers after INTR, SUSP, or QUIT control characters. pendingCauses any input that is pending after a switch from raw to canonical mode to be re-input the next time a read operation becomes pending or the next time input arrives. Pending is an internal state bit. -pendingNo text is pending. tostopSignals SIGTOU for background output. -tostopDoes not signal SIGTOU for background output. xcaseEchoes uppercase characters on input, and displays uppercase characters on output with a preceding \ (backslash). -xcaseDoes not echo uppercase characters on input.
show all
$ stty -a speed 38400 baud; rows 30; columns 104; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; dsusp = ^Y; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; status = ^T; min = 1; time = 0; -parenb -parodd cs8 hupcl -cstopb cread -clocal -crtscts -ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -ixon ixoff ixany imaxbel iutf8 opost -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -tostop -echoprt echoctl echoke -flusho -extprocshow size
$ stty size 30 104enable/disable echo
$ stty echo # or stty sane $ stty -echo
tty ( teletypewriter )
[!NOTE|label:references:]
tabs
[!NOTE|label:references]