Add PageUp PageDown support

This commit is contained in:
Kirigaya Kazuto 2018-11-19 19:02:31 +08:00
parent 971314d6cc
commit 745258116b

View File

@ -7,7 +7,7 @@ local term=require('term')
local shell=require('shell')
require('libevent')
local version_tag="Smart Storage v0.5.4"
local version_tag="Smart Storage v0.5.5"
print(version_tag)
print("Checking hardware...")
@ -153,11 +153,11 @@ local function display(tb_data,tb_display,begin_at,filter)
local count_shown=0
for i=begin_at,#tb_display,1 do
local this_table=tb_data[tb_display[i]]
if(filter==nil or string.len(filter)<1 or string.find(this_table.name,filter)~=nil) then
if(filter==nil or string.len(filter)<1) then
local old=gpu.setForeground(0xFFFF00)
gpu.set(1,i-begin_at+3,this_table.name .. " -- " .. this_table.label .. " (" .. this_table.total .. ")")
gpu.setForeground(old)
else
elseif(string.find(this_table.name,filter)~=nil) then
gpu.set(1,i-begin_at+3,this_table.name .. " -- " .. this_table.label .. " (" .. this_table.total .. ")")
end
count_shown=count_shown+1
@ -184,10 +184,24 @@ while true do
need_refresh=false
end
local e=WaitMultipleEvent("interrupted","scroll","touch")
local e=WaitMultipleEvent("interrupted","scroll","touch","key_down")
if(e.event=="interrupted") then
break
elseif(e.event=="key_down") then
local w,h=gpu.getResolution()
if(e.code==201) then -- PageUp
if(begin_at>1) then
begin_at=begin_at-(h-5)
if(begin_at<1) then begin_at=1 end
need_refresh=true
end
elseif(e.code==209) then -- PageDown
if(begin_at+h-5<#tb_display) then
begin_at=begin_at+h-5
need_refresh=true
end
end
elseif(e.event=="scroll") then
-- Scroll Down = -1. Scroll Up = 1
if(e.direction<0) then