DabDaddy6223

cara_int_main

Aug 4th, 2026 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1. require "cara_generic_api"
  2. local ui = require "cara_ui"
  3. local screenManager = require "cara_screen_manager"
  4.  
  5. local screens = {
  6.     require("screens.startup_screen")
  7. }
  8.  
  9. function main()
  10.     for _, screen in ipairs(screens) do
  11.         screenManager.append(screen)
  12.     end
  13.  
  14.     while true do
  15.         local current = screenManager.current()
  16.         if current == nil then
  17.             break
  18.         end
  19.        
  20.         if ui.isDirty() then
  21.             ui.clear()
  22.             current.draw(ui)
  23.             ui.validate()
  24.         end
  25.  
  26.         local event = { os.pullEvent() }
  27.  
  28.         if event[1] == "key" then
  29.             local action = current.key(event[2])
  30.  
  31.             if action then
  32.                 if action.type == "quit" then
  33.                     break
  34.                 elseif action.type == "close" then
  35.                     os.shutdown()
  36.                 elseif action.type == "switch" then
  37.                     if action.screen == "next" then
  38.                         screenManager.next()
  39.                     elseif action.screen == "prev" then
  40.                         screenManager.prev()
  41.                     elseif type(action.screen) == "number" then
  42.                         screenManager.switchTo(action.screen)
  43.                     end
  44.                 end
  45.             end
  46.         end
  47.     end
  48.  
  49.     term.setBackgroundColor(colors.black)
  50.     term.setTextColor(colors.white)
  51.     term.clear()
  52.     term.setCursorPos(1, 1)
  53. end
  54.  
  55. main()
Advertisement
Add Comment
Please, Sign In to add comment