Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sc = peripheral.find("sophisticatedstorage:controller")
- local sto = peripheral.find("sophisticatedstorage:barrel")
- local scSide = "left"
- local stoSide = "right"
- 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 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 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
- win.write(string.sub(j[2],s))
- end
- win.setBackgroundColor(winNormColor.bg)
- win.setTextColor(winNormColor.font)
- end
- local function re_scan()
- tList = sc.list()
- -- for i,j in pairs(tList) do
- -- table.insert(nList,{i, j.name})
- -- end
- local item = nil
- local enchants = {}
- for i,j in pairs(tList) do
- if(string.match(j.name,"minecraft:enchanted_book")~=nil) then
- item = sc.getItemDetail(i)
- enchants = item.enchantments
- for o,k in pairs(enchants) do
- table.insert(nList,{i, k.displayName})
- end
- end
- end
- -- for i,j in pairs(nList) do
- -- if(j[2] == nil ) then
- -- table.remove(nList,i)
- -- end
- -- end
- itemCount = table.getn(nList)
- pageCount = itemCount / mh + 1
- pageIndex = 1
- inPageIndex = 1
- end
- local function sub_scan()
- end
- local function pageChange()
- winList = {}
- local listSize = 0
- if (pageIndex == pageCount) then
- listSize = itemCount % mh
- else listSize = mh end
- local pos = pageIndex * (mh-1)
- for i=1,listSize,1 do
- repeat
- pos = pos + 1
- if(listSize ~= mh) then
- break
- end
- until(nList[pos]~=nil)
- table.insert(winList,{nList[pos][1], nList[pos][2]})
- 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)
- itemCount = table.getn(nList)
- pageCount = (itemCount - itemCount % mh) / mh -1
- 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()
- term.write(winList[inPageIndex][1])
- term.write(winList[inPageIndex][2])
- List_move()
- end
- end
- local keyMap = {
- ["end"]=(function ()
- if(inPageIndex < mh) then
- inPageIndex = inPageIndex + 1
- renewWindow()
- end
- end),
- ["home"]=(function ()
- if(inPageIndex > 1) then
- inPageIndex = inPageIndex - 1
- 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