Register
It is currently Mon Apr 23, 2018 6:49 pm

Bash dialog with Help Button & Help Text? [SOLVED]


All times are UTC - 6 hours


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 PostPosted: Sat Feb 10, 2018 2:29 am   

Joined: Mon Aug 21, 2017 12:15 am
Posts: 5
Location: Europe
Hi,

I study the Bash Dialog.
I want to understand how can one use the --help-button with the corresponding help text?
How to show the help text?
Eg., here is a nice tutorial script about --menu dialog, with help button:
https://bash.cyberciti.biz/guide/A_menu_box
but how to implement into it the following.
If the user hit the <HELP> button, then the corresponding Help text should be shown.
How can I achive this?

Best, Pal


Last edited by csanyipal on Fri Feb 16, 2018 12:26 am, edited 1 time in total.

Top
 Profile  
 PostPosted: Sat Feb 10, 2018 4:58 pm   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 574
Code:
echo 'help file content. Will appear on screen if F1 is pressed' > some-helpfile

dialog --help-button --hline 'press <F1> to read help'  --hfile some-helpfile --menu  'Choose something' 20 40 15  'tag entry one' 'item1' 'second tag entry' 'item2' 2> result_file

rc=$?
echo
echo rc is $rc
printf 'result_file content: '
cat result_file
echo

rm result_file
rm some-helpfile
Note: There are two complete helps. One shows just a text file.
The second just prefixes the output (i.e. the choosen tag) with the uppercase word 'HELP' and sets the exit status to 2.
React either to the output, or on retrun code 'rc'

Not all widgets provided by dialog know about the help button.


Top
 Profile  
 PostPosted: Sun Feb 11, 2018 12:14 am   

Joined: Mon Aug 21, 2017 12:15 am
Posts: 5
Location: Europe
uhelp wrote:
Code:
echo 'help file content. Will appear on screen if F1 is pressed' > some-helpfile

dialog --help-button --hline 'press <F1> to read help'  --hfile some-helpfile --menu  'Choose something' 20 40 15  'tag entry one' 'item1' 'second tag entry' 'item2' 2> result_file

rc=$?
echo
echo rc is $rc
printf 'result_file content: '
cat result_file
echo

rm result_file
rm some-helpfile
Note: There are two complete helps. One shows just a text file.
The second just prefixes the output (i.e. the choosen tag) with the uppercase word 'HELP' and sets the exit status to 2.
React either to the output, or on retrun code 'rc'

Not all widgets provided by dialog know about the help button.

Thank you very much!
But I still not understand why must the user press <F1> to read help text, because there is already the < Help > button?
The <F1> button can be used without the <Help> button by skipping the --help-button, like this:
Code:
#!/bin/bash
echo 'help file content. Will appear on screen if F1 is pressed' > some-helpfile

dialog --hline 'press <F1> to read help'  --hfile some-helpfile --menu  \
'Choose something' 20 40 15  'tag entry one' 'item1' 'second tag entry' 'item2' 2> result_file

rc=$?
echo
echo rc is $rc
printf 'result_file content: '
cat result_file
echo

rm result_file
rm some-helpfile

My question was: how to use that < Help > button for this purpose, namely, to can read the help text?
For me the < Help > button is there for that purpose, right?
If not, then what for is there the <Help> button?


Top
 Profile  
 PostPosted: Sun Feb 11, 2018 7:30 am   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 574
Quote:
Note: There are two complete helps. One shows just a text file.
The second just prefixes the output (i.e. the choosen tag) with the uppercase word 'HELP' and sets the exit status to 2.

Two different kind of help available.

Just as an educated guess of mine, i'd say that the F1 help was defined long ago by IBM's SAA (SystemApplicationArchitecture), which demands that help is available by pressing F1.
The F1 help facility of dialog can be considered beeing static. You display a (text) file and that's it.

The second way to offer help gives the ability to react on selected item allbeit not yet definitly choosen.
This help can by thus more specific than the F1 help (and doesn't need to be extensive).
Try the help button of given example with the two different items selected to see how this can help.


Top
 Profile  
 PostPosted: Sun Feb 11, 2018 9:00 am   

Joined: Mon Aug 21, 2017 12:15 am
Posts: 5
Location: Europe
uhelp wrote:
Quote:
Note: There are two complete helps. One shows just a text file.
The second just prefixes the output (i.e. the choosen tag) with the uppercase word 'HELP' and sets the exit status to 2.

Two different kind of help available.

Just as an educated guess of mine, i'd say that the F1 help was defined long ago by IBM's SAA (SystemApplicationArchitecture), which demands that help is available by pressing F1.
The F1 help facility of dialog can be considered beeing static. You display a (text) file and that's it.

The second way to offer help gives the ability to react on selected item allbeit not yet definitly choosen.
This help can by thus more specific than the F1 help (and doesn't need to be extensive).
Try the help button of given example with the two different items selected to see how this can help.

Indeed, when I press <Help> button when 'tag entry one item1' is selected, the dialog box exited and I get printed this on the shell:
rc is 2
result_file content: HELP tag entry one

So how can I use this output of dialog box to show a corresponding Help text and then to return to this menu dialog box?
An user want's to return to the menu after the Help text was read, right?
So how can show the Help message when the user press the <Help> button, and after reading it, how do I restore the menu?


Top
 Profile  
 PostPosted: Mon Feb 12, 2018 8:42 pm   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 574
A very common way to do this uses case command.
Code:
echo 'some help' > myhelp

while true; do
    # display the dialog
    dialog --help-button --hline 'press <F1> to read help'  --hfile zugang-sparkasse --menu  'Choose something' 20 40 15  'tag entry one' 'item1' 'second tag entry' 'item2' 2> result_file
   
    # save return code   
    rc=$?
   
    # check value
    case "$rc" in
        2  ) # we are in help case
             # do whatever needs to be done here
             echo we got return code: $rc
             echo this is the output of help command
             read # wait for any key pressed to see what's going on
             ;;
        0  ) # user has choosen somthing
             # just leave the loop
             echo we got return code: $rc
             printf "user has choosen: "
             cat result_file
             read # wait for any key pressed to see what's going on
             break
             ;;
        1  ) # user has choosen cancel
             # do whatever needs to be done if user cancels dialog
             echo "you don't want me something to do?"
             echo we got return code: $rc
             read # wait for any key pressed to see what's going on
             exit # we just stop the script
             ;;
        *  ) # all other return codes are somewhat strange
             # bail out and redo the dialog
             echo something strange happend
             echo we got return code: $rc
             echo redoing dialog
             echo very unlikely that you will ever see this
             read # wait for any key pressed to see what's going on
             ;;
    esac
done

echo
rm result_file
rm myhelp


Top
 Profile  
 PostPosted: Fri Feb 16, 2018 12:22 am   

Joined: Mon Aug 21, 2017 12:15 am
Posts: 5
Location: Europe
I practised a little, and I created this script:
Code:
#!/bin/bash
echo 'This is the Help text that displayed when <F1> pressed.' > F1helpText
echo 'This is the Help text for item1.\nIt is displayed when the <Help> button pressed while item1 selected.' > helptext_1
echo 'This is the Help text for item2.\nIt is displayed when the <Help> button pressed while item2 selected.' > helptext_2

while true; do
    # display the dialog
    dialog --help-button --hfile F1helpText \
    --menu  'Choose something' 20 40 15  'tag entry one' 'item1' 'second tag entry' 'item2' 'Quit' 'Quit' 2> result_file

    # Which button was pressed?
    # in case <OK> the value of $rc is 0
    # in case <Cancel> the value of $rc is 1
    # in case <Help> the value of $rc is 2
    rc=$?

    # The value of the $rc variable is examined.
    case "$rc" in
        2  ) # We are in help case when <Help> pressed.
             # Do whatever needs to be done here.
                case $(cat result_file) in
                    "HELP tag entry one" )
                       dialog --msgbox "`cat helptext_1`" 10 50
                       ;;
                    "HELP second tag entry" )
                       dialog --msgbox "`cat helptext_2`" 10 50
                       ;;
                esac
             ;;
        0  ) # The user selected the menu with the <OK> button.
             # We just leave the menu, but before we tell you what happened.
             dialog --msgbox "We got return code: `echo $rc`.\
             \nUser has choosen: `cat result_file`." 10 50
                 case $(cat result_file) in
                     "Quit" )
                     dialog --msgbox "Exit follows." 10 50
                     break
                     ;;
                 esac
             ;;
        1  ) # The user pressed the <Cancel> button.
             # Do whatever needs to be done here.
             dialog --msgbox "You don't want me something to do?\
             \nWe got return code: `echo $rc`.\
             \nUser has choosen: `cat result_file`.\
             \nExit follows." 10 50
             exit # We just stop the script.
             ;;
        *  ) # All other return codes are somewhat strange, eg. <Esc> pressed
             # Bail out and redo the dialog.
             echo "Something strange happend."
             echo "We got return code:" $rc
             echo "Redoing dialog."
             echo -e "\nPress Enter!"
             read # Wait for any key pressed to see what's going on.
             ;;
    esac
done

rm F1helpText
rm result_file
rm helptext_1
rm helptext_2


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 25 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP