Highlighted Menu

Highlighted Menu

am 08.01.2008 20:47:41 von apogeusistemas

Hi:

I need create an Operator=B4s Menu, and I=B4d like know how
create a highlighted rectangle like this:


-----------------------------------------
| |
| Hostname |
| |
| 1) Shutdown the System |
| |
| 2) Shutdown databank |
| |
| 3) Exit this menu |
| |
-------------------------------------------|

Thank you.

Re: Highlighted Menu

am 08.01.2008 21:46:28 von wayne

apogeusistemas@gmail.com wrote:
> Hi:
>
> I need create an Operator´s Menu, and I´d like know how
> create a highlighted rectangle like this:
>
>
> -----------------------------------------
> | |
> | Hostname |
> | |
> | 1) Shutdown the System |
> | |
> | 2) Shutdown databank |
> | |
> | 3) Exit this menu |
> | |
> -------------------------------------------|
>
> Thank you.

If you have it installed on your system (Linux) you can
use the "dialog" command.

If not, you need to use tput to draw, highlight,
blink, revers-video, change colors, etc., using
the terminal capability database "terminfo".

Here are a few demos I wrote awhile back when learning
this stuff, maybe they will help. While suggestions for
improvement are always welcome, please don't laugh!

-Wayne

========================cut-here===============

$ cat ansi_colors.sh
#!/bin/bash

# This script should show (on most terminal emulators, including
# PuTTY) all 64 combinations of foreground/background colors.
#

MAX_COLORS=$(( $(tput colors) - 1 ))

[ "$MAX_COLORS" -le 0 ] && exit 1

COL1_LEN=$(( $MAX_COLORS / 2 ))

tput clear # Move cursor to top of screen
printf '\t\t\tANSI Terminal Color Chart:\n'

# Save current cursor position:
tput sc

for bg in $(seq 0 $COL1_LEN)
do
for fg in $(seq 0 $MAX_COLORS)
do
tput setab $bg
tput setaf $fg
printf " Background color $bg, forground color $fg "
tput op # reset to default colors
echo
done
done

# Restore saved cursor position:
tput rc

COL2_START=$(( $COL1_LEN + 1 ))

for bg in $(seq $COL2_START $MAX_COLORS)
do
for fg in $(seq 0 $MAX_COLORS)
do
tput cuf 40 # more to col 40
tput setab $bg
tput setaf $fg
printf " Background color $bg, foreground color $fg "
tput op # reset to default colors
echo
done
done

========================cut-here===============

$ cat dots
#!/bin/bash
#
# dots - a demo of a fancy progress bar.
# Usage: dots num-of-items-to-process
# dots counts lines piped into it. Every so often
# a dot is displayed, and the percent complete is updated.
#
# $Id: dots,v 1.1 2005/02/12 01:09:36 wayne Exp $

PATH=/bin:/usr/bin

dots()
{
NUM_ITEMS=$1
MAX_DOTS=50
let 'ITEMS_PER_DOT = NUM_ITEMS / MAX_DOTS'
bold=`tput smso`
norm=`tput rmso`

# Initialize the terminal for ncurses:
tput sc
tput civis

echo -n "$bold(00%)$norm"

while read; do
let "cnt = (cnt + 1) % ITEMS_PER_DOT"
if [ "$cnt" -eq 0 ]
then
let 'num_dots += 1'
let 'percent = (100 * num_dots) / MAX_DOTS'
[ "$percent" -gt "100" ] && percent=100
tput rc
printf "$bold(%02d%%)$norm" "$percent"
tput smir
echo -n "."
tput rmir
fi
done
tput cnorm
echo
}

echo 'working:'
NUM=$(find /etc 2>/dev/null |wc -l)

exec 3> >(dots $NUM)

MSGS=$(find /etc 2>&1 >&3)
exec 3>&-
sleep 0.75

========================cut-here===============

$ cat dialog-demo-form
#!/bin/bash
# Demo of dialog command to produce a simple form.
# The hard part is parsing the output, which may contain
# spaces and other unsavory characters. In bash (and POSIX)
# a simple: echo $RESULTS | { read x; read y; } or loop
# won't work, as a separate shell is started for the
# pipeline stages.

# Display the form and capture the results:
RESULTS=$(dialog --stdout --form \
'Pet Registration Form' 15 65 12 \
'Your name:' 1 1 '' 1 15 20 0 \
'Pet name:' 3 1 '' 3 15 20 0 \
'Pet type:' 5 1 '' 5 15 20 0)

# If form was canceled then exit:
[ $? -ne 0 ] && exit 1

# Read form data into variables, using temp files and I/O redirection:
TMP=$(mktemp)
trap 'rm $TMP; trap - 0; exit' 0 1 2 3 15
echo "$RESULTS" > $TMP

exec 3< $TMP
read -r OWNER_NAME <&3
read -r PET_NAME <&3
read -r PET_TYPE <&3

exec 3<&-

printf "\nName is %s, Pet's name is %s, and it is a %s.\n" \
"$OWNER_NAME" "$PET_NAME" "$PET_TYPE"