-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Set mute & volume property explicitly to be able to hear audio always
- Loading branch information
1 parent
ba4dedf
commit 56c3ea0
Showing
3 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then | ||
echo "$0 <list of options delimited by colon>" | ||
echo "$0 -f <file containing list of optons>" | ||
exit 0 | ||
fi | ||
|
||
if [[ "$1" == "-s" ]] || [[ "$1" == "--single-shot" ]]; then | ||
singleShot=1 | ||
shift | ||
fi | ||
|
||
if [[ "$1" == "-f" ]]; then | ||
if [[ ! -f "$2" ]]; then | ||
echo "Input file \"$2\" is not present" | ||
exit 1 | ||
fi | ||
|
||
options=$(cat $2) | ||
else | ||
options="$*" | ||
fi | ||
|
||
handler=${!#} | ||
if [[ -f "$handler" ]]; then | ||
if [[ ! -x "$handler" ]]; then | ||
echo "Handler file \"$handler\" found, but lacks executable permissiong, check" | ||
exit 1 | ||
else | ||
options=${@:1:$#-1} | ||
fi | ||
else | ||
handler='' | ||
fi | ||
|
||
prevChoice='0' | ||
|
||
function cleanTmpFile() { | ||
if [[ ! -z "$optionFile" ]] && [[ -e $optionFile ]]; then | ||
rm $optionFile | ||
fi | ||
} | ||
|
||
trap cleanTmpFile SIGINT | ||
|
||
while :; do | ||
|
||
optionFile=$(mktemp) | ||
./menu_driver.sh $optionFile "$prevChoice" "$options" | ||
|
||
if [[ -e $optionFile ]]; then | ||
result=$(cat $optionFile) | ||
prevChoice=$(echo $result | cut -d ':' -f 1) | ||
menu="$(echo $result | cut -d ':' -f 2)" | ||
else | ||
prevChoice=0 | ||
fi | ||
|
||
if [[ $prevChoice -eq 0 ]]; then | ||
exit 0 | ||
fi | ||
|
||
if [[ ! -z "$handler" ]]; then | ||
$handler "$menu" | ||
fi | ||
|
||
if [[ $singleShot -eq 1 ]]; then | ||
exit 0 | ||
fi | ||
|
||
cleanTmpFile | ||
|
||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/bin/sh | ||
|
||
choice=0 | ||
maxChoice=-1 | ||
prevChoice=-1 | ||
navChoice=1 | ||
declare -A menuMap | ||
menuMap[1]=1 | ||
|
||
if [[ $# -le 1 ]]; then | ||
echo "Pass <file_to_store_option> as first arg and ':' separated list of options" | ||
exit 1 | ||
fi | ||
|
||
# If first arg is a tmp file (where the caller wants to read the choice entered by user) | ||
# confirm if it is indeed a tmp file and shift the args | ||
outputFile=$1 | ||
if [[ -f $outputFile ]] && [[ $outputFile =~ ^/tmp/tmp.* ]]; then | ||
shift | ||
fi | ||
|
||
if [[ $1 =~ ^[0-9]+$ ]]; then | ||
prevChoice=$1 | ||
navChoice=$1 | ||
shift | ||
fi | ||
|
||
inputList=$(echo $* | sed -e 's/ /<SPACE>/g' -e 's/:/ /g') | ||
|
||
displayMenu() { | ||
idx=1 | ||
menuList=$1 | ||
|
||
#clear | ||
for menu in $menuList;do | ||
menuMap[$idx]="$(echo $menu | sed 's/<SPACE>/ /g')" | ||
|
||
if [[ $prevChoice -eq $idx ]]; then # Previously chose option | ||
echo -n "*" | ||
elif [[ $navChoice -eq $idx ]]; then # Provisional option i.e in the process of navigating using keys | ||
echo -n "-" | ||
else | ||
echo -n " " | ||
fi | ||
|
||
printf "%2d : %s\n" $idx "${menuMap[$idx]}" | ||
idx=$((idx+1)) | ||
done | ||
echo " 0 : Exit" | ||
|
||
if [[ $maxChoice -eq -1 ]]; then | ||
maxChoice=$((idx-1)) | ||
fi | ||
} | ||
|
||
while :; do | ||
|
||
displayMenu "$inputList" | ||
|
||
read -e -p "Choose the option : " choice | ||
|
||
case $choice in | ||
0) | ||
exit 0 | ||
;; | ||
|
||
"") | ||
if [[ ! -z "$navChoice" ]] && [[ $navChoice -ge 1 ]] && [[ $navChoice -le $maxChoice ]]; then | ||
choice=$navChoice | ||
prevChoice=$navChoice | ||
break | ||
fi | ||
;; | ||
|
||
[up]) | ||
if [[ $navChoice -gt 1 ]]; then | ||
navChoice=$((navChoice-1)) | ||
else | ||
navChoice=$maxChoice | ||
fi | ||
;; | ||
|
||
[dn]) | ||
if [[ $navChoice -lt $maxChoice ]]; then | ||
navChoice=$((navChoice+1)) | ||
else | ||
navChoice=1 | ||
fi | ||
;; | ||
|
||
*) | ||
if [[ $choice -ge 1 ]] && [[ $choice -le $maxChoice ]]; then | ||
prevChoice=$choice | ||
navChoice=$choice | ||
break | ||
else | ||
echo "Incorrect option, try again" | ||
sleep 1 | ||
continue | ||
fi | ||
;; | ||
|
||
esac | ||
|
||
done | ||
|
||
echo "$choice:${menuMap[$choice]}" > $outputFile |