From e41c4564d6ceadeaaa19cccd6dbc5a1a0f841129 Mon Sep 17 00:00:00 2001 From: Kiritow <1362050620@qq.com> Date: Tue, 20 Nov 2018 00:09:10 +0800 Subject: [PATCH] Update SmartStorage --- SmartStorage.lua | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/SmartStorage.lua b/SmartStorage.lua index 3a920a4..761e985 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.6" +local version_tag="Smart Storage v0.5.7" print(version_tag) print("Checking hardware...") @@ -126,6 +126,17 @@ local function GetDisplayTable(result) return keys end +local function GetDisplayTableFiltered(result,filter) + local keys={} + for k,v in pairs(result) do + if(k~="slot_used" and k~="slot_total" and string.find(k,filter)~=nil) then + table.insert(keys,k) + end + end + table.sort(keys) + return keys +end + --[[ Display Design 1: Smart Storage (version info etc.) 2: ------------ (window title here) ------------ @@ -173,11 +184,11 @@ 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,item_filter) @@ -239,19 +250,22 @@ while true do 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 + tb_display=GetDisplayTableFiltered(result,item_filter) 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 + elseif(e.x<=string.len(" ")) then + if(item_filter~=nil and string.len(item_filter)>0) then + item_filter='' + + tb_display=GetDisplayTable(result) + begin_at=1 + + need_refresh=true + end end elseif(e.y>=3 and e.y<=h-3) then if(begin_at+e.y-3<=#tb_display) then