mirror of
https://github.com/CCLeonOS/LeonOS.git
synced 2026-03-03 15:08:29 +00:00
feat: 更新安装程序版本至0.3.8 Beta 5
refactor: 移除ROM目录下多余的completions文件 docs: 添加项目规则说明要求使用中文回复 chore: 添加VSCode计数器生成的代码统计文件
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("about", completion.build(
|
||||
-- about command doesn't take parameters
|
||||
))
|
||||
@@ -1,7 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("app", completion.build(
|
||||
{completion.choice, choices = {"install", "update", "remove", "list"}, desc = "Command"},
|
||||
{completion.anything, desc = "App name", optional = true}
|
||||
))
|
||||
@@ -1,6 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("appdelete", completion.build(
|
||||
{completion.anything, desc = "App name"}
|
||||
))
|
||||
@@ -1,6 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("applist", completion.build(
|
||||
-- applist command doesn't take parameters
|
||||
))
|
||||
@@ -1,6 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("clear", completion.build(
|
||||
-- clear command doesn't take parameters
|
||||
))
|
||||
@@ -1,6 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("commands", completion.build(
|
||||
-- commands command doesn't take parameters
|
||||
))
|
||||
@@ -1,7 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("config", completion.build(
|
||||
{completion.anything, desc = "Config key"},
|
||||
{completion.anything, desc = "Config value", optional = true}
|
||||
))
|
||||
@@ -1,6 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("craftos", completion.build(
|
||||
-- craftos command doesn't take parameters
|
||||
))
|
||||
@@ -1,7 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("find", completion.build(
|
||||
{completion.anything, desc = "Search pattern"},
|
||||
{completion.dir, desc = "Directory", optional = true}
|
||||
))
|
||||
@@ -1,6 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("helplist", completion.build(
|
||||
-- helplist command doesn't take parameters
|
||||
))
|
||||
@@ -1,6 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("history", completion.build(
|
||||
{completion.number, desc = "Number of entries", optional = true}
|
||||
))
|
||||
@@ -1,6 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("imageview", completion.build(
|
||||
completion.anything
|
||||
))
|
||||
@@ -1,6 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("lua", completion.build(
|
||||
{completion.dirOrFile, desc = "Script file", optional = true}
|
||||
))
|
||||
@@ -1,6 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("peripherals", completion.build(
|
||||
-- peripherals command doesn't take parameters
|
||||
))
|
||||
@@ -1,6 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("programs", completion.build(
|
||||
-- programs command doesn't take parameters
|
||||
))
|
||||
@@ -1,6 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("shell", completion.build(
|
||||
{completion.anything, desc = "Command", optional = true}
|
||||
))
|
||||
@@ -1,6 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("storage", completion.build(
|
||||
-- storage command doesn't take parameters
|
||||
))
|
||||
@@ -1,6 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("threads", completion.build(
|
||||
-- threads command doesn't take parameters
|
||||
))
|
||||
@@ -1,6 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("time", completion.build(
|
||||
-- time command doesn't take parameters
|
||||
))
|
||||
@@ -1,7 +0,0 @@
|
||||
local shell = require("shell")
|
||||
local completion = require("cc.shell.completion")
|
||||
|
||||
shell.setCompletionFunction("wget", completion.build(
|
||||
{completion.anything, desc = "URL"},
|
||||
{completion.dirOrFile, desc = "Output file", optional = true}
|
||||
))
|
||||
175
data/computercraft/lua/rom/help/create_package.hlp
Normal file
175
data/computercraft/lua/rom/help/create_package.hlp
Normal file
@@ -0,0 +1,175 @@
|
||||
=== How To Create A Package ===
|
||||
|
||||
This guide explains how to create your own packages for LeonOS using the `pkg` command.
|
||||
|
||||
== Introduction ==
|
||||
|
||||
Packages are a way to distribute and reuse code in LeonOS. A package typically contains:
|
||||
- A metadata file (package.json)
|
||||
- One or more Lua files with your code
|
||||
- Optional resources (images, configuration files, etc.)
|
||||
|
||||
== Creating a Package ==
|
||||
|
||||
To create a new package, use the `pkg init` command:
|
||||
|
||||
>>color yellow
|
||||
pkg init <package_name>
|
||||
>>color white
|
||||
|
||||
Replace `<package_name>` with a unique name for your package.
|
||||
|
||||
== Package Structure ==
|
||||
|
||||
After running `pkg init`, the following structure will be created in the `/packages/` directory:
|
||||
|
||||
/packages/
|
||||
<package_name>/
|
||||
1.0.0/
|
||||
package.json - Package metadata
|
||||
<package_name>.lua - Main package file
|
||||
|
||||
== package.json Format ==
|
||||
|
||||
The package.json file contains metadata about your package. Here's an example:
|
||||
|
||||
>>color yellow
|
||||
{
|
||||
"name": "<package_name>",
|
||||
"version": "1.0.0",
|
||||
"author": "Your Name",
|
||||
"description": "A brief description of your package",
|
||||
"main": "<package_name>.lua",
|
||||
"dependencies": {},
|
||||
"exports": {
|
||||
"function1": "function1",
|
||||
"function2": "function2"
|
||||
}
|
||||
}
|
||||
>>color white
|
||||
|
||||
- **name**: The name of your package (must match the directory name)
|
||||
- **version**: The package version (semantic versioning recommended)
|
||||
- **author**: Your name or username
|
||||
- **description**: A short description of what the package does
|
||||
- **main**: The main Lua file to load
|
||||
- **dependencies**: Other packages your package depends on
|
||||
- **exports**: Functions or variables to export for other programs to use
|
||||
|
||||
== Writing Package Code ==
|
||||
|
||||
Edit the `<package_name>.lua` file to add your code. Here's a simple example:
|
||||
|
||||
>>color yellow
|
||||
-- <package_name>.lua
|
||||
|
||||
local mypackage = {}
|
||||
|
||||
function mypackage.function1(param)
|
||||
return "Hello, " .. param .. "!"
|
||||
end
|
||||
|
||||
function mypackage.function2()
|
||||
return "This is function2"
|
||||
end
|
||||
|
||||
return mypackage
|
||||
>>color white
|
||||
|
||||
== Testing Your Package ==
|
||||
|
||||
To test your package before publishing, you can use it in a Lua program:
|
||||
|
||||
>>color yellow
|
||||
-- test_package.lua
|
||||
|
||||
local mypackage = require("<package_name>")
|
||||
print(mypackage.function1("world"))
|
||||
>>color white
|
||||
|
||||
Run the test program:
|
||||
|
||||
>>color yellow
|
||||
lua test_package.lua
|
||||
>>color white
|
||||
|
||||
== Installing Your Package ==
|
||||
|
||||
Once your package is ready, you can install it locally:
|
||||
|
||||
>>color yellow
|
||||
pkg install --local /packages/<package_name>/1.0.0/
|
||||
>>color white
|
||||
|
||||
== Publishing Your Package ==
|
||||
|
||||
To share your package with others, you need to publish it to a package repository. This typically involves:
|
||||
|
||||
1. Creating an account on the repository
|
||||
2. Uploading your package files
|
||||
3. Registering your package
|
||||
|
||||
For more information on publishing, see the documentation for your chosen repository.
|
||||
|
||||
== Best Practices ==
|
||||
|
||||
- Use semantic versioning (major.minor.patch)
|
||||
- Keep your package focused on a single purpose
|
||||
- Document your functions and their parameters
|
||||
- Test your package thoroughly
|
||||
- Update the version number when you make changes
|
||||
|
||||
== Example Walkthrough ==
|
||||
|
||||
Let's create a simple package called "greeting":
|
||||
|
||||
1. Create the package:
|
||||
>>color yellow
|
||||
pkg init greeting
|
||||
>>color white
|
||||
|
||||
2. Edit package.json:
|
||||
>>color yellow
|
||||
{
|
||||
"name": "greeting",
|
||||
"version": "1.0.0",
|
||||
"author": "Your Name",
|
||||
"description": "A simple greeting package",
|
||||
"main": "greeting.lua",
|
||||
"dependencies": {},
|
||||
"exports": {
|
||||
"sayHello": "sayHello"
|
||||
}
|
||||
}
|
||||
>>color white
|
||||
|
||||
3. Edit greeting.lua:
|
||||
>>color yellow
|
||||
-- greeting.lua
|
||||
|
||||
local greeting = {}
|
||||
|
||||
function greeting.sayHello(name)
|
||||
return "Hello, " .. name .. "! Welcome to LeonOS!"
|
||||
end
|
||||
|
||||
return greeting
|
||||
>>color white
|
||||
|
||||
4. Test the package:
|
||||
>>color yellow
|
||||
-- test_greeting.lua
|
||||
local greeting = require("greeting")
|
||||
print(greeting.sayHello("User"))
|
||||
>>color white
|
||||
|
||||
Run with: lua test_greeting.lua
|
||||
|
||||
5. Install the package:
|
||||
>>color yellow
|
||||
pkg install --local /packages/greeting/1.0.0/
|
||||
>>color white
|
||||
|
||||
Now your package is ready to use in other programs!
|
||||
|
||||
For more information, run `pkg help` or check other help files in the /rom/help directory.
|
||||
194
data/computercraft/lua/rom/programs/network.lua
Normal file
194
data/computercraft/lua/rom/programs/network.lua
Normal file
@@ -0,0 +1,194 @@
|
||||
-- network.lua - Network utility tool for CC Tweaked
|
||||
|
||||
local expect = require("cc.expect").expect
|
||||
local rednet = require("rednet")
|
||||
local term = require("term")
|
||||
local textutils = require("textutils")
|
||||
local os = require("os")
|
||||
local colors = require("colors")
|
||||
|
||||
-- Check if HTTP is available
|
||||
local http_available = package.loaded.http ~= nil
|
||||
local http = nil
|
||||
if http_available then
|
||||
http = require("http")
|
||||
end
|
||||
|
||||
local function print_usage()
|
||||
print("Network Utility Tool")
|
||||
print("Usage:")
|
||||
print(" network status - Check network status")
|
||||
print(" network scan <ip> [port_range] - Scan ports on a device")
|
||||
print(" network discover - Discover remote devices")
|
||||
print(" network help - Show this help")
|
||||
end
|
||||
|
||||
local function check_network_status()
|
||||
print("=== Network Status ===")
|
||||
print("HTTP: " .. (http_available and "Enabled" or "Disabled"))
|
||||
|
||||
local modems = {}
|
||||
for _, side in pairs(peripheral.getNames()) do
|
||||
if peripheral.getType(side) == "modem" then
|
||||
table.insert(modems, side)
|
||||
end
|
||||
end
|
||||
|
||||
print("Available modems: " .. #modems)
|
||||
if #modems > 0 then
|
||||
print("Modem list:")
|
||||
for _, modem in ipairs(modems) do
|
||||
print(" - " .. modem .. " (Open: " .. tostring(rednet.isOpen(modem)) .. ")")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function scan_ports(ip, port_range)
|
||||
if not http_available then
|
||||
error("HTTP is not enabled in the ComputerCraft configuration", 0)
|
||||
end
|
||||
|
||||
expect(1, ip, "string")
|
||||
expect(2, port_range, "string", "nil")
|
||||
|
||||
local start_port, end_port = 1, 1024
|
||||
if port_range then
|
||||
start_port, end_port = port_range:match("(%d+)-(%d+)")
|
||||
if not start_port or not end_port then
|
||||
error("Invalid port range format. Use: start-end", 0)
|
||||
end
|
||||
start_port = tonumber(start_port)
|
||||
end_port = tonumber(end_port)
|
||||
end
|
||||
|
||||
print("Scanning ports " .. start_port .. "-" .. end_port .. " on " .. ip)
|
||||
print("Press Ctrl+T to cancel")
|
||||
|
||||
local open_ports = {}
|
||||
local timeout = 0.5 -- seconds per port
|
||||
|
||||
for port = start_port, end_port do
|
||||
term.write("Scanning port " .. port .. "... ")
|
||||
|
||||
local success, result = pcall(function()
|
||||
local url = "http://" .. ip .. ":" .. port
|
||||
local handle = http.get(url, nil, true, timeout)
|
||||
if handle then
|
||||
handle.close()
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end)
|
||||
|
||||
if success and result then
|
||||
print(colors.green .. "OPEN" .. colors.white)
|
||||
table.insert(open_ports, port)
|
||||
else
|
||||
print(colors.red .. "CLOSED" .. colors.white)
|
||||
end
|
||||
|
||||
-- Check for interrupt
|
||||
local timer_id = os.startTimer(0.1)
|
||||
while true do
|
||||
local event, param1 = os.pullEventRaw()
|
||||
if event == "timer" and param1 == timer_id then
|
||||
break
|
||||
elseif event == "terminate" then
|
||||
print("\nScan cancelled.")
|
||||
return
|
||||
end
|
||||
end -- Small delay to prevent CPU overload
|
||||
end
|
||||
|
||||
print("\nScan complete.")
|
||||
if #open_ports > 0 then
|
||||
print("Open ports found: " .. #open_ports)
|
||||
for _, port in ipairs(open_ports) do
|
||||
print(" - " .. port)
|
||||
end
|
||||
else
|
||||
print("No open ports found.")
|
||||
end
|
||||
end
|
||||
|
||||
local function discover_devices()
|
||||
-- Find available modems and open them
|
||||
local modems = {}
|
||||
for _, side in pairs(peripheral.getNames()) do
|
||||
if peripheral.getType(side) == "modem" then
|
||||
table.insert(modems, side)
|
||||
if not rednet.isOpen(side) then
|
||||
rednet.open(side)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if #modems == 0 then
|
||||
error("No modems found. Please attach a modem.", 0)
|
||||
end
|
||||
|
||||
print("Discovering devices on network...")
|
||||
print("Press Ctrl+T to cancel")
|
||||
|
||||
-- Ensure rednet is running without blocking
|
||||
if not rednet.isOpen() then
|
||||
-- We don't use rednet.run() as it blocks, instead we'll handle events manually
|
||||
for _, modem in ipairs(modems) do
|
||||
rednet.open(modem)
|
||||
end
|
||||
end
|
||||
|
||||
-- Send broadcast
|
||||
rednet.broadcast("DISCOVER")
|
||||
|
||||
local devices = {}
|
||||
local timeout = 5 -- seconds
|
||||
local timer = os.startTimer(timeout)
|
||||
|
||||
while true do
|
||||
local event = table.pack(os.pullEvent())
|
||||
if event[1] == "timer" and event[2] == timer then
|
||||
break
|
||||
elseif event[1] == "rednet_message" then
|
||||
local sender_id = event[2]
|
||||
local message = event[3]
|
||||
if message == "DISCOVER_RESPONSE" then
|
||||
if not devices[sender_id] then
|
||||
devices[sender_id] = true
|
||||
print("Found device: " .. sender_id)
|
||||
end
|
||||
end
|
||||
elseif event[1] == "terminate" then
|
||||
print("\nDiscovery cancelled.")
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- Close modems
|
||||
for _, modem in ipairs(modems) do
|
||||
rednet.close(modem)
|
||||
end
|
||||
|
||||
print("\nDiscovery complete.")
|
||||
print("Found " .. textutils.size(devices) .. " devices.")
|
||||
end
|
||||
|
||||
-- Main program
|
||||
local args = {...}
|
||||
if #args == 0 or args[1] == "help" then
|
||||
print_usage()
|
||||
elseif args[1] == "status" then
|
||||
check_network_status()
|
||||
elseif args[1] == "scan" then
|
||||
if #args < 2 then
|
||||
print("Error: Missing IP address")
|
||||
print_usage()
|
||||
else
|
||||
scan_ports(args[2], args[3])
|
||||
end
|
||||
elseif args[1] == "discover" then
|
||||
discover_devices()
|
||||
else
|
||||
print("Error: Unknown command")
|
||||
print_usage()
|
||||
end
|
||||
Reference in New Issue
Block a user