feat: 初始提交 LeonOS 实现
添加 LeonOS 的基本实现,包括:
- 核心 API 模块(colors, disk, gps, keys, multishell, parallel, rednet, redstone, settings, vector)
- 命令行程序(about, alias, bg, clear, copy, delete, edit, fg, help, list, lua, mkdir, move, paint, peripherals, programs, reboot, set, shutdown, threads)
- 系统启动脚本和包管理
- 文档(README.md, LICENSE)
- 开发工具(devbin)和更新程序
实现功能:
- 完整的线程管理系统
- 兼容 ComputerCraft 的 API 设计
- 改进的 shell 和命令补全系统
- 多标签终端支持
- 设置管理系统
2025-08-31 16:54:18 +08:00
|
|
|
-- rc.shell
|
|
|
|
|
|
|
|
|
|
local rc = require("rc")
|
|
|
|
|
local fs = require("fs")
|
|
|
|
|
local term = require("term")
|
|
|
|
|
local shell = require("shell")
|
|
|
|
|
local colors = require("colors")
|
|
|
|
|
local thread = require("rc.thread")
|
|
|
|
|
local textutils = require("textutils")
|
|
|
|
|
|
|
|
|
|
if os.version then
|
|
|
|
|
textutils.coloredPrint(colors.yellow, os.version(), colors.white)
|
|
|
|
|
else
|
|
|
|
|
textutils.coloredPrint(colors.yellow, rc.version(), colors.white)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
thread.vars().parentShell = thread.id()
|
|
|
|
|
shell.init(_ENV)
|
|
|
|
|
|
|
|
|
|
if not shell.__has_run_startup then
|
|
|
|
|
shell.__has_run_startup = true
|
|
|
|
|
if fs.exists("/startup.lua") then
|
|
|
|
|
local ok, err = pcall(dofile, "/startup.lua")
|
|
|
|
|
if not ok and err then
|
|
|
|
|
io.stderr:write(err, "\n")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if fs.exists("/startup") and fs.isDir("/startup") then
|
|
|
|
|
local files = fs.list("/startup/")
|
|
|
|
|
table.sort(files)
|
|
|
|
|
|
|
|
|
|
for f=1, #files, 1 do
|
|
|
|
|
local ok, err = pcall(dofile, "/startup/"..files[f])
|
|
|
|
|
if not ok and err then
|
|
|
|
|
io.stderr:write(err, "\n")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local aliases = {
|
|
|
|
|
background = "bg",
|
|
|
|
|
clr = "clear",
|
|
|
|
|
cp = "copy",
|
|
|
|
|
dir = "list",
|
|
|
|
|
foreground = "fg",
|
|
|
|
|
mv = "move",
|
|
|
|
|
rm = "delete",
|
|
|
|
|
rs = "redstone",
|
|
|
|
|
sh = "shell",
|
2025-08-31 17:52:37 +08:00
|
|
|
ps = "threads",
|
|
|
|
|
restart = "reboot"
|
feat: 初始提交 LeonOS 实现
添加 LeonOS 的基本实现,包括:
- 核心 API 模块(colors, disk, gps, keys, multishell, parallel, rednet, redstone, settings, vector)
- 命令行程序(about, alias, bg, clear, copy, delete, edit, fg, help, list, lua, mkdir, move, paint, peripherals, programs, reboot, set, shutdown, threads)
- 系统启动脚本和包管理
- 文档(README.md, LICENSE)
- 开发工具(devbin)和更新程序
实现功能:
- 完整的线程管理系统
- 兼容 ComputerCraft 的 API 设计
- 改进的 shell 和命令补全系统
- 多标签终端支持
- 设置管理系统
2025-08-31 16:54:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for k, v in pairs(aliases) do
|
|
|
|
|
shell.setAlias(k, v)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local completions = "/rc/completions"
|
|
|
|
|
for _, prog in ipairs(fs.list(completions)) do
|
|
|
|
|
dofile(fs.combine(completions, prog))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local history = {}
|
|
|
|
|
while true do
|
|
|
|
|
term.setTextColor(colors.yellow)
|
|
|
|
|
term.setBackgroundColor(colors.black)
|
2025-08-31 19:23:21 +08:00
|
|
|
rc.write(colors.yellow.."$"..shell.dir()..colors.green.." >>> ")
|
feat: 初始提交 LeonOS 实现
添加 LeonOS 的基本实现,包括:
- 核心 API 模块(colors, disk, gps, keys, multishell, parallel, rednet, redstone, settings, vector)
- 命令行程序(about, alias, bg, clear, copy, delete, edit, fg, help, list, lua, mkdir, move, paint, peripherals, programs, reboot, set, shutdown, threads)
- 系统启动脚本和包管理
- 文档(README.md, LICENSE)
- 开发工具(devbin)和更新程序
实现功能:
- 完整的线程管理系统
- 兼容 ComputerCraft 的 API 设计
- 改进的 shell 和命令补全系统
- 多标签终端支持
- 设置管理系统
2025-08-31 16:54:18 +08:00
|
|
|
term.setTextColor(colors.white)
|
|
|
|
|
|
|
|
|
|
local text = term.read(nil, history, shell.complete)
|
|
|
|
|
if #text > 0 then
|
|
|
|
|
history[#history+1] = text
|
|
|
|
|
local ok, err = shell.run(text)
|
|
|
|
|
if not ok and err then
|
|
|
|
|
io.stderr:write(err, "\n")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|