Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- LemonOS: Pocket Shell for Lemonphone
- -- by ChatGPT (GPT-5)
- -- Features: Persistent settings, live clock, signal bars, auto-netchat install, firmware info
- local CONFIG_PATH = "/lemonos.cfg"
- local NETCHAT_PATH = "/netchat"
- local STARTUP_PATH = "/startup.lua"
- -- Firmware info
- local firmware = {
- device = "Lemonphone Pocket Computer",
- version = "LemonOS v1.0.0",
- }
- local config = {
- username = "User",
- accentColor = colors.yellow,
- bgColor = colors.black,
- rednetSide = "back",
- }
- -- === CONFIG LOAD/SAVE ===
- local function saveConfig()
- local file = fs.open(CONFIG_PATH, "w")
- if file then
- file.write(textutils.serialize(config))
- file.close()
- end
- end
- local function loadConfig()
- if fs.exists(CONFIG_PATH) then
- local file = fs.open(CONFIG_PATH, "r")
- if file then
- local data = file.readAll()
- file.close()
- local ok, tbl = pcall(textutils.unserialize, data)
- if ok and type(tbl) == "table" then
- for k, v in pairs(tbl) do
- config[k] = v
- end
- end
- end
- end
- end
- loadConfig()
- -- === AUTO DOWNLOAD NETCHAT ===
- if not fs.exists(NETCHAT_PATH) then
- print("Downloading netchat...")
- if http then
- local success, response = pcall(http.get, "https://pastebin.com/raw/GwmGxjwy")
- if success and response then
- local content = response.readAll()
- response.close()
- local file = fs.open(NETCHAT_PATH, "w")
- file.write(content)
- file.close()
- print("netchat installed!")
- else
- print("Failed to download netchat.")
- end
- else
- print("HTTP API not enabled, cannot download netchat.")
- end
- -- Set startup to shell.run("firm.lpsw")
- local file = fs.open(STARTUP_PATH, "w")
- file.write('shell.run("firm.lpsw")')
- file.close()
- end
- -- === INITIALIZE REDNET ===
- if peripheral.find("modem") then
- rednet.open(config.rednetSide)
- else
- rednet.close(config.rednetSide)
- end
- -- === UTILITIES ===
- local function centerText(y, text, color)
- local w = term.getSize()
- local x = math.floor((w - #text) / 2)
- term.setCursorPos(x, y)
- if color then term.setTextColor(color) end
- term.write(text)
- term.setTextColor(colors.white)
- end
- local function getSignalStrength()
- if not rednet.isOpen(config.rednetSide) then return 0 end
- local peers = { rednet.lookup("lemonphone_ping") }
- if #peers == 0 then
- return 1
- elseif #peers < 3 then
- return 2
- else
- return 3
- end
- end
- local function drawSignalBars(strength)
- local barChar = "|"
- local maxBars = 3
- for i = 1, maxBars do
- if i <= strength then
- term.setTextColor(colors.lime)
- else
- term.setTextColor(colors.gray)
- end
- term.write(barChar)
- end
- term.setTextColor(colors.white)
- end
- local function drawTopBar()
- local w = term.getSize()
- term.setCursorPos(1, 1)
- term.setBackgroundColor(config.accentColor)
- term.clearLine()
- -- Left: signal strength
- term.setCursorPos(2, 1)
- if rednet.isOpen(config.rednetSide) then
- drawSignalBars(getSignalStrength())
- term.write(" Net")
- else
- term.setTextColor(colors.red)
- term.write("X NoNet")
- term.setTextColor(colors.white)
- end
- -- Right: time and date
- local timeStr = textutils.formatTime(os.time(), true)
- local dateStr = os.date("%b %d")
- local clock = timeStr .. " | " .. dateStr
- term.setCursorPos(w - #clock - 1, 1)
- term.setTextColor(colors.white)
- term.write(clock)
- end
- local function drawMenu(selected)
- local apps = {
- {name = "Messages", cmd = "netchat join"},
- {name = "Files", cmd = "shell"},
- {name = "Settings", cmd = "settings"},
- {name = "About Lemonphone", cmd = "about"},
- {name = "Reboot", cmd = "reboot"}
- }
- local _, h = term.getSize()
- local startY = 4
- term.setTextColor(colors.white)
- for i, app in ipairs(apps) do
- term.setCursorPos(4, startY + i - 1)
- if i == selected then
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.black)
- else
- term.setBackgroundColor(config.bgColor)
- term.setTextColor(colors.white)
- end
- term.clearLine()
- term.setCursorPos(4, startY + i - 1)
- term.write(app.name)
- end
- term.setBackgroundColor(config.bgColor)
- return apps
- end
- -- === SETTINGS MENU ===
- local function openSettings()
- while true do
- term.setBackgroundColor(config.bgColor)
- term.clear()
- centerText(3, "Settings", config.accentColor)
- term.setCursorPos(2, 5)
- term.write("1. Change Username")
- term.setCursorPos(2, 6)
- term.write("2. Change Accent Color")
- term.setCursorPos(2, 7)
- term.write("3. Back")
- local _, key = os.pullEvent("key")
- if key == keys.one then
- term.setCursorPos(2, 9)
- term.clearLine()
- term.write("Enter new username: ")
- config.username = read()
- saveConfig()
- elseif key == keys.two then
- term.setCursorPos(2, 9)
- term.clearLine()
- term.write("Color name (e.g. yellow): ")
- local colorName = read()
- if colors[colorName] then
- config.accentColor = colors[colorName]
- saveConfig()
- else
- term.setCursorPos(2, 10)
- term.write("Invalid color.")
- sleep(1)
- end
- elseif key == keys.three then
- return
- end
- end
- end
- -- === ABOUT LEMONPHONE ===
- local function aboutLemonphone()
- term.setBackgroundColor(config.bgColor)
- term.clear()
- centerText(3, "About Lemonphone", config.accentColor)
- term.setCursorPos(2, 5)
- term.write("Device: " .. firmware.device)
- term.setCursorPos(2, 6)
- term.write("Firmware: " .. firmware.version)
- term.setCursorPos(2, 8)
- term.write("Press any key to return...")
- os.pullEvent("key")
- end
- -- === MAIN LOOP ===
- local selected = 1
- local refreshRate = 1.0
- local timer = os.startTimer(refreshRate)
- while true do
- term.setBackgroundColor(config.bgColor)
- term.clear()
- drawTopBar()
- centerText(3, config.username .. "'s Lemonphone", config.accentColor)
- local apps = drawMenu(selected)
- local event, key = os.pullEvent()
- if event == "key" then
- if key == keys.up then
- selected = math.max(1, selected - 1)
- elseif key == keys.down then
- selected = math.min(#apps, selected + 1)
- elseif key == keys.enter then
- local chosen = apps[selected]
- if chosen.name == "Settings" then
- openSettings()
- elseif chosen.name == "About Lemonphone" then
- aboutLemonphone()
- else
- term.setBackgroundColor(config.bgColor)
- term.clear()
- term.setCursorPos(1, 1)
- shell.run(chosen.cmd)
- end
- end
- elseif event == "timer" then
- timer = os.startTimer(refreshRate)
- drawTopBar()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment