1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Bar Menu

Discussion in 'T&T - Scripting' started by Joe Caverly, Mar 1, 2010.

  1. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    639
    Likes Received:
    7
    Here's a bar menu script that I wrote, and have been using for a while. It's not the most eloquent, but it does the job.

    Code:
    @echo off
    setlocal
    ::------------------------------------+
    :: Make sure FireFox is running       |
    ::------------------------------------+
    if not isapp "C:\Program Files\Mozilla Firefox\firefox.exe" start /pgm "C:\Program Files\Mozilla Firefox\firefox.exe"
    ::------------------------------------+
    :: Clean up the environment           |
    ::------------------------------------+
    unalias *
    unset *
    if %@arrayinfo[Menu,0] eq 1 unsetarray Menu
    ::------------------------------------+
    :: Create an array of Menu options    |
    ::------------------------------------+
    setarray Menu[7]
    set Menu[0]=1) National Post
    set Menu[1]=2) eBay
    set Menu[2]=3) St. Thomas Public Library
    set Menu[3]=4) Exeter Radar Environment Canada
    set Menu[4]=5) JPSoftware Forums
    set Menu[5]=6) Free Space On Drive C:
    set Menu[6]=7) Exit This Menu
    set MaxRow=%@eval[%@arrayinfo[Menu,1]-1]
    ::----------------------------------------------+
    :: Find the length of the longest menu item     |
    ::----------------------------------------------+
    set MaxLen=0
    do therow=0 to %MaxRow
      if %@len[%Menu[%therow]] gt %MaxLen set MaxLen=%@len[%Menu[%therow]]
    enddo
    ::------------------------------------+
    :: Draw a box for the Menu            |
    ::------------------------------------+
    cls
    drawbox 0 0 %@eval[%MaxRow+2] %@eval[%MaxLen+1] 1 bri whi on blu fill blu
    set currentrow=0
    ::------------------------------------+
    :: Draw the Menu                      |
    ::------------------------------------+
    gosub DrawMenu
    ::------------------------------------+
    :: Process user input                 |
    ::------------------------------------+
    do forever
      do forever
        screen %@eval[%MaxRow+3] 0
        inkey /P %%option
        :: @28 - Enter
        if %option eq @28 leave
        :: @80 - Down Arrow
        if %option eq @80 set currentrow=%@inc[%currentrow]
        :: @72 - Up Arrow
        if %option eq @72 set currentrow=%@dec[%currentrow]
        :: @79 - End
        if %option eq @79 set currentrow=%MaxRow
        :: @71 - Home
        if %option eq @71 set currentrow=0
        if %currentrow gt %MaxRow set currentrow=0
        if %currentrow lt 0 set currentrow=%MaxRow
        ::--------------------------------+
        :: Check for a number             |
        ::--------------------------------+
        iff %option gt 0 .and. %option lt %@eval[%MaxRow+2] then
          set currentrow=%@eval[%option-1]
          gosub DrawMenu
          leave
        endiff
        ::--------------------------------+
        :: Draw the Menu                  |
        ::--------------------------------+
        gosub DrawMenu
        ::--------------------------------+
        :: Go back and process user input |
        ::--------------------------------+
      enddo
      ::----------------------------------+
      :: A Menu option was selected       |
      :: Take the chosen route            |
      ::----------------------------------+
      set option=%@inc[%currentrow]
      if %option eq 1 gosub option1
      if %option eq 2 gosub option2
      if %option eq 3 gosub option3
      if %option eq 4 gosub option4
      if %option eq 5 gosub option5
      if %option eq 6 gosub option6
      if %option eq 7 leave
    enddo
    ::------------------------------------+
    :: Exit This Menu                     |
    ::------------------------------------+
    if %@arrayinfo[Menu,0] eq 1 unsetarray Menu
    endlocal
    ::------------------------------------+
    :: Return to command prompt           |
    ::------------------------------------+
    quit
    
    ::----------------------------------+
    :: Draw the Menu                    |
    ::----------------------------------+
    :DrawMenu
    do therow=0 to %MaxRow
      if %therow eq %currentrow scrput %@eval[%therow+1] 1 bri blu on whi %Menu[%therow]
      if %therow ne %currentrow scrput %@eval[%therow+1] 1 bri whi on blu %Menu[%therow]
    enddo
    return
    
    ::------------------------------------+
    :: Option 1                           |
    ::------------------------------------+
    :option1
      start /pgm http://www.nationalpost.com
    return
    
    ::------------------------------------+
    :: Option 2                           |
    ::------------------------------------+
    :option2
      start /pgm http://www.ebay.ca
    return
    
    ::------------------------------------+
    :: Option 3                           |
    ::------------------------------------+
    :option3
      start /pgm http://www.st-thomas.library.on.ca/
    return
    
    ::------------------------------------+
    :: Option 4                           |
    ::------------------------------------+
    :option4
      start /pgm http://www.weatheroffice.gc.ca/radar/index_e.html?id=WSO
    return
    
    ::------------------------------------+
    :: Option 5                           |
    ::------------------------------------+
    :option5
      start /pgm http://www.jpsoft.com/forums/index.php
    return
    
    ::------------------------------------+
    :: Option 6                           |
    ::------------------------------------+
    :option6
      free c:
    return
    
    This was written using TCC 11. I use mine mainly as a menu for web sites, but you can customize it as you wish for your system.

    Joe
     

Share This Page