mirror of
https://github.com/CCLeonOS/LeonOS.git
synced 2026-03-03 15:17:01 +00:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51cf60dfc1 | ||
|
|
a441a62417 | ||
|
|
b1e7f6c8d3 | ||
|
|
9f0b5c4156 | ||
|
|
06458f0283 | ||
|
|
b0973e2ad4 | ||
|
|
5deffe0ef4 | ||
|
|
770a04eaca | ||
|
|
93cebf337e | ||
|
|
03c76ebcd7 | ||
|
|
13c047c8d4 | ||
|
|
b34df6d682 | ||
|
|
3cb9a007f2 | ||
|
|
ab37382fa8 | ||
|
|
a5766b5e6a | ||
|
|
a37d349cd4 | ||
|
|
16ac26e2bd | ||
|
|
f9fa18585f | ||
|
|
1927d1222d | ||
|
|
bf396ef4ba | ||
|
|
adb57f5ee8 | ||
|
|
81297b724f | ||
|
|
50f8f989c7 | ||
|
|
0bb365cadb | ||
|
|
98a108f1f6 | ||
|
|
429b98ab00 | ||
|
|
e60b50b9e1 | ||
|
|
ef76f6db50 |
15
LICENSE_BSL
Normal file
15
LICENSE_BSL
Normal file
@@ -0,0 +1,15 @@
|
||||
BLC Certificate
|
||||
|
||||
Copyright © LeonOS Organization. All rights reserved.
|
||||
|
||||
The full name of the BLC Certificate is "Build with LeonCore".
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of the operating system with the BLC Certificate, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the operating system; when using or modifying the operating system with the BLC Certificate, you may keep the operating system closed-source, but shall indicate this agreement on the system information page; you must indicate "Powered by LeonCore" at startup or in other relevant locations of the operating system; you may use the operating system for commercial profit, but for commercialized versions of the operating system, you shall report the profit situation to LeonCore via GitHub Issues; you may open-source the operating system under any open-source license other than the BLC License; this agreement shall only apply to the open-source projects of LeonCore.
|
||||
|
||||
Any contributor who submits code, documents, or other contributions to the LeonCore open-source project hereby grants the LeonOS Organization the right to use, modify, and redistribute such contributions, and the submitted content must comply with the terms of this agreement. The contributor shall ensure that the submitted content is free of copyright disputes and does not infringe the legitimate rights and interests of third parties; otherwise, the contributor shall bear full responsibility for any consequences arising therefrom.
|
||||
|
||||
This version of the BLC Agreement is Version 1.0. The LeonOS Organization reserves the right to revise this agreement, and the revised agreement shall be published through the official GitHub repository of the LeonCore project. After the revised agreement takes effect, any act of using or modifying the operating system shall comply with the latest version of the agreement.
|
||||
|
||||
THE OPERATING SYSTEM WITH THE BLC CERTIFICATE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE OPERATING SYSTEM OR THE USE OR OTHER DEALINGS IN THE OPERATING SYSTEM.
|
||||
31
README.md
31
README.md
@@ -1,6 +1,35 @@
|
||||

|
||||
# LeonOS
|
||||
Use
|
||||
```shell
|
||||
wget run https://gh.catmak.name/https://raw.githubusercontent.com/Leonmmcoset/LeonOS/refs/heads/main/installer.lua
|
||||
wget run https://gh.catmak.name/https://raw.githubusercontent.com/CCLeonOS/LeonOS/refs/heads/main/installer.lua
|
||||
```
|
||||
to install the LeonOS system.
|
||||
|
||||
> [!NOTE]
|
||||
> The CatOS program is moved to `ccleonos/catos-installer`.
|
||||
|
||||
## How did LeonOS work?
|
||||
[](https://mermaid.live/edit#pako:eNq1WO9T00gY_lc6cfwGTSgUSmfuZrQtZ-dkdE79ctZxQhpoJE06STrKqTMgVMvPogeIiAIHHnhzU_HUo0LR_-Wum5RP_Av3bjZJE1qmMtPrlya77_Pus---u--zuU9xcpKnwtSgKN_lUqyi-a5HE5IPfufP-9DLL9WNHeP9AXo9fVxeqT75o1Kaqo7OVErT-qcxY2caDI7L-etR33e-63KmPSrflY7LkwnJ8aCv76FyARVXKp8nwVIvzKPJWbS5qy_PHZdnjI1i5esrfXJUX52sTj0yHn02Ftb0xbzpA3vgRFZVo_ygT5BUjRVFXvENCqIYPhdlYqG-vjZVU-RhPnyu60IvEwu0cbIoK-FzDMOcgCtZSRPSvAWOMX19McYBd0Z6ujujp4P5exqvSKxooTH2YsBBx7p7YgHv0M7sjYUdPb9X2d-q7D8jjTdUXrmZoEgHDkippOcL6HEObS2hzQ944tStcDhsEbaZCNywCfUlqJSmZdQwTQ8JWio74OfkNM1xIi9LskpbfwOiPECnWUGik6zG0mCSycIUOIUd1Ggxy9IDgqz64SFBucii4mR1M3e0_Lde_EQa43bQgTHpxUu-XwDeznpgNw5rp9XN2_FyVvKeMTBVO4C-9vbvHySo6tf56sbMCasHtfFOTMJGze2hwtJPV_rR3LRRfotmchj0g6Bdyg40RqDHL1DuTVayo_bv6BjA9aUnlYO_0dZneM2w3LA_zaV5zWRwWeZYse-aO7ZbS0fjO_rqLJraqJTmjnKzxmGR9JKRIcLkAWKL5tbQ9nT100RlfxuMjcm8vvqnE2M7Gwk6EgdkJE5HomjvTeVwFbZlIzOyEpH4WZfAT6zou7IyjE8IlVZ4kWdV3j-SFu0luSxIGrCoHGwa62P65qi-9gbPcXNOXy9XtydQ_sXplDD2zKQ0heVpJSvyKp1R5Ds8p9023_zppM2pH5YCJz_w8izOaTxs-7Ny8Th3L6idbdu_o8JTsoTwgErjOEEi8Qam7h1G6y8_6ku75MVYmdD35xuktgduIRzbGxmYD7asncVAYXWX5K3x4cA4WCNdanZgSGEzKTtvIWYNTKlbxBr_LsqyJspskpwM5UX0roym1quHh875UNstpx0OtdjXvJ01-rVR7OCb7OJXrsUkTRnJyCQzcQPsYFTYhAoD5OqoeU5bFzGPo__h7LWHqz05a5Gg4Iw5WlxF4wW3Jf5d06BMZzM49PPv0NROdWIF1iuRgNKbZ5jbg6Z73z-Pn_l6mdsqr2mCNNRkvrU5W85bNFkFQCrxSDvUTs7nwtW4CpOBP_T-UVOC2Prb2GkKzzdlx2YElT7JqF9O4vMEb4SdDfTqORxnaP_XptQsWAvZpYnHOoJXFRnSJI0ZEuFANh7mWXwN4gKKAcrtNSVsu2kh44zlso5yBMxFXhNkqcYaBCXkLyrO6Pn5pmRdDlrIl6t5raMcSwqarJhpYMs0o7xU_fIUvdhpStcCt5AqTzzW0bzEi-ZhUCqiqbfkzG7KDmNaSC0F7up4_ciPpNkMDt_RQtF4uawvr6PdiabULFgL2Q0Tj_W7CIo3O2Tuc5CB-sI7fWas-Z6xQC3il7Hc1ZGza30yLiX5e5ji3l-WRPj4G9TcpkS9Dlp0oDt07Wqe9N9RZclNnpeSjSqbpUfw5ccUFLCZ3CIHawZi8W2iwXJ3ZsVQG8PN-YrCpXi40bGwwW7aWgrNFqq74yfofRs7t78WltIaBZu8GezaNYNIsf0Cyj9vcJdxKS3S61JelgY1VZxHL2Et6RVCFtYrjiy5C_GC6uOWJQC3NAXB2QID88G1nLSaVR03WTXUUvFWQcUddq0iPU7lwl34TujWuebqkQ8Up1waPWng0squRPXMyB34B57VJRjPervvmRaXUg7NLp68ZzYAkasm0fHOHdN1paTaqCFFSFLhQVZU-TYqzSuQM_BO3cc-E5SW4uE0oMLwmGSVYZwmDwGUYaWfZTlNhTUlCzBFzg6l7Bcyt6jA4oA6FpBYvBKR4Xihwh3dTMD0QYXvU_eocHtHR5e_KxDs7O4JMcEepjPY2UaNQHsg5O8JdoQCvcHOXqYrGOoJPGyjfjEHDvgDwVCog-kJhoK9THdvCDySgtZPPkCZ36Ee_gdH7zUU)
|
||||
Chinese version
|
||||
---
|
||||
|
||||
LeonOS's kernal "The LeonCore Open Source Project" which is LeonCore is open source as BLC Certificate
|
||||
|
||||
```
|
||||
BLC Certificate
|
||||
|
||||
Copyright © LeonOS Organization. All rights reserved.
|
||||
|
||||
The full name of the BLC Certificate is "Build with LeonCore".
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of the operating system with the BLC Certificate, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the operating system; when using or modifying the operating system with the BLC Certificate, you may keep the operating system closed-source, but shall indicate this agreement on the system information page; you must indicate "Powered by LeonCore" at startup or in other relevant locations of the operating system; you may use the operating system for commercial profit, but for commercialized versions of the operating system, you shall report the profit situation to LeonCore via GitHub Issues; you may open-source the operating system under any open-source license other than the BLC License; this agreement shall only apply to the open-source projects of LeonCore.
|
||||
|
||||
Any contributor who submits code, documents, or other contributions to the LeonCore open-source project hereby grants the LeonOS Organization the right to use, modify, and redistribute such contributions, and the submitted content must comply with the terms of this agreement. The contributor shall ensure that the submitted content is free of copyright disputes and does not infringe the legitimate rights and interests of third parties; otherwise, the contributor shall bear full responsibility for any consequences arising therefrom.
|
||||
|
||||
This version of the BLC Agreement is Version 1.0. The LeonOS Organization reserves the right to revise this agreement, and the revised agreement shall be published through the official GitHub repository of the LeonCore project. After the revised agreement takes effect, any act of using or modifying the operating system shall comply with the latest version of the agreement.
|
||||
|
||||
THE OPERATING SYSTEM WITH THE BLC CERTIFICATE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE OPERATING SYSTEM OR THE USE OR OTHER DEALINGS IN THE OPERATING SYSTEM.
|
||||
```
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
_G._HOST = _G._HOST .. " (LeonOS 1.0.1)"
|
||||
_G._HOST = _G._HOST .. " (LeonOS 1.0.3)"
|
||||
local fs = rawget(_G, "fs")
|
||||
|
||||
_G._RC_ROM_DIR = _RC_ROM_DIR or (...) and fs.exists("/leonos") and "/leonos" or "/rom"
|
||||
@@ -32,7 +32,7 @@ local rc = {
|
||||
_VERSION = {
|
||||
major = 1,
|
||||
minor = 0,
|
||||
patch = 1
|
||||
patch = 3
|
||||
},
|
||||
queueEvent = pull(os, "queueEvent"),
|
||||
startTimer = pull(os, "startTimer"),
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"description": "An example package for LeonOS",
|
||||
"author": "LeonMMcoset",
|
||||
"license": "MIT",
|
||||
"type": "app",
|
||||
"dependencies": {},
|
||||
"files": [
|
||||
"example.lua"
|
||||
|
||||
94
data/computercraft/lua/rom/apis/appgui.lua
Normal file
94
data/computercraft/lua/rom/apis/appgui.lua
Normal 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
|
||||
103
data/computercraft/lua/rom/help/appgui.hlp
Normal file
103
data/computercraft/lua/rom/help/appgui.hlp
Normal file
@@ -0,0 +1,103 @@
|
||||
=== appgui API ===
|
||||
|
||||
The `appgui` API provides simple functions for drawing top bars and bottom bars in LeonOS applications, making it easy to create consistent user interfaces.
|
||||
|
||||
== Introduction ==
|
||||
|
||||
The appgui API is designed to simplify the process of adding professional-looking UI elements to your applications. It provides two main functions for drawing centered text bars at the top or bottom of the screen.
|
||||
|
||||
== Available Functions ==
|
||||
|
||||
- **appgui.topbar(text, [fgColor], [bgColor])**: Draws a top bar with centered text
|
||||
- **appgui.downbar(text, [fgColor], [bgColor])**: Draws a bottom bar with centered text
|
||||
|
||||
== Function Parameters ==
|
||||
|
||||
Both functions accept the following parameters:
|
||||
|
||||
- **text**: (string) The text to display in the bar
|
||||
- **fgColor**: (number, optional) The foreground color (default: white)
|
||||
- **bgColor**: (number, optional) The background color (default: blue)
|
||||
|
||||
== Usage Examples ==
|
||||
|
||||
=== Basic Usage ===
|
||||
|
||||
First, you need to import the appgui module:
|
||||
|
||||
>>color yellow
|
||||
local appgui = require("appgui")
|
||||
>>color white
|
||||
|
||||
Then you can use the functions to draw bars:
|
||||
|
||||
1. Draw a top bar with default colors (white text on blue background):
|
||||
>>color yellow
|
||||
appgui.topbar("My Application Title")
|
||||
>>color white
|
||||
|
||||
2. Draw a bottom bar with default colors:
|
||||
>>color yellow
|
||||
appgui.downbar("Status: Ready")
|
||||
>>color white
|
||||
|
||||
=== Custom Colors ===
|
||||
|
||||
You can specify custom colors using the `colors` module:
|
||||
|
||||
>>color yellow
|
||||
local colors = require("colors")
|
||||
|
||||
-- Red text on yellow background
|
||||
appgui.topbar("Warning Message", colors.red, colors.yellow)
|
||||
|
||||
-- Green text on black background
|
||||
appgui.downbar("Success", colors.green, colors.black)
|
||||
>>color white
|
||||
|
||||
=== Complete Example ===
|
||||
|
||||
Here's a complete example showing how to use both top and bottom bars in an application:
|
||||
|
||||
>>color yellow
|
||||
local appgui = require("appgui")
|
||||
local term = require("term")
|
||||
local colors = require("colors")
|
||||
|
||||
-- Clear the screen
|
||||
term.clear()
|
||||
|
||||
-- Draw top and bottom bars
|
||||
appgui.topbar("My Application")
|
||||
appgui.downbar("Press Q to quit")
|
||||
|
||||
-- Add some content
|
||||
print()
|
||||
print("Welcome to my application!")
|
||||
print()
|
||||
print("This is a demonstration of the appgui API.")
|
||||
print()
|
||||
|
||||
-- Wait for 'Q' key to exit
|
||||
while true do
|
||||
local event, key = os.pullEvent("key")
|
||||
if key == 16 then -- Q key
|
||||
break
|
||||
end
|
||||
end
|
||||
>>color white
|
||||
|
||||
== Notes ==
|
||||
|
||||
- The text will be automatically centered in the bar
|
||||
- The functions will preserve the original terminal colors by saving and restoring them
|
||||
- After drawing a top bar, the cursor will be positioned below the bar
|
||||
- After drawing a bottom bar, the cursor will be positioned at the top of the screen
|
||||
- You can use any colors available in the `colors` module
|
||||
- If the text is longer than the terminal width, it will be truncated
|
||||
|
||||
== See Also ==
|
||||
|
||||
- **colors**: For available color values
|
||||
- **term**: For other terminal manipulation functions
|
||||
- **appgui_demo**: A demonstration program showing the appgui API in action
|
||||
@@ -52,10 +52,33 @@ The package.json file contains metadata about your package. Here's an example:
|
||||
- **version**: The package version (semantic versioning recommended)
|
||||
- **author**: Your name or username
|
||||
- **description**: A short description of what the package does
|
||||
- **type**: The type of your package ("app" for applications, "api" for libraries)
|
||||
- **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
|
||||
|
||||
== Package Type Field ==
|
||||
|
||||
The `type` field in package.json determines where your package files will be installed:
|
||||
|
||||
- **app**: Files will be installed in the `/app` directory (default behavior)
|
||||
- **api**: Files will be installed in the `/leonos/apis` directory
|
||||
|
||||
Example of a package.json with type field:
|
||||
|
||||
>>color yellow
|
||||
{
|
||||
"name": "example-api",
|
||||
"version": "1.0.0",
|
||||
"author": "Your Name",
|
||||
"description": "An example API package",
|
||||
"type": "api",
|
||||
"main": "example-api.lua",
|
||||
"dependencies": {},
|
||||
"exports": {}
|
||||
}
|
||||
>>color white
|
||||
|
||||
== Writing Package Code ==
|
||||
|
||||
Edit the `<package_name>.lua` file to add your code. Here's a simple example:
|
||||
|
||||
77
data/computercraft/lua/rom/programs/appgui_demo.lua
Normal file
77
data/computercraft/lua/rom/programs/appgui_demo.lua
Normal file
@@ -0,0 +1,77 @@
|
||||
-- appgui_demo.lua
|
||||
-- Demonstration of the appgui API for drawing top and bottom bars
|
||||
|
||||
local appgui = require("appgui")
|
||||
local term = require("term")
|
||||
local colors = require("colors")
|
||||
|
||||
-- Clear the screen before starting
|
||||
term.clear()
|
||||
|
||||
-- Draw the top bar with default colors (white text on blue background)
|
||||
appgui.topbar("LeonOS App GUI Demo")
|
||||
|
||||
-- Add some content in the middle
|
||||
print()
|
||||
print("This is a demonstration of the appgui API.")
|
||||
print()
|
||||
print("The top bar shows the application title.")
|
||||
print("The bottom bar shows the status information.")
|
||||
print()
|
||||
print("Press any key to see custom colors...")
|
||||
|
||||
-- Wait for a key press using a safe event pulling function
|
||||
local pullEventFunc = os.pullEvent or os.pullEventRaw
|
||||
if not pullEventFunc then
|
||||
error("No valid event pulling function found")
|
||||
end
|
||||
local event, key = table.unpack({pullEventFunc("key")})
|
||||
|
||||
-- Clear the screen and redraw with custom colors
|
||||
term.clear()
|
||||
appgui.topbar("Custom Colored Top Bar", colors.yellow, colors.red)
|
||||
|
||||
-- Add some content
|
||||
print()
|
||||
print("Now with custom colors!")
|
||||
print()
|
||||
print("Top bar: Yellow text on Red background")
|
||||
print()
|
||||
print("Press any key to continue...")
|
||||
|
||||
-- Wait for a key press using a safe event pulling function
|
||||
local pullEventFunc = os.pullEvent or os.pullEventRaw
|
||||
if not pullEventFunc then
|
||||
error("No valid event pulling function found")
|
||||
end
|
||||
local event, key = table.unpack({pullEventFunc("key")})
|
||||
|
||||
-- Clear the screen and draw both top and bottom bars
|
||||
term.clear()
|
||||
appgui.topbar("Complete GUI Demo")
|
||||
appgui.downbar("Status: Running - Press Q to quit")
|
||||
|
||||
-- Add some content in the middle
|
||||
print()
|
||||
print("Now you can see both top and bottom bars.")
|
||||
print()
|
||||
print("Try resizing the terminal window to see how the text stays centered.")
|
||||
print()
|
||||
print("Press Q to exit this demo.")
|
||||
|
||||
-- Main loop to handle key presses
|
||||
while true do
|
||||
-- Use a safe event pulling function
|
||||
local pullEventFunc = os.pullEvent or os.pullEventRaw
|
||||
if not pullEventFunc then
|
||||
error("No valid event pulling function found")
|
||||
end
|
||||
local event, key = table.unpack({pullEventFunc("key")})
|
||||
if key == 16 then -- Q key
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- Clear the screen before exiting
|
||||
term.clear()
|
||||
print("AppGUI Demo has ended.")
|
||||
@@ -1,68 +0,0 @@
|
||||
-- CatOS web installer: wget run https://catos.cpolar.cn/install.lua
|
||||
-- This CatOS installer is for LeonOS
|
||||
-- Require
|
||||
fs = require("fs")
|
||||
http = require("http")
|
||||
term = require("term")
|
||||
colors = require("colors")
|
||||
textutils = require("textutils")
|
||||
-- Main
|
||||
local SITE = "https://catos.cpolar.cn"
|
||||
textutils.coloredPrint("You are going to install CatOS to your computer.")
|
||||
textutils.coloredPrint("We suggest you backup the files before install the CatOS.")
|
||||
textutils.coloredPrint(colors.yellow, "Are you sure? (y/n)")
|
||||
local confirm = term.read()
|
||||
if confirm ~= "y" then
|
||||
print("Installation cancelled.")
|
||||
return
|
||||
end
|
||||
local function http_get(url)
|
||||
local r = http.get(url)
|
||||
if not r then error("request failed: " .. url) end
|
||||
local s = r.readAll() or ""; r.close(); return s
|
||||
end
|
||||
|
||||
local function write_file(path, content)
|
||||
local dir = fs.getDir(path)
|
||||
if dir ~= "" and not fs.exists(dir) then fs.makeDir(dir) end
|
||||
local h = fs.open(path, "w")
|
||||
if not h then error("cannot write: " .. path) end
|
||||
h.write(content or "")
|
||||
h.close()
|
||||
end
|
||||
|
||||
term.setBackgroundColor(colors.black)
|
||||
term.setTextColor(colors.white)
|
||||
term.clear()
|
||||
term.setCursorPos(1,1)
|
||||
print("CatOS installer - fetching manifest...")
|
||||
local manifest_json = http_get(SITE .. "/repo/catos-manifest.json")
|
||||
local ok, manifest = pcall(textutils.unserializeJSON, manifest_json)
|
||||
if not ok or type(manifest) ~= "table" then error("invalid manifest") end
|
||||
|
||||
local base = manifest.base or "/root"
|
||||
local files = manifest.files or {}
|
||||
local total = #files
|
||||
local i = 0
|
||||
for _, rel in ipairs(files) do
|
||||
i = i + 1
|
||||
-- black overlay with progress
|
||||
local w,h = term.getSize()
|
||||
term.setBackgroundColor(colors.black)
|
||||
term.setTextColor(colors.white)
|
||||
term.setCursorPos(1,1); term.clearLine()
|
||||
print(string.format("Installing CatOS [%d/%d] %s", i, total, rel))
|
||||
-- draw progress bar at line 3
|
||||
local pct = math.floor((i-1)/math.max(1,total) * (w-2))
|
||||
term.setCursorPos(1,3)
|
||||
term.clearLine()
|
||||
term.write("[")
|
||||
term.write(string.rep("#", pct))
|
||||
term.write(string.rep("-", (w-2)-pct))
|
||||
term.write("]")
|
||||
local content = http_get(SITE .. base .. "/" .. rel)
|
||||
write_file(rel, content)
|
||||
end
|
||||
|
||||
term.setCursorPos(1,5)
|
||||
print("CatOS installed. Type 'restart' to complete the installation.")
|
||||
@@ -35,7 +35,7 @@ print("LeonOS Lua REPL.\nCall exit() to exit.")
|
||||
local history = {}
|
||||
while run do
|
||||
term.setTextColor(colors.white)
|
||||
io.write("$ lua >>> ")
|
||||
io.write("$ lua # ")
|
||||
local data = term.read(nil, history, function(text)
|
||||
return textutils.complete(text, env)
|
||||
end)
|
||||
|
||||
@@ -29,7 +29,7 @@ local pkg_config = {
|
||||
local_pkg_dir = "/packages", -- 本地包存储目录
|
||||
installed_db = "/packages/installed.json", -- 已安装包数据库
|
||||
cache_dir = "/packages/cache", -- 缓存目录
|
||||
github_api_url = "https://raw.githubusercontent.com" -- GitHub API基础URL
|
||||
github_api_url = "https://gh.catmak.name/https://raw.githubusercontent.com" -- GitHub API基础URL
|
||||
}
|
||||
|
||||
-- 创建新包
|
||||
@@ -54,6 +54,7 @@ local function create_package(pkg_name)
|
||||
description = "A new package for LeonOS",
|
||||
author = "LeonOS User",
|
||||
license = "MIT",
|
||||
type = "app", -- 默认类型为app
|
||||
dependencies = {},
|
||||
files = {
|
||||
pkg_name .. ".lua"
|
||||
@@ -288,18 +289,25 @@ local function install_github_package(repo_path, options)
|
||||
meta_file:write(textutils.serializeJSON(meta, false))
|
||||
meta_file:close()
|
||||
|
||||
-- 下载并安装文件
|
||||
-- 根据package类型确定安装目录
|
||||
print("Installing version: " .. pkg_version)
|
||||
local app_dir = "/app"
|
||||
if not fs.exists(app_dir) then
|
||||
fs.makeDir(app_dir)
|
||||
local install_dir
|
||||
if meta.type and meta.type == "api" then
|
||||
install_dir = "/leonos/apis"
|
||||
else
|
||||
install_dir = "/app" -- 默认安装到app目录
|
||||
end
|
||||
|
||||
-- 确保安装目录存在
|
||||
if not fs.exists(install_dir) then
|
||||
fs.makeDir(install_dir)
|
||||
end
|
||||
|
||||
local success_count = 0
|
||||
local fail_count = 0
|
||||
|
||||
for _, file_path in ipairs(meta.files or {}) do
|
||||
local dest = fs.combine(app_dir, file_path)
|
||||
local dest = fs.combine(install_dir, file_path)
|
||||
|
||||
if download_github_package_file(repo_path, file_path, dest) then
|
||||
print("Installed: " .. file_path)
|
||||
@@ -386,17 +394,23 @@ local function install_package(pkg_name, options)
|
||||
return false
|
||||
end
|
||||
|
||||
-- 安装文件
|
||||
-- 根据package类型确定安装目录
|
||||
print("Installing version: " .. latest_version)
|
||||
-- 确保app目录存在
|
||||
local app_dir = "/app"
|
||||
if not fs.exists(app_dir) then
|
||||
fs.makeDir(app_dir)
|
||||
local install_dir
|
||||
if meta.type and meta.type == "api" then
|
||||
install_dir = "/leonos/apis"
|
||||
else
|
||||
install_dir = "/app" -- 默认安装到app目录
|
||||
end
|
||||
|
||||
-- 确保安装目录存在
|
||||
if not fs.exists(install_dir) then
|
||||
fs.makeDir(install_dir)
|
||||
end
|
||||
|
||||
for _, file_path in ipairs(meta.files or {}) do
|
||||
local src = fs.combine(version_path, file_path)
|
||||
local dest = fs.combine(app_dir, file_path)
|
||||
local dest = fs.combine(install_dir, file_path)
|
||||
|
||||
-- 确保目标目录存在
|
||||
local dest_dir = fs.getDir(dest)
|
||||
@@ -508,9 +522,14 @@ local function remove_package(pkg_name)
|
||||
file:close()
|
||||
local ok, meta = pcall(textutils.unserializeJSON, meta_content)
|
||||
if ok and meta then
|
||||
-- 删除包文件
|
||||
-- 移除包文件
|
||||
for _, file_path in ipairs(meta.files or {}) do
|
||||
local dest = fs.combine("/rom", file_path)
|
||||
local dest
|
||||
if meta.type and meta.type == "api" then
|
||||
dest = fs.combine("/leonos/apis", file_path)
|
||||
else
|
||||
dest = fs.combine("/app", file_path)
|
||||
end
|
||||
if fs.exists(dest) then
|
||||
fs.delete(dest)
|
||||
print("Removed: " .. file_path)
|
||||
|
||||
@@ -40,7 +40,7 @@ textutils.coloredPrint(colors.yellow,
|
||||
print("Checking for update...")
|
||||
|
||||
local http = require("http")
|
||||
local base = "https://gh.catmak.name/https://raw.githubusercontent.com/Leonmmcoset/LeonOS/refs/heads/main/"
|
||||
local base = "https://gh.catmak.name/https://raw.githubusercontent.com/CCLeonOS/LeonOS/refs/heads/main/"
|
||||
|
||||
local Bhandle, Berr = http.get(base .. "data/computercraft/lua/bios.lua")
|
||||
if not Bhandle then
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
-- LeonOS installer
|
||||
local INSTALLER_VERSION = "1.0.1"
|
||||
local INSTALLER_VERSION = "1.0.3 Beta 7"
|
||||
local DEFAULT_ROM_DIR = "/leonos"
|
||||
|
||||
print("Start loading LeonOS installer ("..INSTALLER_VERSION..")...")
|
||||
@@ -47,7 +47,7 @@ print("[Installer] Loading done.")
|
||||
print("[Installer] Loading module 7")
|
||||
local function rcload(f)
|
||||
return ghload(
|
||||
"Leonmmcoset/LeonOS/refs/heads/main/data/computercraft/lua/rom/"..f, f)
|
||||
"CCLeonOS/LeonOS/refs/heads/main/data/computercraft/lua/rom/"..f, f)
|
||||
end
|
||||
print("[Installer] Loading done.")
|
||||
print("[Installer] Loading module 8")
|
||||
@@ -69,6 +69,7 @@ term.write("[Installer] Loading done.\n")
|
||||
local term = require("term")
|
||||
local colors = require("colors")
|
||||
local rc = require("rc")
|
||||
-- local appgui = require("appgui")
|
||||
-- 保存当前颜色设置
|
||||
local old_fg = term.getTextColor()
|
||||
local old_bg = term.getBackgroundColor()
|
||||
@@ -96,10 +97,13 @@ tu.coloredPrint("If you want to keep the existing files, please backup them firs
|
||||
tu.coloredPrint(colors.yellow, "Are you sure? (y/n)")
|
||||
local confirm = read()
|
||||
if confirm ~= "y" then
|
||||
term.at(1, y).clearLine()
|
||||
print("Installation cancelled.")
|
||||
return
|
||||
end
|
||||
|
||||
for y=2, term.getSize() do
|
||||
term.at(1, y).clearLine()
|
||||
end
|
||||
local ROM_DIR
|
||||
-- tu.coloredPrint("Enter installation directory ", colors.yellow, "[",
|
||||
-- colors.lightBlue, DEFAULT_ROM_DIR, colors.yellow, "]")
|
||||
@@ -123,7 +127,7 @@ end
|
||||
|
||||
bullet("Getting repository tree...")
|
||||
|
||||
local repodata = dl("https://gh.catmak.name/https://api.github.com/repos/Leonmmcoset/LeonOS/git/trees/main?recursive=1")
|
||||
local repodata = dl("https://gh.catmak.name/https://api.github.com/repos/CCLeonOS/LeonOS/git/trees/main?recursive=1")
|
||||
|
||||
repodata = json.decode(repodata)
|
||||
|
||||
@@ -179,7 +183,7 @@ for i=1, #to_dl, 1 do
|
||||
local v = to_dl[i]
|
||||
if v.type == "blob" then
|
||||
parallels[#parallels+1] = function()
|
||||
local data = dl("https://gh.catmak.name/https://raw.githubusercontent.com/Leonmmcoset/LeonOS/refs/heads/main/data/computercraft/lua/"..v.path)
|
||||
local data = dl("https://gh.catmak.name/https://raw.githubusercontent.com/CCLeonOS/LeonOS/refs/heads/main/data/computercraft/lua/"..v.path)
|
||||
assert(io.open(v.real_path, "w")):write(data):close()
|
||||
done = done + 1
|
||||
progress(pby, done, #to_dl)
|
||||
@@ -193,11 +197,14 @@ term.at(1, pby).write((" "):rep((term.getSize())))
|
||||
term.at(okx, oky)
|
||||
ok()
|
||||
|
||||
bullet("Downloading startup file...")
|
||||
assert(io.open(
|
||||
fs.exists("/startup.lua") and "/unbios-rc.lua" or "/startup.lua", "w"))
|
||||
:write(dl(
|
||||
"https://gh.catmak.name/https://raw.githubusercontent.com/Leonmmcoset/LeonOS/refs/heads/main/unbios.lua"
|
||||
"https://gh.catmak.name/https://raw.githubusercontent.com/CCLeonOS/LeonOS/refs/heads/main/unbios.lua"
|
||||
)):close()
|
||||
ok()
|
||||
os.sleep(0.5)
|
||||
|
||||
tu.coloredPrint(colors.yellow, "Your computer will restart in 3 seconds.")
|
||||
local _, y = term.getCursorPos()
|
||||
|
||||
Reference in New Issue
Block a user