0

enter image description here

I'm learning Bash Script and now want to make a simple console game just using pure Bash without external libraries. But I'm just wondering how to make buttons and attach some key presses like the Enter key for users to make some app's logic events.

Would anyone suggest or give me some resources to achieve this?

frankiie
  • 101
  • 1
  • Probably this is an interesting post for you: [How do I create a terminal based gui](https://unix.stackexchange.com/questions/285777/how-do-i-create-a-terminal-based-gui) – thanasisp May 06 '22 at 20:22
  • @thanasisp Thanks for the suggestion! However, I don't want to use external libraries such `dialog` , etc. Is any way to draw the simple GUI just using pure Bash? – frankiie May 06 '22 at 20:27
  • you may need `dialog`: https://linuxconfig.org/how-to-use-ncurses-widgets-in-shell-scripts-on-linux – user996142 May 06 '22 at 21:04
  • Your question is effectively "I want to do something complicated but I want to use a completely inappropriate language and I don't want to use any of the tools which might make it feasible". You should re-think your goals and/or your implementation plans. – cas May 07 '22 at 01:07

1 Answers1

0

No, you can't do a GUI in bash. You can do menu-based interactions though: get familiar with the select command.

Here's an example:

PS3='What do you want to do [1-4]> '
select choice in "Join" "Sign In" "Sign Out" "Exit"; do
    case $choice in 
        Join)
            join_command
            break ;;
        "Sign In")
            sign_in_command
            break ;;
        "Sign Out")
            sign_out_command
            break ;;
        Exit)
            echo "kthxbye"
            exit ;;
    esac
done

which looks like

1) Join
2) Sign In
3) Sign Out
4) Exit
What do you want to do [1-4]> 
glenn jackman
  • 84,176
  • 15
  • 116
  • 168