Advertisement
T3RRYT3RR0R

Batch User Interface Guide

Dec 11th, 2019
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 13.82 KB | None | 0 0
  1. ::: Disable Command line commands from diplaying
  2.  
  3. @ECHO OFF
  4.  
  5. ::: Define Size of the Console Window
  6.  
  7. Mode Con: cols=125 lines=25
  8.  
  9. ::: Select Name of the Command Window
  10.  
  11. TITLE Introduction to Batch User Interfaces.
  12.  
  13. :intro
  14.  
  15. ::: Define Variable Names For Page text
  16.  
  17. Call :nullsentences
  18.  
  19. ::: Establishes handling of page selection
  20.  
  21.     Set returnpage=intro
  22.     Set targetpage=setup
  23.  
  24. ::: Assigns text to the User Interface Screen Header.
  25.  
  26.     Set headertext=Introduction to Batch User Interface and Choice Command
  27.  
  28. ::: Assigns text to the screens textfield
  29.  
  30.     Set Sentence1=Welcome to my Advanced batch Interface Tutorial.
  31.     Set Sentence2=We'll be covering everything needed to be able to reproduce
  32.     Set Sentence3=the format of this batch file.
  33.     Set Sentence4=All the commands used to achieve this style of user interface
  34.     Set Sentence5=are simple to master, however provide a much better user
  35.     Set Sentence6=experience than typical batch inteface menus.
  36.     Set sentence7=All commands will appear in Yellow
  37.     Set sentence8=                                                         Let's take a look...
  38.  
  39. GOTO pagenext
  40.  
  41. :setup
  42.  
  43.     Set returnpage=intro
  44.     Set targetpage=bldscr1
  45.  
  46. Call :nullsentences
  47.  
  48.     Set headertext=Setting up your Script.
  49.  
  50.     Set Sentence1=The First line of your script will be:
  51.     Set Sentence2=^@ECHO OFF
  52.     Set Sentence3=The next command you have a bit of freedom with, as it depends on what size you
  53.     Set Sentence4=want your console to display at. "cols" defines how wide, "lines" defines how high.
  54.     Set Sentence5=Mode con: cols=125 lines=25
  55.     Set Sentence6=Next up, it's time to choose a title for your program.
  56.     Set Sentence7=TITLE Introduction to Batch User Interfaces.
  57.     Set Sentence8=Now that we've set up the basic properties of our console, Let's build our display...
  58.  
  59. GOTO pageboth
  60.  
  61. :bldscr1
  62.  
  63.     Set returnpage=setup
  64.     Set targetpage=bldscr2
  65.  
  66. Call :nullsentences
  67.  
  68.     Set headertext=Creating your Screen Template
  69.  
  70.     Set sentence1=To save alot of time and effort, Create a template for the screens display that allows you to
  71.     Set sentence2=easily change the information presented to the user by changing a few variables then calling the screen.
  72.     Set sentence3=It's up to you to choose what sort of border you wish to place around your text field and what variable names you
  73.     Set sentence4=wish to use to diplay the text. To make life easier, Variables with descriptive names are best.
  74.     Set sentence5=Your screen should be called from each page that wishes to use it. To call a label, use the following
  75.     Set sentence6=CALL :screen
  76.     Set sentence7=Substitute screen for the label name you wish to use / call.
  77.     Set sentence8=Next up, we'll look at the screen template for this program.
  78.  
  79. GOTO pageboth
  80.  
  81. :::
  82.  
  83. :bldscr2
  84.  
  85.     Set returnpage=bldscr1
  86.     Set targetpage=bldscr3
  87.  
  88. Call :nullsentences
  89.  
  90.     Set sentence1=:screen The label name for this programs Screen template
  91.     Set sentence2=cls Clears the Console screen
  92.     Set sentence3=color 02 Sets the default Color of the background and text
  93.     Set sentence4=IF ^%%avprev^%%==0 Set prev=*ESC[90m(P)revious*ESC[32m The variables ^%%avprev^%%/^%%avnext^%% Display current navigation options.
  94.     Set sentence5=IF ^%%avprev^%%==1 Set prev=*ESC[35m(P)revious*ESC[32m
  95.     Set sentence6=IF ^%%avnext^%%==0 Set next=*ESC[90m(N)ext*ESC[32m
  96.     Set sentence7=IF ^%%avnext^%%==1 Set next=*ESC[35m(N)ext*ESC[32m
  97.     Set sentence8=*ESC is to be substituted for the ANSI escape symbol. Continued...
  98.  
  99. GOTO pageboth
  100.  
  101. :bldscr3
  102.  
  103.     Set returnpage=bldscr2
  104.     Set targetpage=bldscr4
  105.  
  106. Call :nullsentences
  107.  
  108.     Set headertext=Creating your Screen Template
  109.  
  110.     Set sentence1=Adjust the border for your header to the style you desire.
  111.     Set sentence2=^ECHO ====================================================================================================================
  112.     Set sentence3=^ECHO ^%%header^%%*ESC[32m Displays the text stored to the Variable header
  113.     Set sentence4=^ECHO ====================================================================================================================
  114.     Set sentence5=
  115.     Set sentence6=
  116.     Set sentence7=
  117.     Set sentence8=Continued...
  118.  
  119. GOTO pageboth
  120.  
  121. :bldscr4
  122.  
  123.     Set returnpage=bldscr3
  124.     Set targetpage=bldscr5
  125.  
  126. Call :nullsentences
  127.  
  128.     Set sentence1=Space out (our group) your sentences as you wish.
  129.     Set sentence2=^ECHO = ^%%sentence1^%% Displays the text stored to the Variable Sentence1
  130.     Set sentence3=^ECHO =
  131.     Set sentence4=^ECHO = ^%%sentence2^%%
  132.     Set sentence5=^ECHO =
  133.     Set sentence6=^ECHO = ^%%sentence3^%%
  134.     Set sentence7=This Tutorial uses 8 sentences with spaces to keep information clearly divided.
  135.     Set sentence8=
  136.  
  137. GOTO pageboth
  138.  
  139. :bldscr5
  140.  
  141.     Set returnpage=bldscr4
  142.     Set targetpage=prptmp1
  143.  
  144. Call :nullsentences
  145.  
  146.     Set sentence1=Display the navigation options Available to the user, and return to the place in the program
  147.     Set sentence2=from which you called your screen.
  148.     Set sentence3=^ECHO ====================================================================================================================
  149.     Set sentence4=^ECHO  ^%%prev^%%                                                                                                 ^%%next^%%
  150.     Set sentence5=^ECHO ====================================================================================================================
  151.     Set sentence6=^GOTO :EOF
  152.     Set sentence7=If you have other options for the user to take, You can easily Incorperate them into your Header Variable.
  153.     Set sentence8=In labels that offer additional options, use: Set header=Option (1) Option (2) Option (3)  etc...
  154.  
  155. GOTO pageboth
  156.  
  157. :prptmp1
  158.  
  159.     Set returnpage=bldscr5
  160.     Set targetpage=prptmp2
  161.     Set headertext=Preparing to use your template.
  162.  
  163. Call :nullsentences
  164.  
  165.     Set sentence1=Chances are, your not going to fill every sentence on every screen your program uses.
  166.     Set sentence2=Because of this, you need to clear the variables before getting ready to call your screen.
  167.     Set sentence3=To do this. create another function to call from pages that call your screen.
  168.     Set sentence4= :nullsentences
  169.     Set sentence5= Set Sentence1=
  170.     Set sentence6= Set Sentence2= Repeat this for the number of sentences your screen uses.
  171.     Set sentence7= Set Sentence8= You can also copy the Setting component of this function when you're preparing sentences.
  172.     Set sentence8= GOTO :EOF
  173.  
  174. GOTO pageboth
  175.  
  176. :prptmp2
  177.  
  178.     Set returnpage=prptmp1
  179.     Set targetpage=explainchoice
  180.     Set headertext=Putting the template to use.
  181.  
  182. Call :nullsentences
  183.  
  184.     Set sentence1=Prior to Setting your Sentence Variables, you want to refresh them.
  185.     Set sentence2=Call :nullsentences
  186.     Set sentence3=Now Set your Sentences.
  187.     Set sentence4=Set sentence1=*ESC[36mPrior to Setting your *ESC[37mSentence*ESC[36m Variables, you want to refresh them.*ESC[32m
  188.     Set sentence5=Set sentence2=*ESC[33mCall :nullsentences*ESC[32m
  189.     Set sentence6=Set sentence3=*ESC[36mNow Set your Sentences.*ESC[32m
  190.     Set sentence7=Next up, I'll be explaining CHOICE Selection and Basic Navigation for your Interface
  191.     Set sentence8=
  192.  
  193. GOTO pageboth
  194.  
  195. :explainchoice
  196.  
  197.     Set returnpage=prptmp2
  198.     Set targetpage=optionselect
  199.     Set headertext=CHOICE and Navigation
  200.  
  201. Call :nullsentences
  202.  
  203.     Set sentence1=The CHOICE command is what allows your user to interact with the user Interface.
  204.     Set sentence2=For paging through labels, as this program has so far, assigning label names to variables
  205.     Set sentence3=is the way to go. In each 'page', prior to the choice command:
  206.     Set sentence4=^Set targetpage=nextpagelabelname
  207.     Set sentence5=^Set returnpage=lastpagelabelname
  208.     Set sentence6=^CHOICE /N /C:pn /M ""^%%1
  209.     Set sentence7=IF ERRORLEVEL ==2 GOTO ^%%targetpage^%%
  210.     Set sentence8=IF ERRORLEVEL ==1 GOTO ^%%returnpage^%%
  211.  
  212. GOTO pageboth
  213.  
  214. :optionselect
  215.  
  216.     Set returnpage=explainchoice
  217.     Set targetpage=usetmplte
  218.     Set headertext=^CHOICE and Navigation
  219.  
  220. Call :nullsentences
  221.  
  222.     Set sentence1=For multi Directional paging, this program uses the following function
  223.     Set sentence2=^:pageboth
  224.     Set sentence3=^Set avnext=1
  225.     Set sentence4=^set avprev=1
  226.     Set sentence5=^Call :screen
  227.     Set sentence6=^CHOICE /N /C:pn /M ""^%%1
  228.     Set sentence7=^IF ERRORLEVEL ==2 GOTO ^%%targetpage^%%
  229.     Set sentence8=^IF ERRORLEVEL ==1 GOTO ^%%returnpage^%%
  230.  
  231. GOTO pageboth
  232.  
  233. :usetmplte
  234.  
  235.     Set returnpage=optionselect
  236.     Set targetpage=wrapup
  237.     Set headertext=Putting it all together.
  238.     Set avnext=1
  239.     set avprev=1
  240.  
  241. cls
  242. IF %avprev%==0 Set prev=(P)revious
  243. IF %avprev%==1 Set prev=(P)revious
  244. IF %avnext%==0 Set next=(N)ext
  245. IF %avnext%==1 Set next=(N)ext
  246. ECHO ============================================================================================================================
  247. ECHO = %headertext%
  248. ECHO ============================================================================================================================
  249. ECHO =
  250. ECHO = Using the screen template becomes as simple as Copying code and changing the value of the variables and label names:
  251. ECHO =
  252. ECHO = :nameofcurrentlabel
  253. ECHO = Call :nullsentences
  254. ECHO = Set Sentence1= blah blah
  255. ECHO = Set Sentence2= blah blah
  256. ECHO = Set Sentence3= blah blah
  257. ECHO = Set Sentence4= blah blah
  258. ECHO = Set Sentence5= blah blah
  259. ECHO = Set Sentence6= blah blah
  260. ECHO = Set Sentence7= blah blah
  261. ECHO = Set Sentence8= blah blah
  262. ECHO = Set returnpage=nameofpreviouslabel
  263. ECHO = Set targetpage=nameofnextlabel
  264. ECHO = Set headertext=Desired Header Text
  265. ECHO = GOTO pageboth Or Call :screen followed by other choices as required.
  266. ECHO ============================================================================================================================
  267. ECHO = %prev%                                                                                                         %next%
  268. ECHO ============================================================================================================================
  269. CHOICE /T 5 /C pn /N /D n >nul
  270. IF ERRORLEVEL ==2 GOTO %targetpage%
  271. IF ERRORLEVEL ==1 GOTO %returnpage%
  272.  
  273. :wrapup
  274.  
  275.     Set returnpage=usetmplte
  276.     Set targetpage=wrapup
  277.     Set headertext=The TakeAway.
  278.  
  279. Call :nullsentences
  280.  
  281.     Set sentence1=As you will have learned by now, with just a few commands, a very simple yet informative User Interface
  282.     Set sentence2=can be made for batch files.
  283.     Set sentence3=A little bit of formatting to display information clearly
  284.     Set sentence4=A touch of Color to highlight important information or show availble options
  285.     Set sentence5=Is all it takes to make batch programs a more enjoyable experience.
  286.     Set sentence6=
  287.     Set sentence7=For a copy of this program, Visit: https://pastebin.com/jbXyaPwN
  288.     Set sentence8=
  289.  
  290. GOTO prevpage
  291.  
  292. :::
  293.  
  294. :nullsentences
  295.  
  296.     Set sentence1=
  297.     Set sentence2=
  298.     Set sentence3=
  299.     Set sentence4=
  300.     Set sentence5=
  301.     Set sentence6=
  302.     Set sentence7=
  303.     Set sentence8=
  304. GOTO :EOF
  305.  
  306. :pagenext
  307.  
  308.     Set avnext=1
  309.     set avprev=0
  310. Call :screen
  311. CHOICE /T 5 /C pn /N /D n >nul
  312. IF ERRORLEVEL ==2 GOTO %targetpage%
  313. IF ERRORLEVEL ==1 GOTO %returnpage%
  314.  
  315. :pageboth
  316.     Set avnext=1
  317.     set avprev=1
  318. Call :screen
  319. CHOICE /T 5 /C pn /N /D n >nul
  320. IF ERRORLEVEL ==2 GOTO %targetpage%
  321. IF ERRORLEVEL ==1 GOTO %returnpage%
  322.  
  323. :prevpage
  324.     Set avnext=0
  325.     set avprev=1
  326. Call :screen
  327. CHOICE /T 5 /C pn /N /D n >nul
  328. IF ERRORLEVEL ==2 GOTO %targetpage%
  329. IF ERRORLEVEL ==1 GOTO %returnpage%
  330.  
  331. :screen
  332. cls
  333. color 02
  334. IF %avprev%==0 Set prev=(P)revious
  335. IF %avprev%==1 Set prev=(P)revious
  336. IF %avnext%==0 Set next=(N)ext
  337. IF %avnext%==1 Set next=(N)ext
  338. ECHO ============================================================================================================================
  339. ECHO = %headertext%
  340. ECHO ============================================================================================================================
  341. ECHO =
  342. ECHO = %sentence1%
  343. ECHO =
  344. ECHO = %sentence2%
  345. ECHO =
  346. ECHO = %sentence3%
  347. ECHO =
  348. ECHO = %sentence4%
  349. ECHO =
  350. ECHO = %sentence5%
  351. ECHO =
  352. ECHO = %sentence6%
  353. ECHO =
  354. ECHO = %sentence7%
  355. ECHO =
  356. ECHO = %sentence8%
  357. ECHO =
  358. ECHO ============================================================================================================================
  359. ECHO = %prev%                                                                                                         %next%
  360. ECHO ============================================================================================================================
  361. GOTO :EOF
  362.  
  363.  
  364. :::
  365.  
  366. :end
  367. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement