mirror of
https://github.com/CCLeonOS/LeonOS.git
synced 2026-03-03 15:17:01 +00:00
feat: 添加时间显示和图片查看程序并更新安装器版本
- 添加 time.lua 程序用于显示和格式化当前时间 - 添加 imageview.lua 程序用于从URL加载和显示图片 - 添加 pkg_download_en.hlp 帮助文档说明包管理功能 - 更新安装器版本号至 0.3.7 Beta 7
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
这个是我的世界模组CC电脑Tweaked版本的操作系统
|
这个是我的世界模组CC电脑Tweaked版本的操作系统
|
||||||
所以要用CC Tweaked所支持的lua代码写
|
所以要用CC Tweaked所支持的lua代码写
|
||||||
|
所有东西都用英语写
|
||||||
91
data/computercraft/lua/rom/help/pkg_download_en.hlp
Normal file
91
data/computercraft/lua/rom/help/pkg_download_en.hlp
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
=== How to Download Packages ===
|
||||||
|
|
||||||
|
In LeonOS, you can use the `pkg` command to download and install software packages. This help document will detailed explain how to use this command.
|
||||||
|
|
||||||
|
== Basic Usage ==
|
||||||
|
|
||||||
|
Download and install a package:
|
||||||
|
```
|
||||||
|
pkg install <package_name>
|
||||||
|
```
|
||||||
|
|
||||||
|
== Command Options ==
|
||||||
|
|
||||||
|
The `pkg install` command supports the following options:
|
||||||
|
|
||||||
|
- `-f`, `--force`: Force installation, overwrite existing files
|
||||||
|
- `-v`, `--verbose`: Show detailed installation process
|
||||||
|
- `-h`, `--help`: Show help information
|
||||||
|
|
||||||
|
== Usage Examples ==
|
||||||
|
|
||||||
|
1. Install a package:
|
||||||
|
```
|
||||||
|
pkg install example-package
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Force install a package:
|
||||||
|
```
|
||||||
|
pkg install --force example-package
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Install a package with detailed information:
|
||||||
|
```
|
||||||
|
pkg install -v example-package
|
||||||
|
```
|
||||||
|
|
||||||
|
4. View help for `pkg install` command:
|
||||||
|
```
|
||||||
|
pkg install --help
|
||||||
|
```
|
||||||
|
|
||||||
|
== Search for Packages ==
|
||||||
|
|
||||||
|
Before installing a package, you can search for available packages:
|
||||||
|
```
|
||||||
|
pkg search <search_keyword>
|
||||||
|
```
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```
|
||||||
|
pkg search editor
|
||||||
|
```
|
||||||
|
|
||||||
|
== View Package Information ==
|
||||||
|
|
||||||
|
Before installing a package, you can view detailed information about it:
|
||||||
|
```
|
||||||
|
pkg info <package_name>
|
||||||
|
```
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```
|
||||||
|
pkg info example-package
|
||||||
|
```
|
||||||
|
|
||||||
|
== Update Packages ==
|
||||||
|
|
||||||
|
You can update installed packages using the following command:
|
||||||
|
```
|
||||||
|
pkg update <package_name>
|
||||||
|
```
|
||||||
|
|
||||||
|
If you don't specify a package name, all installed packages will be updated:
|
||||||
|
```
|
||||||
|
pkg update
|
||||||
|
```
|
||||||
|
|
||||||
|
== Frequently Asked Questions ==
|
||||||
|
|
||||||
|
Q: What should I do if I encounter a network error when downloading a package?
|
||||||
|
A: Please check your network connection to ensure you can access the Internet. If the problem persists, please try again later.
|
||||||
|
|
||||||
|
Q: How can I view installed packages?
|
||||||
|
A: You can use the `pkg list` command to view all installed packages.
|
||||||
|
|
||||||
|
Q: Where can I get package names?
|
||||||
|
A: You can search for packages using the `pkg search` command or check the official package repository list.
|
||||||
|
|
||||||
|
== Exit Help ==
|
||||||
|
|
||||||
|
Press the ESC key to exit the help document.
|
||||||
92
data/computercraft/lua/rom/programs/imageview.lua
Normal file
92
data/computercraft/lua/rom/programs/imageview.lua
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
-- imageview.lua: Image viewer that loads from URL
|
||||||
|
local http = require("http")
|
||||||
|
local paintutils = require("paintutils")
|
||||||
|
local term = require("term")
|
||||||
|
local event = require("event")
|
||||||
|
local shell = require("shell")
|
||||||
|
|
||||||
|
-- 帮助信息函数
|
||||||
|
local function printHelp()
|
||||||
|
print("Usage: imageview <image_url>")
|
||||||
|
print("Options:")
|
||||||
|
print(" --help, -h Show this help message")
|
||||||
|
print("
|
||||||
|
Displays an image from the specified URL.
|
||||||
|
Press ESC to exit back to shell.")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 下载图片函数
|
||||||
|
local function downloadImage(url)
|
||||||
|
print("Downloading image from: " .. url)
|
||||||
|
local response, err = http.get(url, nil, true)
|
||||||
|
if not response then
|
||||||
|
print("Error downloading image: " .. err)
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local data = response.readAll()
|
||||||
|
response.close()
|
||||||
|
return data
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 主函数
|
||||||
|
local function main(args)
|
||||||
|
-- 处理命令行参数
|
||||||
|
if #args == 0 or args[1] == "--help" or args[1] == "-h" then
|
||||||
|
printHelp()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local imageUrl = args[1]
|
||||||
|
|
||||||
|
-- 检查是否是有效的URL
|
||||||
|
if not imageUrl:match("^https?://") then
|
||||||
|
print("Error: Invalid URL format. Must start with http:// or https://")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 下载图片
|
||||||
|
local imageData = downloadImage(imageUrl)
|
||||||
|
if not imageData then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 尝试加载图片
|
||||||
|
local success, image = pcall(function()
|
||||||
|
return paintutils.loadImage(imageData)
|
||||||
|
end)
|
||||||
|
|
||||||
|
if not success then
|
||||||
|
print("Error loading image: " .. image)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 清除屏幕并显示图片
|
||||||
|
term.clear()
|
||||||
|
local w, h = term.getSize()
|
||||||
|
|
||||||
|
-- 计算图片居中位置
|
||||||
|
local imgW, imgH = #image[1], #image
|
||||||
|
local x = math.floor((w - imgW) / 2)
|
||||||
|
local y = math.floor((h - imgH) / 2)
|
||||||
|
|
||||||
|
-- 绘制图片
|
||||||
|
paintutils.drawImage(image, x, y)
|
||||||
|
|
||||||
|
print("\nImage displayed. Press ESC to exit.")
|
||||||
|
|
||||||
|
-- 监听ESC键
|
||||||
|
while true do
|
||||||
|
local _, key = event.pull("key")
|
||||||
|
if key == 27 then -- ESC键
|
||||||
|
term.clear()
|
||||||
|
term.setCursorPos(1, 1)
|
||||||
|
print("Image viewer closed.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 运行主函数
|
||||||
|
local args = {...}
|
||||||
|
main(args)
|
||||||
66
data/computercraft/lua/rom/programs/time.lua
Normal file
66
data/computercraft/lua/rom/programs/time.lua
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
-- time.lua: Display current time
|
||||||
|
local shell = require("shell")
|
||||||
|
|
||||||
|
-- 帮助信息函数
|
||||||
|
local function printHelp()
|
||||||
|
print("Usage: time [options]")
|
||||||
|
print("Options:")
|
||||||
|
print(" --help, -h Show this help message")
|
||||||
|
print(" --format, -f <fmt> Specify time format string (see below for details)")
|
||||||
|
print("
|
||||||
|
Formats for --format option:")
|
||||||
|
print(" %Y: Year (4 digits)")
|
||||||
|
print(" %m: Month (01-12)")
|
||||||
|
print(" %d: Day (01-31)")
|
||||||
|
print(" %H: Hour (00-23)")
|
||||||
|
print(" %M: Minute (00-59)")
|
||||||
|
print(" %S: Second (00-59)")
|
||||||
|
print(" %A: Full weekday name")
|
||||||
|
print(" %B: Full month name")
|
||||||
|
print("
|
||||||
|
Examples:")
|
||||||
|
print(" time # Show current time in default format")
|
||||||
|
print(" time --format '%Y-%m-%d %H:%M:%S' # Show time as YYYY-MM-DD HH:MM:SS")
|
||||||
|
print(" time -f '%A, %B %d, %Y' # Show time as 'Monday, January 01, 2023'")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 主函数
|
||||||
|
local function main(args)
|
||||||
|
-- 处理命令行参数
|
||||||
|
local showHelp = false
|
||||||
|
local formatStr = "%Y-%m-%d %H:%M:%S"
|
||||||
|
local i = 1
|
||||||
|
|
||||||
|
while i <= #args do
|
||||||
|
if args[i] == "--help" or args[i] == "-h" then
|
||||||
|
showHelp = true
|
||||||
|
elseif args[i] == "--format" or args[i] == "-f" then
|
||||||
|
i = i + 1
|
||||||
|
if i <= #args then
|
||||||
|
formatStr = args[i]
|
||||||
|
else
|
||||||
|
print("Error: Missing format string for --format option")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
else
|
||||||
|
print("Error: Unknown option '" .. args[i] .. "'\n")
|
||||||
|
printHelp()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if showHelp then
|
||||||
|
printHelp()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 获取并显示当前时间
|
||||||
|
local currentTime = os.time()
|
||||||
|
local formattedTime = os.date(formatStr, currentTime)
|
||||||
|
print(formattedTime)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 运行主函数
|
||||||
|
local args = {...}
|
||||||
|
main(args)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
-- LeonOS installer
|
-- LeonOS installer
|
||||||
local INSTALLER_VERSION = "0.3.7 Beta 6"
|
local INSTALLER_VERSION = "0.3.7 Beta 7"
|
||||||
local DEFAULT_ROM_DIR = "/leonos"
|
local DEFAULT_ROM_DIR = "/leonos"
|
||||||
|
|
||||||
print("Start loading LeonOS installer ("..INSTALLER_VERSION..")...")
|
print("Start loading LeonOS installer ("..INSTALLER_VERSION..")...")
|
||||||
|
|||||||
Reference in New Issue
Block a user