Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local LINE_MAX = 10
- function needArgFunc(target)
- if target.func then
- return true
- end
- return false
- end
- function canOpen(target)
- if type(target) == "table" then
- return true
- end
- if type(target) == "function" then
- local suc,ft = pcall(target)
- return canOpen(ft)
- end
- return false
- end
- function isCutingString(data)
- if type(data) == "string" and string.len(data) > 10 then
- return true
- end
- return false
- end
- function open(target)
- if type(target) == "table" then
- local op = {}
- for k, v in pairs(target) do
- local additem = {name = k,data = v}
- if type(v) == "function" then
- local suc,data = pcall(v)
- additem["data"] = data
- additem["func"] = v
- additem["suc"] = suc
- end
- op[#op+1] = additem
- end
- return op
- end
- if type(target) == "function" then
- local suc,ft = pcall(target)
- return open(ft)
- end
- return {}
- end
- function slidePos(nx)
- local x,y = term.getCursorPos()
- term.setCursorPos(nx, y)
- end
- function writeClrMax(str,clr,max)
- writeClr(string.sub(str,1,max),clr)
- if string.len(str) > max then
- writeClr("~",colors.orange)
- end
- end
- function writeClr(str,clr)
- term.setTextColor(clr)
- write(str)
- term.setTextColor(colors.white)
- end
- function viewFolders(folders)
- if #folders - 1 > 0 then
- writeClr(folders[#folders-1].name.." > ",colours.grey)
- end
- writeClr(folders[#folders].name.."\n",colors.white)
- end
- function writeItemData(data)
- if data and type(data) == "table" then
- return writeClr("{}",colors.yellow)
- end
- return writeClrMax(tostring(data),colors.white,10)
- end
- function writeFucnData(item)
- if item.func and not item.suc then
- writeClr("func error",colors.red)
- else
- writeItemData(item.data)
- end
- end
- function writeItem(item)
- if item.func then
- writeClr(item.name.."() = ",colors.pink)
- writeFucnData(item)
- write("\n")
- return
- end
- if type(item.data) == "table" then
- writeClr(item.name.." {}\n",colors.yellow)
- return
- end
- writeClr(item.name.." = ",colors.white)
- writeClrMax(tostring(item.data),colors.white,10)
- write("\n")
- end
- function viewItems(list,cursol,slide)
- if not list then write("not datas") end
- for i, v in ipairs(list) do
- if i - slide > 0 and i - slide <= LINE_MAX then
- if i == cursol then
- write(">")
- end
- slidePos(3)
- writeItem(v)
- end
- end
- end
- function initRoot()
- local re = {}
- for i, v in ipairs(peripheral.getNames()) do
- local newitem = {}
- re[#re+1] = {name = v,data = peripheral.wrap(v)}
- end
- return re
- end
- function viewArgs(Arguments,cursol)
- for i, v in ipairs(Arguments) do
- if i == cursol then
- write(">")
- end
- slidePos(3)
- writeClr("arg"..i,colors.white)
- slidePos(8)
- writeItemData(v.arg)
- write("\n")
- end
- if (#Arguments + 1) == cursol then
- write(">")
- end
- slidePos(3)
- writeClr("ADD ARGUMENT\n",colors.lime)
- end
- function initArgus(target,folders)
- return {}
- end
- function SetArgumentMode(target,folders)
- local arguments = initArgus()
- local cursol = 1
- while true do
- ----------------------------------
- term.clear()
- term.setCursorPos(1, 1)
- writeClr("SET ARGUMENTS MODE"..cursol,colors.purple)
- viewFolders(folders)
- writeClr(target.name.."() = ",colors.pink)
- writeItemData(target.data)
- write("\n")
- viewArgs(arguments,cursol)
- ----------------------------------
- local eve = {os.pullEvent()}
- if eve[1] == "key" then
- if eve[2] == 208 then -- up key
- cursol = math.min(cursol+1,#arguments+1)
- end
- if eve[2] == 200 then -- down key
- cursol = math.max(cursol-1,1)
- end
- if eve[2] == 205 then -- right key
- end
- if eve[2] == 203 then -- left key
- return
- end
- if eve[2] == 57 or eve[2] == 28 then -- space key
- if cursol == #arguments + 1 then
- arguments[#arguments + 1] = {}
- else
- term.setCursorPos(8,cursol+2)
- write(" ")
- term.setCursorPos(8,cursol+2)
- arguments[cursol].arg=read()
- local suc,rt = pcall(target.func,unpack(arguments))
- target.data = rt
- target.suc = suc
- end
- end
- end
- end
- end
- local folders = {}
- folders[1]= {name="root",folder=initRoot()}
- local cursol = 1
- local slide = 0
- while true do
- -------------------------------------
- term.clear()
- term.setCursorPos(1, 1)
- --write("Dc="..cursol.."/s="..slide)
- viewFolders(folders)
- viewItems(folders[#folders].folder,cursol,slide)
- -------------------------------------
- local nowSelectItem = folders[#folders].folder[cursol]
- local eve = {os.pullEvent()}
- if eve[1] == "key" then
- if eve[2] == 208 then -- up key
- cursol = math.min(cursol + 1,#folders[#folders].folder)
- slide = math.max(slide,cursol-LINE_MAX)
- end
- if eve[2] == 200 then -- down key
- cursol = math.max(cursol - 1,1)
- slide = math.min(slide,cursol - 1)
- end
- if eve[2] == 205 then -- right key
- if isCutingString( nowSelectItem.data ) then
- writeClr( nowSelectItem.data,colors.green )
- os.pullEvent("key")
- end
- end
- if eve[2] == 203 then -- left key
- if folders[#folders].name ~= "root" then
- table.remove(folders,#folders)
- cursol = 1
- slide = 0
- end
- end
- if eve[2] == 30 then ---a
- if needArgFunc( nowSelectItem ) then
- SetArgumentMode(nowSelectItem,folders)
- end
- end
- if eve[2] == 57 or eve[2] == 28 then -- space key
- if canOpen( nowSelectItem.data ) then
- local newFld = {}
- newFld["name"] = nowSelectItem.name
- newFld["folder"] = open( nowSelectItem.data )
- folders[#folders+1] = newFld
- cursol = 1
- slide = 0
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement