Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local scSide = "top"
- local stoSide = "back"
- local sto = peripheral.wrap(stoSide)
- local sc = peripheral.wrap(scSide)
- local mw = 51
- local mh = 16
- local topBar = window.create(term.current(),1 ,1 ,mw,1)
- local win = window.create(term.current(), 1,2,mw,mh)
- local pageIndex = 0
- local inPageIndex = 0
- local pageCount = 0
- local itemCount = 0
- local listSize = 0
- local winNormColor = {
- font = colors.black,
- bg = colors.lime
- }
- local winFocusColor = {
- font = colors.gray,
- bg = colors.pink
- }
- topBar.setBackgroundColor(colors.orange)
- topBar.setTextColor(colors.white)
- win.setBackgroundColor(winNormColor.bg)
- win.setTextColor(winNormColor.font)
- local nList = {}
- local function LDebug(str,col)
- term.setCursorPos(1,col)
- term.setTextColor(colors.orange)
- term.setBackgroundColor(colors.white)
- term.clearLine()
- term.write(str)
- end
- local function paraseCMD()
- end
- local function renewTopBar()
- local str = string.format("%3d/%3d size:%d",pageIndex,pageCount,itemCount)
- topBar.clear()
- topBar.setCursorPos(1,1)
- topBar.write(str)
- end
- -- index, name
- local winList = {}
- local function renewWindow()
- win.clear()
- local s = 0
- for i,j in pairs(winList) do
- win.setCursorPos(1,i)
- if(i == inPageIndex) then
- win.setBackgroundColor(winFocusColor.bg)
- win.setTextColor(winFocusColor.font)
- win.clearLine()
- else
- win.setBackgroundColor(winNormColor.bg)
- win.setTextColor(winNormColor.font)
- end
- s = string.find(j[2],":")
- win.write(i..string.sub(j[2],s+1))
- end
- win.setBackgroundColor(winNormColor.bg)
- win.setTextColor(winNormColor.font)
- end
- local function re_count()
- itemCount = table.getn(nList)
- pageCount = (itemCount - itemCount % mh)/mh
- if(itemCount % mh ~= 0) then
- pageCount = pageCount +1
- end
- end
- local function re_scan()
- tList = sc.list()
- for i,j in pairs(tList) do
- table.insert(nList,{i, j.name})
- end
- for i,j in pairs(nList) do
- if(j[2] == nil ) then
- table.remove(nList,i)
- end
- end
- re_count()
- pageIndex = 1
- inPageIndex = 1
- end
- local function sub_scan()
- end
- local function pageChange()
- winList = {}
- local tMod = itemCount % mh
- if (pageIndex == pageCount and tMod ~= 0) then
- listSize = tMod
- else listSize = mh end
- local pos = (pageIndex - 1) * mh
- -- LDebug("listSize "..listSize.."itemCOunt "..itemCount, 19)
- for i=1,listSize,1 do
- repeat
- pos = pos + 1
- if(pos > itemCount) then
- break
- end
- until(nList[pos]~=nil)
- if(pos > itemCount) then
- break
- end
- table.insert(winList,{nList[pos][1], nList[pos][2]})
- end
- -- LDebug("endPos "..pos,18)
- if(inPageIndex > listSize)then
- inPageIndex = listSize
- end
- end
- local function List_move()
- local pos = winList[inPageIndex][1]
- sc.pushItems(stoSide,pos)
- for i,j in pairs(nList) do
- if(j[1] == pos) then
- table.remove(nList,i)
- end
- end
- -- table.remove(nList,pageIndex * mh + inPageIndex)
- re_count()
- if(pageIndex >= pageCount) then
- pageIndex = pageCount
- if(inPageIndex <= itemCount % mh) then
- inPageIndex = itemCount % mh
- end
- end
- pageChange()
- renewTopBar()
- renewWindow()
- end
- local function init()
- re_scan()
- -- gen winList
- pageChange()
- renewTopBar()
- renewWindow()
- end
- local function mainloop()
- term.clear()
- init()
- while true do
- term.setCursorPos(1,18)
- term.setTextColour(colors.white)
- local cmd = io.read()
- term.clearLine()
- List_move()
- end
- end
- local keyMap = {
- ["end"]=(function ()
- if(inPageIndex < mh and inPageIndex < listSize) then
- inPageIndex = inPageIndex + 1
- -- LDebug("nowPos "..(pageIndex-1) * mh + inPageIndex,18)
- renewWindow()
- end
- end),
- ["home"]=(function ()
- if(inPageIndex > 1) then
- inPageIndex = inPageIndex - 1
- -- LDebug("nowPos "..(pageIndex-1) * mh + inPageIndex,18)
- renewWindow()
- end
- end),
- ["pageUp"]=(function ()
- if(pageIndex > 1) then
- inPageIndex = 1
- pageIndex = pageIndex - 1
- pageChange()
- renewTopBar()
- renewWindow()
- end
- end),
- ["pageDown"]=(function ()
- if(pageIndex < pageCount) then
- inPageIndex = 1
- pageIndex = pageIndex + 1
- pageChange()
- renewTopBar()
- renewWindow()
- end
- end),
- }
- local function key_check()
- while true do
- local event, key, isHeld = os.pullEvent("key")
- local kvalue = keys.getName(key)
- if(keyMap[kvalue]~= nil) then
- keyMap[kvalue]()
- term.setTextColour(colors.white)
- term.setCursorPos(1,18)
- end
- end
- end
- parallel.waitForAny(mainloop,key_check)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement