From 478ea016ed3d259e85e428521b37df6980692f56 Mon Sep 17 00:00:00 2001 From: Kiritow <1362050620@qq.com> Date: Mon, 19 Nov 2018 17:49:52 +0800 Subject: [PATCH] Smart Storage supports filter --- SmartStorage.lua | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/SmartStorage.lua b/SmartStorage.lua index 9469260..bd9d833 100644 --- a/SmartStorage.lua +++ b/SmartStorage.lua @@ -142,19 +142,21 @@ local function display_single(tb_data,tb_display,which_one,display_at) gpu.set(1,display_at,this_table.name .. " -- " .. this_table.label .. " (" .. this_table.total .. ")") end -local function display(tb_data,tb_display,begin_at) +local function display(tb_data,tb_display,begin_at,filter) local w,h=gpu.getResolution() gpu.fill(1,1,w,h-1,' ') -- Status bar is not cleared gpu.set(1,1,version_tag) gpu.fill(1,2,w,1,'-') gpu.fill(1,h-2,w,1,'-') - gpu.set(1,h-1," ") + gpu.set(1,h-1," ") local count_shown=0 for i=begin_at,#tb_display,1 do - count_shown=count_shown+1 local this_table=tb_data[tb_display[i]] - gpu.set(1,i-begin_at+3,this_table.name .. " -- " .. this_table.label .. " (" .. this_table.total .. ")") + if(string.find(this_table,filter)~=nil) then + gpu.set(1,i-begin_at+3,this_table.name .. " -- " .. this_table.label .. " (" .. this_table.total .. ")") + count_shown=count_shown+1 + end if(i-begin_at+3>=h-3) then break end end @@ -167,12 +169,14 @@ print("Smart Storage System Starting...") status("Scanning...") local result=full_scan() local tb_display=GetDisplayTable(result) +local begin_at_old=1 local begin_at=1 +local item_filter='' local need_refresh=true while true do if(need_refresh) then - display(result,tb_display,begin_at) + display(result,tb_display,begin_at,item_filter) need_refresh=false end @@ -211,6 +215,24 @@ while true do tb_display=GetDisplayTable(result) begin_at=1 + need_refresh=true + elseif(e.x<=string.len(" ")) then + term.setCursor(1,h-1) + term.clearLine() + io.write("Filter: ") + item_filter=io.read() + if(item_filter~=nil and string.len(item_filter)>0) then + begin_at_old=begin_at + begin_at=1 + else + begin_at=begin_at_old + end + + need_refresh=true + elseif(e.x<=string.len(" ")) then + item_filter='' + begin_at=begin_at_old + need_refresh=true end elseif(e.y>=3 and e.y<=h-3) then