Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Basalt UI Framework Test Program
- -- Run this in ComputerCraft with Basalt installed
- local basalt = require("basalt")
- -- Create main frame
- local main = basalt.createFrame()
- :setBackground(colors.black)
- :setSize("parent.w", "parent.h")
- -- Title bar
- local titleBar = main:addFrame()
- :setPosition(1, 1)
- :setSize("parent.w", 3)
- :setBackground(colors.blue)
- local title = titleBar:addLabel()
- :setText("Basalt UI Test Dashboard")
- :setPosition(2, 2)
- :setForeground(colors.white)
- -- System info panel
- local sysPanel = main:addFrame()
- :setPosition(2, 5)
- :setSize(25, 12)
- :setBackground(colors.gray)
- local sysTitle = sysPanel:addLabel()
- :setText("System Info")
- :setPosition(2, 1)
- :setForeground(colors.white)
- local cpuLabel = sysPanel:addLabel()
- :setText("CPU: 45%")
- :setPosition(2, 3)
- :setForeground(colors.lime)
- local memLabel = sysPanel:addLabel()
- :setText("Memory: 128MB")
- :setPosition(2, 4)
- :setForeground(colors.cyan)
- local diskLabel = sysPanel:addLabel()
- :setText("Disk: 2.4GB")
- :setPosition(2, 5)
- :setForeground(colors.yellow)
- -- CPU usage bar using labels
- local cpuBarBg = sysPanel:addLabel()
- :setText(" ")
- :setPosition(2, 7)
- :setBackground(colors.red)
- local cpuBarFg = sysPanel:addLabel()
- :setText(" ")
- :setPosition(2, 7)
- :setBackground(colors.lime)
- -- Control panel
- local controlPanel = main:addFrame()
- :setPosition(29, 5)
- :setSize(25, 15)
- :setBackground(colors.gray)
- local controlTitle = controlPanel:addLabel()
- :setText("Controls")
- :setPosition(2, 1)
- :setForeground(colors.white)
- -- Buttons
- local startBtn = controlPanel:addButton()
- :setText("Start Process")
- :setPosition(2, 3)
- :setSize(20, 3)
- :setBackground(colors.green)
- :setForeground(colors.white)
- local stopBtn = controlPanel:addButton()
- :setText("Stop Process")
- :setPosition(2, 7)
- :setSize(20, 3)
- :setBackground(colors.red)
- :setForeground(colors.white)
- local configBtn = controlPanel:addButton()
- :setText("Configuration")
- :setPosition(2, 11)
- :setSize(20, 3)
- :setBackground(colors.orange)
- :setForeground(colors.white)
- -- Log panel
- local logPanel = main:addFrame()
- :setPosition(2, 18)
- :setSize(52, 8)
- :setBackground(colors.black)
- local logTitle = logPanel:addLabel()
- :setText("Activity Log")
- :setPosition(2, 1)
- :setForeground(colors.white)
- -- Log entries using labels instead of list
- local logLine1 = logPanel:addLabel()
- :setText("System initialized")
- :setPosition(2, 3)
- :setForeground(colors.lime)
- local logLine2 = logPanel:addLabel()
- :setText("Basalt UI loaded successfully")
- :setPosition(2, 4)
- :setForeground(colors.cyan)
- local logLine3 = logPanel:addLabel()
- :setText("Waiting for user input...")
- :setPosition(2, 5)
- :setForeground(colors.yellow)
- local logLine4 = logPanel:addLabel()
- :setText("")
- :setPosition(2, 6)
- :setForeground(colors.white)
- -- Input field
- local inputFrame = main:addFrame()
- :setPosition(2, 27)
- :setSize(52, 4)
- :setBackground(colors.gray)
- local inputLabel = inputFrame:addLabel()
- :setText("Command:")
- :setPosition(2, 2)
- :setForeground(colors.white)
- local inputField = inputFrame:addInput()
- :setPosition(12, 2)
- :setSize(30, 1)
- :setBackground(colors.white)
- :setForeground(colors.black)
- local executeBtn = inputFrame:addButton()
- :setText("Execute")
- :setPosition(44, 2)
- :setSize(8, 1)
- :setBackground(colors.blue)
- :setForeground(colors.white)
- -- Status indicators
- local statusFrame = main:addFrame()
- :setPosition(56, 5)
- :setSize(15, 12)
- :setBackground(colors.lightGray)
- local statusTitle = statusFrame:addLabel()
- :setText("Status")
- :setPosition(2, 1)
- :setForeground(colors.black)
- local powerLED = statusFrame:addLabel()
- :setText("● Power")
- :setPosition(2, 3)
- :setForeground(colors.lime)
- local networkLED = statusFrame:addLabel()
- :setText("● Network")
- :setPosition(2, 4)
- :setForeground(colors.blue)
- local diskLED = statusFrame:addLabel()
- :setText("● Disk")
- :setPosition(2, 5)
- :setForeground(colors.yellow)
- local uptimeLabel = statusFrame:addLabel()
- :setText("Uptime: 0h")
- :setPosition(2, 7)
- :setForeground(colors.black)
- -- Variables for system simulation
- local currentCpuUsage = 45
- local logCount = 3
- local startTime = os.clock()
- -- Function to update CPU bar
- local function updateCpuBar(percentage)
- local barLength = math.floor(percentage / 5)
- local barText = string.rep(" ", barLength)
- cpuBarFg:setText(barText)
- end
- -- Event handlers
- startBtn:onClick(function()
- logCount = logCount + 1
- if logCount == 4 then
- logLine4:setText("Process started at " .. os.date("%H:%M:%S"))
- :setForeground(colors.lime)
- else
- logLine1:setText("Process started at " .. os.date("%H:%M:%S"))
- :setForeground(colors.lime)
- logLine2:setText("System running optimally")
- :setForeground(colors.cyan)
- logLine3:setText("All systems green")
- :setForeground(colors.lime)
- logLine4:setText("Ready for commands")
- :setForeground(colors.white)
- end
- currentCpuUsage = math.random(60, 90)
- cpuLabel:setText("CPU: " .. currentCpuUsage .. "%")
- updateCpuBar(currentCpuUsage)
- end)
- stopBtn:onClick(function()
- logLine1:setText("Process stopped at " .. os.date("%H:%M:%S"))
- :setForeground(colors.red)
- logLine2:setText("System idle")
- :setForeground(colors.orange)
- logLine3:setText("Waiting for new task")
- :setForeground(colors.yellow)
- logLine4:setText("")
- :setForeground(colors.white)
- currentCpuUsage = math.random(10, 30)
- cpuLabel:setText("CPU: " .. currentCpuUsage .. "%")
- updateCpuBar(currentCpuUsage)
- end)
- configBtn:onClick(function()
- logLine1:setText("Configuration panel opened")
- :setForeground(colors.orange)
- logLine2:setText("Settings loaded")
- :setForeground(colors.cyan)
- logLine3:setText("Ready to configure")
- :setForeground(colors.white)
- logLine4:setText("")
- end)
- executeBtn:onClick(function()
- local command = inputField:getValue()
- if command ~= "" then
- logLine1:setText("> " .. command)
- :setForeground(colors.cyan)
- logLine2:setText("Command executed successfully")
- :setForeground(colors.lime)
- logLine3:setText("Return code: 0")
- :setForeground(colors.white)
- logLine4:setText("Ready for next command")
- :setForeground(colors.yellow)
- inputField:setValue("")
- end
- end)
- -- Real-time system update
- local function updateSystem()
- while true do
- sleep(3)
- -- Update CPU usage
- currentCpuUsage = math.max(20, math.min(95, currentCpuUsage + math.random(-15, 15)))
- cpuLabel:setText("CPU: " .. currentCpuUsage .. "%")
- updateCpuBar(currentCpuUsage)
- -- Update memory
- local memUsed = math.random(64, 256)
- memLabel:setText("Memory: " .. memUsed .. "MB")
- -- Update uptime
- local uptime = math.floor((os.clock() - startTime) / 3600)
- uptimeLabel:setText("Uptime: " .. uptime .. "h")
- -- Blink network LED
- if math.random() > 0.5 then
- networkLED:setForeground(colors.lightBlue)
- else
- networkLED:setForeground(colors.blue)
- end
- end
- end
- -- Initialize CPU bar
- updateCpuBar(currentCpuUsage)
- -- Start the system update timer
- parallel.waitForAny(
- function()
- basalt.run()
- end,
- updateSystem
- )
Advertisement
Add Comment
Please, Sign In to add comment