feat(appgui): 添加应用GUI界面支持及包类型管理

新增appgui API用于绘制顶部和底部状态栏,提供一致的UI界面
在package.json中添加type字段区分应用和API包类型
更新安装程序以使用新的appgui界面
修改pkg程序以支持根据包类型安装到不同目录
添加appgui使用文档和演示程序
This commit is contained in:
2025-09-12 17:10:44 +08:00
parent 429b98ab00
commit 0bb365cadb
7 changed files with 346 additions and 33 deletions

View File

@@ -0,0 +1,94 @@
-- appgui API for LeonOS
-- Provides simple topbar and downbar drawing functions
local term = require("term")
local colors = require("colors")
local expect = require("cc.expect").expect
local appgui = {}
--- Draws a top bar with the specified text centered
--- @param text string The text to display in the top bar
--- @param fgColor number Optional foreground color (default: white)
--- @param bgColor number Optional background color (default: blue)
function appgui.topbar(text, fgColor, bgColor)
expect(1, text, "string")
expect(2, fgColor, "number", "nil")
expect(3, bgColor, "number", "nil")
-- Default colors
fgColor = fgColor or colors.white
bgColor = bgColor or colors.blue
-- Save current colors
local oldFg = term.getTextColor()
local oldBg = term.getBackgroundColor()
-- Get terminal size
local w, h = term.getSize()
-- Set colors and position
term.setTextColor(fgColor)
term.setBackgroundColor(bgColor)
term.setCursorPos(1, 1)
-- Clear the top line
term.clearLine()
-- Calculate padding for centered text
local padding = math.floor((w - #text) / 2)
-- Draw the top bar with centered text
term.write(string.rep(" ", padding) .. text .. string.rep(" ", padding))
-- Restore original colors
term.setTextColor(oldFg)
term.setBackgroundColor(oldBg)
-- Move cursor below the top bar
term.setCursorPos(1, 2)
end
--- Draws a bottom bar with the specified text centered
--- @param text string The text to display in the bottom bar
--- @param fgColor number Optional foreground color (default: white)
--- @param bgColor number Optional background color (default: blue)
function appgui.downbar(text, fgColor, bgColor)
expect(1, text, "string")
expect(2, fgColor, "number", "nil")
expect(3, bgColor, "number", "nil")
-- Default colors
fgColor = fgColor or colors.white
bgColor = bgColor or colors.blue
-- Save current colors
local oldFg = term.getTextColor()
local oldBg = term.getBackgroundColor()
-- Get terminal size
local w, h = term.getSize()
-- Set colors and position
term.setTextColor(fgColor)
term.setBackgroundColor(bgColor)
term.setCursorPos(1, h)
-- Clear the bottom line
term.clearLine()
-- Calculate padding for centered text
local padding = math.floor((w - #text) / 2)
-- Draw the bottom bar with centered text
term.write(string.rep(" ", padding) .. text .. string.rep(" ", padding))
-- Restore original colors
term.setTextColor(oldFg)
term.setBackgroundColor(oldBg)
-- Move cursor to a safe position
term.setCursorPos(1, 1)
end
return appgui