Friday, September 23, 2011

Simple Bash tput menu

Nice and simple tput menu.

#!/usr/bin/env bash

# clear the screen
tput clear

# Move cursor to screen location X,Y (top left is 0,0)
tput cup 3 15

# Set a foreground colour using ANSI escape
tput setaf 3
echo "-- MAIN MENU --"
tput sgr0

tput cup 5 17
# Set reverse video mode
tput rev
echo "M A I N - M E N U"
tput sgr0

tput cup 7 15
echo "1. Run All Tests"

tput cup 8 15
echo "2. Run Specific Test"

tput cup 9 15
echo "Q. Quit Menu"

# Set bold mode
tput bold
tput cup 12 15
read -p "Enter your choice [1-4] " choice

tput clear
tput sgr0
tput rc

case $choice in
1) echo "Running All tests";;
2) echo "Run specific Test";;
q|Q) echo "Exiting Menu.";exit 0;;
*) echo "Invalid option";;

esac

No comments:

Post a Comment