WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: popask "NO" values differ in keyboard  (Read 5734 times)

Offline PDP-8

  • Hero Member
  • *****
  • Posts: 915
popask "NO" values differ in keyboard
« on: August 08, 2019, 04:51:45 AM »
TinyCorePure64 10.1 :

If you aren't using a mouse to click on yes / no, but instead are using the return key OR the space key to register a "NO", they return different values.  Use TAB to navigate to "no" button.

Example:

popask using the return/enter key to register a "yes" = 1

popask using the SPACE key to register a "yes" =1

Fine.

Use the TAB key to navigate to NO button.

popask using return/enter to register "no" = 1

popask using SPACE key to register "no" = 0

So, not a showstopper, BUT in the hands of the unskilled who might just actually use the space/return keys instead of a mouse, may result in unintended actions.
« Last Edit: August 08, 2019, 04:54:22 AM by PDP-8 »
That's a UNIX book! - cool  -- Garth

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11520
Re: popask "NO" values differ in keyboard
« Reply #1 on: August 08, 2019, 12:34:45 PM »
Hi PDP-8
It seems it's not a bug:
Quote
Description

Displays a printf-style message in a pop-up box with an "Yes" and "No" button and waits for the user to hit a button. The return value is 1
if the user hits Yes, 0 if they pick No or another dialog box is still open. The enter key is a shortcut for Yes and ESC is a shortcut for No.

Note: Common dialog boxes are application modal. No more than one common dialog box can be open at any time. Requests for
additional dialog boxes are ignored.
Found here:
https://www.fltk.org/documentation.php/doc-1.1/functions.html#fl_ask

Offline pek

  • Full Member
  • ***
  • Posts: 111
Re: popask "NO" values differ in keyboard
« Reply #2 on: September 23, 2021, 10:30:59 PM »
Hi guys,
How to catch the Yes No output?
I tried

I always get No - regardless I clicked yes or no

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11520
Re: popask "NO" values differ in keyboard
« Reply #3 on: September 23, 2021, 11:40:01 PM »
Hi pek
Check out  xmessage.  It's part of  Xorg-7.7-bin.tcz. Example:
Code: [Select]
tc@E310:~$ xmessage -buttons Yes:1,No:2,Maybe:3 -print  -center "Hello, World!"
Maybe
tc@E310:~$ echo $?
3
tc@E310:~$

This tells  xmessage  to create a popup with 3 buttons, Yes, No, and Maybe.
The numbers are the exit code you want for each button. The exit code can be found in  $?
The  -print  option tells it to print the name of the button selected.
The  -center  option tells it to place the popup in the center of the screen.

Just entering  xmessage  produces a help screen.

Offline pek

  • Full Member
  • ***
  • Posts: 111
Re: popask "NO" values differ in keyboard
« Reply #4 on: September 24, 2021, 12:14:11 AM »
Hi Rich..
Sorry I was asking about popask.
I don't have xorg, only xfbdev. So I don't have xmessage either.

Back to popask..
Code: [Select]
popask
clicked yes.. gives 1
and
Code: [Select]
popask
clicked no.. gives 0

How to catch that 1 or 0 so I can make and if loop?
Thanks.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11520
Re: popask "NO" values differ in keyboard
« Reply #5 on: September 24, 2021, 12:23:09 AM »
Hi pek
When you click a button, popask exits and returns an exit code. That exit code (0 or 1) will be in the  $?  variable.

This will display the value of the exit code:
Code: [Select]
echo $?
Test it like this for No:
Code: [Select]
if [ "$?" == 0 ]

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11520
Re: popask "NO" values differ in keyboard
« Reply #6 on: September 24, 2021, 12:31:05 AM »
Hi pek
Ignore the previous post. It seems  popask  doesn't use the exit code for this. Try this:
Code: [Select]
VAR="`popask "Your text."`"The value will be in  $VAR. Those are not single quotes, they are back ticks.

Offline pek

  • Full Member
  • ***
  • Posts: 111
Re: popask "NO" values differ in keyboard
« Reply #7 on: September 24, 2021, 12:38:05 AM »
Hi Rich..
Strangely no matter if  I clicked yes or no, it always give me 0 for $?.

when I click yes
Code: [Select]
$ popask
$ 1
$ echo $?
$ 0

when I click no
Code: [Select]
$ popask
$ 0
$ echo $?
$ 0

So, it actually spitted out 1 or 0 after clicking.. But the $? always gives 0, regardless.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11520
Re: popask "NO" values differ in keyboard
« Reply #8 on: September 24, 2021, 12:41:07 AM »
Hi pek
You missed the corrected answer I added.

Offline pek

  • Full Member
  • ***
  • Posts: 111
Re: popask "NO" values differ in keyboard
« Reply #9 on: September 24, 2021, 12:45:14 AM »
Yes, I missed this one.

Hi pek
Ignore the previous post. It seems  popask  doesn't use the exit code for this. Try this:
Code: [Select]
VAR="`popask "Your text."`"The value will be in  $VAR. Those are not single quotes, they are back ticks.

This works as intended.
Thank you very much Rich..  It's brilliant :) :)

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11520
Re: popask "NO" values differ in keyboard
« Reply #10 on: September 24, 2021, 12:49:27 AM »
Hi pek
You are welcome. Glad I could help.