Laon09

test ui

Aug 3rd, 2025 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.82 KB | Source Code | 0 0
  1. -- Basalt UI Framework Test Program
  2. -- Run this in ComputerCraft with Basalt installed
  3.  
  4. local basalt = require("basalt")
  5.  
  6. -- Create main frame
  7. local main = basalt.createFrame()
  8.     :setBackground(colors.black)
  9.     :setSize("parent.w", "parent.h")
  10.  
  11. -- Title bar
  12. local titleBar = main:addFrame()
  13.     :setPosition(1, 1)
  14.     :setSize("parent.w", 3)
  15.     :setBackground(colors.blue)
  16.  
  17. local title = titleBar:addLabel()
  18.     :setText("Basalt UI Test Dashboard")
  19.     :setPosition(2, 2)
  20.     :setForeground(colors.white)
  21.  
  22. -- System info panel
  23. local sysPanel = main:addFrame()
  24.     :setPosition(2, 5)
  25.     :setSize(25, 12)
  26.     :setBackground(colors.gray)
  27.  
  28. local sysTitle = sysPanel:addLabel()
  29.     :setText("System Info")
  30.     :setPosition(2, 1)
  31.     :setForeground(colors.white)
  32.  
  33. local cpuLabel = sysPanel:addLabel()
  34.     :setText("CPU: 45%")
  35.     :setPosition(2, 3)
  36.     :setForeground(colors.lime)
  37.  
  38. local memLabel = sysPanel:addLabel()
  39.     :setText("Memory: 128MB")
  40.     :setPosition(2, 4)
  41.     :setForeground(colors.cyan)
  42.  
  43. local diskLabel = sysPanel:addLabel()
  44.     :setText("Disk: 2.4GB")
  45.     :setPosition(2, 5)
  46.     :setForeground(colors.yellow)
  47.  
  48. -- CPU usage bar using labels
  49. local cpuBarBg = sysPanel:addLabel()
  50.     :setText("                    ")
  51.     :setPosition(2, 7)
  52.     :setBackground(colors.red)
  53.  
  54. local cpuBarFg = sysPanel:addLabel()
  55.     :setText("         ")
  56.     :setPosition(2, 7)
  57.     :setBackground(colors.lime)
  58.  
  59. -- Control panel
  60. local controlPanel = main:addFrame()
  61.     :setPosition(29, 5)
  62.     :setSize(25, 15)
  63.     :setBackground(colors.gray)
  64.  
  65. local controlTitle = controlPanel:addLabel()
  66.     :setText("Controls")
  67.     :setPosition(2, 1)
  68.     :setForeground(colors.white)
  69.  
  70. -- Buttons
  71. local startBtn = controlPanel:addButton()
  72.     :setText("Start Process")
  73.     :setPosition(2, 3)
  74.     :setSize(20, 3)
  75.     :setBackground(colors.green)
  76.     :setForeground(colors.white)
  77.  
  78. local stopBtn = controlPanel:addButton()
  79.     :setText("Stop Process")
  80.     :setPosition(2, 7)
  81.     :setSize(20, 3)
  82.     :setBackground(colors.red)
  83.     :setForeground(colors.white)
  84.  
  85. local configBtn = controlPanel:addButton()
  86.     :setText("Configuration")
  87.     :setPosition(2, 11)
  88.     :setSize(20, 3)
  89.     :setBackground(colors.orange)
  90.     :setForeground(colors.white)
  91.  
  92. -- Log panel
  93. local logPanel = main:addFrame()
  94.     :setPosition(2, 18)
  95.     :setSize(52, 8)
  96.     :setBackground(colors.black)
  97.  
  98. local logTitle = logPanel:addLabel()
  99.     :setText("Activity Log")
  100.     :setPosition(2, 1)
  101.     :setForeground(colors.white)
  102.  
  103. -- Log entries using labels instead of list
  104. local logLine1 = logPanel:addLabel()
  105.     :setText("System initialized")
  106.     :setPosition(2, 3)
  107.     :setForeground(colors.lime)
  108.  
  109. local logLine2 = logPanel:addLabel()
  110.     :setText("Basalt UI loaded successfully")
  111.     :setPosition(2, 4)
  112.     :setForeground(colors.cyan)
  113.  
  114. local logLine3 = logPanel:addLabel()
  115.     :setText("Waiting for user input...")
  116.     :setPosition(2, 5)
  117.     :setForeground(colors.yellow)
  118.  
  119. local logLine4 = logPanel:addLabel()
  120.     :setText("")
  121.     :setPosition(2, 6)
  122.     :setForeground(colors.white)
  123.  
  124. -- Input field
  125. local inputFrame = main:addFrame()
  126.     :setPosition(2, 27)
  127.     :setSize(52, 4)
  128.     :setBackground(colors.gray)
  129.  
  130. local inputLabel = inputFrame:addLabel()
  131.     :setText("Command:")
  132.     :setPosition(2, 2)
  133.     :setForeground(colors.white)
  134.  
  135. local inputField = inputFrame:addInput()
  136.     :setPosition(12, 2)
  137.     :setSize(30, 1)
  138.     :setBackground(colors.white)
  139.     :setForeground(colors.black)
  140.  
  141. local executeBtn = inputFrame:addButton()
  142.     :setText("Execute")
  143.     :setPosition(44, 2)
  144.     :setSize(8, 1)
  145.     :setBackground(colors.blue)
  146.     :setForeground(colors.white)
  147.  
  148. -- Status indicators
  149. local statusFrame = main:addFrame()
  150.     :setPosition(56, 5)
  151.     :setSize(15, 12)
  152.     :setBackground(colors.lightGray)
  153.  
  154. local statusTitle = statusFrame:addLabel()
  155.     :setText("Status")
  156.     :setPosition(2, 1)
  157.     :setForeground(colors.black)
  158.  
  159. local powerLED = statusFrame:addLabel()
  160.     :setText("● Power")
  161.     :setPosition(2, 3)
  162.     :setForeground(colors.lime)
  163.  
  164. local networkLED = statusFrame:addLabel()
  165.     :setText("● Network")
  166.     :setPosition(2, 4)
  167.     :setForeground(colors.blue)
  168.  
  169. local diskLED = statusFrame:addLabel()
  170.     :setText("● Disk")
  171.     :setPosition(2, 5)
  172.     :setForeground(colors.yellow)
  173.  
  174. local uptimeLabel = statusFrame:addLabel()
  175.     :setText("Uptime: 0h")
  176.     :setPosition(2, 7)
  177.     :setForeground(colors.black)
  178.  
  179. -- Variables for system simulation
  180. local currentCpuUsage = 45
  181. local logCount = 3
  182. local startTime = os.clock()
  183.  
  184. -- Function to update CPU bar
  185. local function updateCpuBar(percentage)
  186.     local barLength = math.floor(percentage / 5)
  187.     local barText = string.rep(" ", barLength)
  188.     cpuBarFg:setText(barText)
  189. end
  190.  
  191. -- Event handlers
  192. startBtn:onClick(function()
  193.     logCount = logCount + 1
  194.     if logCount == 4 then
  195.         logLine4:setText("Process started at " .. os.date("%H:%M:%S"))
  196.             :setForeground(colors.lime)
  197.     else
  198.         logLine1:setText("Process started at " .. os.date("%H:%M:%S"))
  199.             :setForeground(colors.lime)
  200.         logLine2:setText("System running optimally")
  201.             :setForeground(colors.cyan)
  202.         logLine3:setText("All systems green")
  203.             :setForeground(colors.lime)
  204.         logLine4:setText("Ready for commands")
  205.             :setForeground(colors.white)
  206.     end
  207.    
  208.     currentCpuUsage = math.random(60, 90)
  209.     cpuLabel:setText("CPU: " .. currentCpuUsage .. "%")
  210.     updateCpuBar(currentCpuUsage)
  211. end)
  212.  
  213. stopBtn:onClick(function()
  214.     logLine1:setText("Process stopped at " .. os.date("%H:%M:%S"))
  215.         :setForeground(colors.red)
  216.     logLine2:setText("System idle")
  217.         :setForeground(colors.orange)
  218.     logLine3:setText("Waiting for new task")
  219.         :setForeground(colors.yellow)
  220.     logLine4:setText("")
  221.         :setForeground(colors.white)
  222.    
  223.     currentCpuUsage = math.random(10, 30)
  224.     cpuLabel:setText("CPU: " .. currentCpuUsage .. "%")
  225.     updateCpuBar(currentCpuUsage)
  226. end)
  227.  
  228. configBtn:onClick(function()
  229.     logLine1:setText("Configuration panel opened")
  230.         :setForeground(colors.orange)
  231.     logLine2:setText("Settings loaded")
  232.         :setForeground(colors.cyan)
  233.     logLine3:setText("Ready to configure")
  234.         :setForeground(colors.white)
  235.     logLine4:setText("")
  236. end)
  237.  
  238. executeBtn:onClick(function()
  239.     local command = inputField:getValue()
  240.     if command ~= "" then
  241.         logLine1:setText("> " .. command)
  242.             :setForeground(colors.cyan)
  243.         logLine2:setText("Command executed successfully")
  244.             :setForeground(colors.lime)
  245.         logLine3:setText("Return code: 0")
  246.             :setForeground(colors.white)
  247.         logLine4:setText("Ready for next command")
  248.             :setForeground(colors.yellow)
  249.         inputField:setValue("")
  250.     end
  251. end)
  252.  
  253. -- Real-time system update
  254. local function updateSystem()
  255.     while true do
  256.         sleep(3)
  257.        
  258.         -- Update CPU usage
  259.         currentCpuUsage = math.max(20, math.min(95, currentCpuUsage + math.random(-15, 15)))
  260.         cpuLabel:setText("CPU: " .. currentCpuUsage .. "%")
  261.         updateCpuBar(currentCpuUsage)
  262.        
  263.         -- Update memory
  264.         local memUsed = math.random(64, 256)
  265.         memLabel:setText("Memory: " .. memUsed .. "MB")
  266.        
  267.         -- Update uptime
  268.         local uptime = math.floor((os.clock() - startTime) / 3600)
  269.         uptimeLabel:setText("Uptime: " .. uptime .. "h")
  270.        
  271.         -- Blink network LED
  272.         if math.random() > 0.5 then
  273.             networkLED:setForeground(colors.lightBlue)
  274.         else
  275.             networkLED:setForeground(colors.blue)
  276.         end
  277.     end
  278. end
  279.  
  280. -- Initialize CPU bar
  281. updateCpuBar(currentCpuUsage)
  282.  
  283. -- Start the system update timer
  284. parallel.waitForAny(
  285.     function()
  286.         basalt.run()
  287.     end,
  288.     updateSystem
  289. )
Advertisement
Add Comment
Please, Sign In to add comment