added scrolling support to the repoinstaller menu

Esse commit está contido em:
Izaya 2020-10-19 13:35:49 +11:00
commit f9af8fb9ef
1 arquivos alterados com 20 adições e 7 exclusões

Ver arquivo

@ -1,7 +1,7 @@
local serial = require "serialization"
local event = require "event"
local fs = require "filesystem"
local unicode = require "unicode"
local fs = require "filesystem"
local event = require "event"
local tArgs = {...}
local ipackages = {} -- installed packages
@ -49,6 +49,10 @@ end
function info(pkg) -- shows info for pkg
clear()
local fh = io.popen("less","w")
local function print(str)
fh:write(str.."\n")
end
print(string.format("%s - %s",pkg,packages[pkg].name))
print(packages[pkg].description)
if packages[pkg].files then
@ -63,6 +67,7 @@ function info(pkg) -- shows info for pkg
print(" - "..k)
end
end
fh:close()
end
local preamble = false
@ -82,14 +87,25 @@ if preamble then -- display pre-inst screen
event.pull("key_down")
end
local selected = 1
local mx, my = require("term").getViewport()
local selected, start = 1, 1
local function drawmenu() -- draw the menu display - nothing but text and VT100 escape codes
local infostring = string.format("[%s][%s]%s", unicode.char(0x2191), unicode.char(0x2193), " Move [Space] (De)select [i] More Info [q] Quit [Enter] Confirm")
clear()
io.write(string.format("\27[%d;1H%s\27[H",my,infostring))
local workingSpace = my - math.ceil(infostring:len() / mx) - 1
if install.label then
print(install.label .. " installer")
workingSpace = workingSpace - 1
end
for k,v in pairs(pkgmap) do
if selected > start + workingSpace - 3 then
start = math.min(start + 3, #pkgmap - workingSpace)
elseif selected < start + 3 then
start = math.max(start - 3, 1)
end
for k = start, math.min(#pkgmap,start+workingSpace) do
local v = pkgmap[k]
if k == selected then
io.write("\27[30;47m")
end
@ -101,7 +117,6 @@ local function drawmenu() -- draw the menu display - nothing but text and VT100
io.write(v)
print("\27[0m")
end
print("Use the arrow keys to navigate. (De)select options with space. View more info by pressing i, and quit by pressing q. Confirm with enter.")
end
--[[
@ -126,8 +141,6 @@ while run do -- menu loop
install = false
elseif ch == 105 and co == 23 then
info(pkgmap[selected])
print("\nPress any key to return to the menu.")
event.pull("key_down")
elseif ch == 0 and co == 208 then
selected = selected + 1
if selected > #pkgmap then