If anyone could test this for me or examine the code.
Instructions:
- put this API code into a folder called "sm".
- edit startup, and type os.loadAPI( "sm" )
- restart the computer
- then test the code in some way
sorry this code section is going to be BIG.
Here's the API
local w,h = term.getSize() function centerPrint( string, ypos ) term.setCursorPos( w/2 - #string/2, ypos ) -- half the width of the screen, minus half the langth of the string. term.write( string ) end function rightPrint( string, ypos ) term.setCursorPos( w - #string, ypos ) -- width of screen, minus the length of the string. term.write( string ) end function headPrint( string, boolean, ypos ) -- string is the title, boolean is whether you want a title or not, ypos is the position that the header line prints on. if boolean == true then sm.centerPrint( string, ypos - 1 ) sm.centerPrint(string.rep( "-", w), ypos ) else sm.centerPrint(string.rep( "-", w), ypos ) end end function footPrint( alignment, string ) -- alignment: user must enter "left", "centre" or "right". term.clearLine( h ) if alignment == "left" then term.setCursorPos( 1, h ) term.write( string ) elseif alignment == "centre" or "center" then sm.centerPrint( string, h ) elseif alignment == "right" then sm.rightPrint( string, h ) end end
the actual code:
--variables local select = 1 --Printing the Menus function printMain() sm.centerPrint( "Explorer", 5 ) sm.centerPrint( "games", 8 ) sm.centerPrint( "computer", 11 ) sm.centerPrint( "info", h - 2 ) local ypos = 6 local underline = "--------" if select == 2 then ypos = 9 underline = "-----" elseif select == 3 then ypos = 12 underline = "--------" elseif select == 4 then ypos = h - 1 underline = "----" end sm.centerPrint( underline, ypos ) end function printExplorer() sm.centerPrint( "My Documents", 5 ) sm.centerPrint( "My Programs", 8 ) sm.centerPrint( "Lua Command Shell", 11 ) sm.centerPrint( "Edit/New Program", 14 ) local ypos = 6 local underline = "------------" if select == 2 then ypos = 9 underline = "-----------" elseif select == 3 then ypos = 12 underline = "-----------------" elseif select == 4 then ypos = 15 underline = "----------------" end sm.centerPrint( underline, ypos ) end function printGames() sm.centerPrint( "Play Favourite", 5 ) sm.centerPrint( "My Games", 8 ) sm.centerPrint( "Gaming Setup", 11 ) local ypos = 6 local underline = "--------------" if select == 2 then ypos = 9 underline = "--------" elseif select == 3 then ypos = 12 underline = "------------" end sm.centerPrint( underline, ypos ) end function printCPU() sm.centerPrint( "Shutdown", 5 ) sm.centerPrint( "Reboot", 8 ) sm.centerPrint( "Settings", 11 ) sm.centerPrint( "Reset", 14 ) local ypos = 6 local underline = "--------" if select == 2 then ypos = 9 underline = "------" elseif select == 3 then ypos = 12 underline = "--------" elseif select == 4 then ypos = h - 1 underline = "-----" end sm.centerPrint( underline, ypos ) end function printHelp() sm.centerPrint( "Get Help!", 5 ) sm.centerPrint( "System Info", 8 ) sm.centerPrint( "API Documentation", 11 ) local ypos = 6 local underline "---------" if select == 2 then ypos = 9 underline = "-----------" elseif select == 3 then ypos = 12 underline = "-----------------" end sm.centerPrint( underline, ypos ) end function printGameSetup() sm.centerPrint( "", 5 ) sm.centerPrint( "", 8 ) sm.centerPrint( "", 11 ) local ypos = 6 local underline = "----------" if select == 2 then ypos = 9 underline = "------" elseif select == 3 then ypos = 12 underline = "-----" end sm.centerPrint( underline, ypos ) end function printSettings() sm.centerPrint( "Set Modem", 5 ) sm.centerPrint( "Set Disk Drive", 8 ) sm.centerPrint( "Other", 11 ) local ypos = 6 underline = "---------" if select == 2 then ypos = 9 underline = "--------------" elseif select == 3 then ypos = 12 underline = "-----" end sm.centerPrint( underline, ypos ) end function printReset() sm.centerPrint( "Info", 5 ) sm.centerPrint( "Do It!", 8 ) local ypos = 6 local underline = "----" if select == 2 then ypos = 9 underline = "------" end sm.centerPrint( underline, ypos ) end --menustate Table local menustate = "main" local mopt = { { ["main"] = { options = { "explorer", "games", "cpu", "help" } draw = printMain run = runMain } } { ["explorer"] = {options = { "my_docs", "my_programs", "lua", "edit" } draw = printExplorer run = runExplorer } } { ["games"] = {options = { "favourite", "my_games", "setup", } draw = printGames } } { ["cpu"] = {options = { "shutdown", "reboot", "settings", "reset"} draw = printCPU } } { ["help"] = {options = { "help", "system", "apis"} draw = printHelp } } { ["gaming_setup"] = {options = { "installing", "modems", "music" } draw = printGameSetup } } { ["settings"] {options = { "set_modem", "set_drive", "other" } draw = printSettings } } { ["reset"] {options = { "info", "do_it!" } draw = printReset } } } -- Running the menus up = 200 down = 208 enter = 28 function runMain() while true do term.clear() sm.headPrint( "SMIos: Main Menu", true, 2 ) sm.footPrint( "right", "by SMI -- Samdeman22") mopt[menustate].draw() mopt[menustate].run() local id, key = os.pullEvent( "key" ) -- UP = 200, DOWN = 208, ENTER = 28. if key == up and select > 1 then select = select - 1 elseif key == down and select < #mopt[menustate].options then select = select + 1 elseif key == enter then if mopt[menustate].options[select] == "explorer" then menustate = "explorer" elseif mopt[menustate].options[select] == "games" then menustate = "games" elseif mopt[menustate].options[select] == "cpu" then menustate = "cpu" elseif mopt[menustate].options[select] == "help" then menustate = "help" end end end end function runExplorer() while true do term.clear sm.headPrint( "SMIos: Explorer", true, 2 ) sm.footPrint( "right", "by SMI -- Samdeman22" ) mopt[menustate].draw() local id, key = os.pullEvent( "key" ) if key == up and select > 1 then select = select - 1 elseif key == down and select < #mopt[menustate].options then select = select + 1 elseif key == enter then if mopt[menustate].options[select] == "my_docs" then elseif mopt[menustate].options[select] == "my_programs" then elseif mopt[menustate].options[select] == "lua" then term.clear() sm.headPrint( "SMI: Lua", true, 2 ) term.setCursorPos( 1, 3 ) elseif mopt[menustate].options[select] == "edit" then term.clear() term.setCursorPos( 1, 1 ) print( "type the name of the program to edit, or create" ) print( "note: programs created are saved in sm/my_programs/" term.write( "edit " ) end end -- Actually running the program runMain()
the code isnt completed, I just wanted to know if what I am doing is right.
Hope that makes sense to someone.