#!/bin/bash
#
# a menu driven shell script sample template

#1: define variables
# ----------------------------------
# EDITOR=vim
# PASSWD=/etc/passwd
RED='\033[0;41;30m'
STD='\033[0;0;39m'

#2: user defined function
# ----------------------------------
pause(){
  read -r -p "Press [Enter] key to continue..." fackEnterKey
}

one(){
  echo "one() called"
  pause
}

# do something in two()
two(){
  echo "two() called"
  pause
}

# function to display menus
show_menus() {
  clear
  echo "~~~~~~~~~~~~~~~~~~~~~"
  echo " M A I N - M E N U"
  echo "~~~~~~~~~~~~~~~~~~~~~"
  echo "1. Set Terminal"
  echo "2. Reset Terminal"
  echo "3. Exit"
}
# read input from the keyboard and take a action
# invoke the one() when the user select 1 from the menu option.
# invoke the two() when the user select 2 from the menu option.
# Exit when user the user select 3 form the menu option.
read_options(){
  # local choice
  read -r -p "Enter choice [ 1 - 3] " choice
  case ${choice} in
    1) one ;;
    2) two ;;
    3) exit 0 ;;
    *) printf '%b\n' "${RED}Error...${STD}" && sleep 2 ;;
  esac
}

#3: trap ctrl+c, ctrl+z and quit singles
# ----------------------------------------------
trap '' INT QUIT TSTP

#4: main logic - infinite loop
# -----------------------------------
while true; do
  show_menus
  read_options
done
