Hi to all, first post.
I've trying for a long time to build browse-able menu batch files like those old DOS utilities you may remember.
I've been around this site for a long time, for I'd not written batch since ages ago, to remember and to learn from all the wonderful stuff you share here.
Thank you all of you for what I've discovered here.
You can see some screenshots at
https://drive.google.com/open?id=0B6xXr ... Uk5endoWU0
https://drive.google.com/open?id=0B6xXr ... EU3ZjVNcUE
https://drive.google.com/open?id=0B6xXrI7w48EOUGNZY0lPbW5nR3M
Well, no more literature, here is the script:
Mod edit:
Hello elzooilogico, it's nice to see a dedicated batch scripter.
Because this is your first post and the script is so complex, the script itself has been shifted to online storage.
Your description of the script and it's aims and operation is terse - and this is to add an alert and an extra layer of effort, so that new users are less likely to try unknown code.
If other forum users would like to evaluate the code then it can be downloaded here: https://www.dropbox.com/s/0vgwsind6jwoy ... t.txt?dl=0
Browsable menu batch template (using utilities)
Moderator: DosItHelp
-
- Posts: 128
- Joined: 23 May 2016 15:39
- Location: Spain
-
- Posts: 128
- Joined: 23 May 2016 15:39
- Location: Spain
Re: Browsable menu batch template (using utilities)
Hi again,
Thanks for your kind welcome, and for pointing me what is obvious. Also I think you have corrected the typo of the title from brwoseable to browsable, thanks again.
First of all, I'm very grateful to DosTips users for all I've learned from their contributions, they have made this feasible.
Yes, it's a long script and maybe complex, for there are many vars, substitutions and checkings.
I know there is not information on what the script does. I've removed all the descriptions to make it fit, due to the 60000 chars limit for new posts.
In the full version of the script, each function have comments to explain (as far as I think) what is going on.
download full script ansimenu.zip from https://drive.google.com/open?id=0B6xXr ... mxtek1mV0E
Now, I'll try to explain briefly.
The script is a template. It provides the ability to create a menu browsable with arrow keys and/or mouse input with just one line of code.
There are indeed many helper functions, but to create a menu only function call is needed.
The function createMenu does the job.
createMenu return_variable, columns, wait_lapse, option_list, header, exit_text, preselected_default_item, additional_function_call
For example:
Will create a menu with a cell for every item in 'item 1...item n' list, with four columns per row, with a header line 'header text', and two additional function showing 'Who am I'. The first may be processed by checking ERRORLEVEL, and the second by a function call (processed in the menu loop). The menu will wait 180 seconds for user input. If time elapses, it will return to caller (parent menu, command processor...)
All menu creation details, input parsing, view updating is performed behind the user.
Hope it helps.
BTW, I'm not a dedicated batch scripter. But I must admit I have been working on it for a long time (as an acid test, is correct?)
Thanks for your kind welcome, and for pointing me what is obvious. Also I think you have corrected the typo of the title from brwoseable to browsable, thanks again.
Mod(erator I guess) saidYour description of the script and it's aims and operation is terse - and this is to add an alert and an extra layer of effort, so that new users are less likely to try unknown code.
First of all, I'm very grateful to DosTips users for all I've learned from their contributions, they have made this feasible.
Yes, it's a long script and maybe complex, for there are many vars, substitutions and checkings.
I know there is not information on what the script does. I've removed all the descriptions to make it fit, due to the 60000 chars limit for new posts.
In the full version of the script, each function have comments to explain (as far as I think) what is going on.
download full script ansimenu.zip from https://drive.google.com/open?id=0B6xXr ... mxtek1mV0E
Now, I'll try to explain briefly.
The script is a template. It provides the ability to create a menu browsable with arrow keys and/or mouse input with just one line of code.
There are indeed many helper functions, but to create a menu only function call is needed.
The function createMenu does the job.
createMenu return_variable, columns, wait_lapse, option_list, header, exit_text, preselected_default_item, additional_function_call
For example:
Code: Select all
:main
title %~nx0
SetLocal EnableDelayedExpansion
call:createMenu selection, 4, 180, "item 1,item 2, item3, ..., item n", "Header Text", "Exit", "", "Who am I:0,Who am I (2):showMe"
:: Note %ERRORLEVEL% is used to keep its value inside block
if %ERRORLEVEL% EQU 0 ( rem ESC key, exit
echo/ * Bye...
EndLocal
exit/B 0
) else if %ERRORLEVEL% EQU 9002 ( rem F2 key
cls
echo/ * I am element: %selection%
set/p newItem=" * Hit enter to continue " <CON
goto:mainMenu
)
::other %ERRORLEVEL% must be a selection, so perform task on it
call:doSomething %selection%
goto:mainMenu
:: F3 key
:showMe
cls
echo/ * I am element: %selection%
set/p newItem=" * Hit enter to continue " <CON
exit/B 0
Will create a menu with a cell for every item in 'item 1...item n' list, with four columns per row, with a header line 'header text', and two additional function showing 'Who am I'. The first may be processed by checking ERRORLEVEL, and the second by a function call (processed in the menu loop). The menu will wait 180 seconds for user input. If time elapses, it will return to caller (parent menu, command processor...)
All menu creation details, input parsing, view updating is performed behind the user.
createMenu return_variable, columns, wait_lapse, option_list, header, exit_text, preselected_default_item, additional_function_call
menu constructor with multiple columns, paging, default item selection ability to append auxiliary function callsparameters:
return_variable
a variable where selected item will be returned as text
columns
desired column number (1-8) or ("" or 0) for auto-compute
if column number is set, the given number will be created. Items excceding column width will be truncated.
when not set, an automatic computing will be done, first taking into account item number, and then item length. column number will be decreased until the longest item fits in it.
wait_time
in seconds. If no selection is done whitin wait time suggested batch control will return to caller (function, menu or command processor)
option_list
item list to build the menu
header
text to show as menu header
exit_text
text to show along? the exit key
preselected_default
desired item to be selected by default at menu startup. If it is not set the first item will be selected
additional_function
you may include additional funtion calls or new menus that will be treated in a special way
you may specify additional function calls defining pairs divided by `:´ and splitted up by ","
each pair must include text to show and funtion to be called. if you set `0´ as calle function, menu will return to caller (function or menu) with a return value (9000 + function offset), 9004 in the example
i.e "Add:AddRecord,Edit:EditRecord,Delete:DeleteRecord,More:0"
return values:
when SELECT key is pressed (ENTER by default), two values are returned
in ERRORLEVEL environment variable : selected item as offset
in return_variable (1st argument) : selected item as text
when EXIT key is pressed (ESC by default)
in ERRORLEVEL environment variable : 0
if there are additional functions set (8th argument)
in ERRORLEVEL environment variable : 9000 + function offset
in return_variable (1st argument) : selected item as text
Hope it helps.
BTW, I'm not a dedicated batch scripter. But I must admit I have been working on it for a long time (as an acid test, is correct?)