File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -4,5 +4,5 @@ wait_for_keypress() {
44 stty -raw
55}
66
7- wait_for_keypress
7+ echo -n " Make your choice: " && wait_for_keypress
88echo " $REPLY "
Original file line number Diff line number Diff line change @@ -484,7 +484,7 @@ choice () {
484484 echo
485485 echo " Press 'q' to quit"
486486 echo
487- read -p " Make your choice: " -n 1 -r
487+ echo -n " Your choice: " && wait_for_keypress
488488 echo
489489
490490 if [[ $REPLY == " q" ]]; then
@@ -495,7 +495,7 @@ choice () {
495495 importantLog " Huh ($REPLY )?"
496496 fi
497497 if $waitstatus ; then
498- read -p $' \n <Press any key to return>' -n 1 -r
498+ echo -n " <Press any key to return>" && wait_for_keypress
499499 else
500500 waitonexit # back to default after method execution
501501 fi
@@ -624,3 +624,15 @@ draw_rounded_square() {
624624
625625}
626626
627+ # #####################################################
628+ # Reading single key input that works on most
629+ # shells. Usage example:
630+ # echo -n "Your choice: " && wait_for_keypress
631+ # Outputs:
632+ # REPLY - contains user selection (the key pressed)
633+ # #####################################################
634+ wait_for_keypress () {
635+ stty raw
636+ REPLY=$( dd bs=1 count=1 2> /dev/null)
637+ stty -raw
638+ }
You can’t perform that action at this time.
0 commit comments