From 745258116bdfcb5b8f35afe96c34be0adc4ab6ab Mon Sep 17 00:00:00 2001 From: Kiritow <1362050620@qq.com> Date: Mon, 19 Nov 2018 19:02:31 +0800 Subject: [PATCH] Add PageUp PageDown support --- SmartStorage.lua | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/SmartStorage.lua b/SmartStorage.lua index 6cfaa7d..2ff97ce 100644 --- a/SmartStorage.lua +++ b/SmartStorage.lua @@ -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