-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackagebrowser.lua
More file actions
127 lines (127 loc) · 4.93 KB
/
packagebrowser.lua
File metadata and controls
127 lines (127 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
function menu( title, ... )
--edit the background color to make the GUI more unique
term.setBackgroundColor( colors.black )
local debug = false --#turn to true to see what it's thinking
local tArgs = { ... }
local dulist = tArgs[1]
local pages = {[1]={}}
for i = 1, #dulist, 1 do
if #pages[ #pages ] == 7 then
pages[ #pages + 1 ] = {}
end
pages[ #pages ][ #pages[#pages] + 1 ] = dulist[i]
end
local maxLen = 0
for k, v in ipairs( tArgs ) do
if #v > maxLen then maxLen = #v end
end
local maxx, maxy = term.getSize()
if maxLen > maxx - 20 then
error( 'largest string is too large', 2 )
end
local centerx = math.ceil( maxx/2 )
local centery
local yValue = {}
local page = 1
local selected = math.ceil( #pages[ page ] / 2 )
local function render()
local tbl = pages[ page ]
centery = (maxy/2) - #tbl/2
term.clear()
term.setCursorPos( centerx - #title/2 + 1, 2 )
term.write( title )
for i = 1, #tbl do
term.setCursorPos( centerx - (#tbl[i]/2), centery + i )
yValue[ i ] = centery + i
term.write( tbl[ i ] )
end
if pages[ page - 1 ] then
term.setCursorPos( 3, centery + #tbl/2 + 1 )
term.write( "previous" )
end
if pages[ page + 1 ] then
term.setCursorPos( maxx - 5, centery + #tbl/2 + 1 )
term.write( "next" )
end
local str = "(" .. page .. "/" .. #pages .. ")"
term.setCursorPos( centerx - (#str/2), maxy )
term.write( str )
end
while true do
render()
if debug then
term.setCursorPos( 1, 1 )
term.write( selected )
term.setCursorPos( 1, 2 )
term.write( page )
end
if term.isColor() then
term.setTextColor( colors.yellow )
end
if selected == "previous" and not pages[ page - 1 ] then
selected = math.ceil( #pages[ page ]/2 )
elseif selected == "next" and not pages[ page + 1 ] then
selected = math.ceil( #pages[ page ]/2 )
end
if type( selected ) == "number" then
term.setCursorPos( centerx - (#pages[page][selected]/2) - 3, yValue[ selected ] )
term.write( "[" )
term.setCursorPos( centerx + (#pages[page][selected]/2) + 2, yValue[ selected ] )
term.write( "]" )
elseif selected == "previous" then
term.setCursorPos( 1, centery + #pages[ page ]/2 + 1 )
term.write( "[" )
term.setCursorPos( 12, centery + #pages[ page ]/2 + 1 )
term.write( "]" )
elseif selected == "next" then
term.setCursorPos( maxx - 7, centery + #pages[ page ]/2 + 1 )
term.write( "[" )
term.setCursorPos( maxx, centery + #pages[ page ]/2 + 1 )
term.write( "]" )
end
if term.isColor() then
term.setTextColor( colors.white )
end
local event, key = os.pullEvent( "key" )
local old = selected
if key == keys.up and type( selected ) == "number" and pages[ page ][ selected - 1 ] then
selected = selected - 1
elseif key == keys.down and type( selected ) == "number" and pages[ page ][ selected + 1 ] then
selected = selected + 1
elseif key == keys.enter then
if type( selected ) == "number" then
return pages[ page ][ selected ]
elseif selected == "next" and pages[ page + 1 ] then
page = page + 1
elseif selected == "previous" and pages[ page - 1 ] then
page = page - 1
end
elseif key == keys.left then
if selected == "next" then
selected = math.ceil( #pages[ page ]/2 )
elseif type( selected ) == "number" and pages[ page - 1 ] then
selected = "previous"
end
elseif key == keys.right then
if selected == "previous" then
selected = math.ceil( #pages[ page ]/2 )
elseif type( selected ) == "number" and pages[ page + 1 ] then
selected = "next"
end
end
end
end
--Display the menu
packages = http.get("https://raw.githubusercontent.com/NiftyNarwhal11/ModularOS/refs/heads/main/packagelist").readAll()
packagelist = require "cc.strings".split(packages, "\n")
local package = menu("Hello", packagelist)
term.clear()
term.setCursorPos(1,1)
print("You have selected to install: ", package)
sleep(2)
local packageConnect = http.get("https://raw.githubusercontent.com/NiftyNarwhal11/ModularOS/refs/heads/main/.packages/" .. package)
if fs.exists(package .. ".lua") then
shell.run("rm " .. package .. ".lua")
end
shell.run("wget https://raw.githubusercontent.com/NiftyNarwhal11/ModularOS/refs/heads/main/.packages/" .. package .. ".lua " .. " " .. package .. ".lua")
print("Done!")