Posted 18 November 2012 - 04:57 AM
I launched worm from this program. the color last used by my program became the background.
Program I used
Spoiler
--[[
Light weight mouse FB mini
by BigSHinyToys
]]--
local bRun = true
local sSlash = [[]]
local path = {}
local tItemList = {}
local width,hight = term.getSize()
local listPos = -1
local lastListPos
local pading = string.rep(" ",width)
local function stringPath()
return sSlash..table.concat(path,sSlash)
end
local function newList()
lastListPos = nil
listPos = -1
tItemList = {{n = "..", id = "back"}} -- adds a back item at top of list
sPath = stringPath()
local folders = {}
local files = {}
local disks = {}
local test,list = pcall(fs.list,sPath) -- stopes fs.list crash
if list == nil then
list = {}
end
if #path == 0 then
for i,v in pairs(rs.getSides()) do
if disk.isPresent(v) then
if disk.hasData(v) then
table.insert(tItemList,{n = disk.getMountPath(v), id = "disk",s = v})
disks[disk.getMountPath(v)] = true
elseif disk.hasAudio(v) then
table.insert(tItemList,{n = disk.getAudioTitle(v), id = "audio",s = v})
end
end
end
end
for i,v in pairs(list) do
if fs.isDir(sPath..sSlash..v) then
table.insert(folders,v)
else
table.insert(files,v)
end
end
table.sort(folders)
table.sort(files)
for i,v in pairs(folders) do
if disks[v] == nil then
table.insert(tItemList,{n = v, id = "folder"})
end
end
for i,v in pairs(files) do
table.insert(tItemList,{n = v, id = "file"})
end
end
term.clear()
newList()
local tIcons = {
back = {tCol = "lightGray",bCol = "blue",txt = " < "},
disk = {tCol = "lightGray",bCol = "blue",txt = "[*]"},
audio = {tCol = "yellow",bCol = "red",txt = "(o)"},
folder = {tCol = "lightGray",bCol = "blue",txt = "[=]"},
file = {tCol = "lime",bCol = "green",txt = " "}}
while bRun do
if lastListPos ~= listPos then
for i = 2,hight do
term.setCursorPos(1,i)
local sel = i+listPos
if tItemList[sel] then
term.setBackgroundColor(colors[tIcons[tItemList[sel].id].bCol])
term.setTextColor(colors[tIcons[tItemList[sel].id].tCol])
term.write(string.sub(tIcons[tItemList[sel].id].txt..tItemList[sel].n..pading,1,width))
else
term.write(pading)
end
end
term.setBackgroundColor(colors.lightBlue)
term.setTextColor(colors.blue)
term.setCursorPos(1,1)
term.write(string.sub(stringPath().." "..tostring(listPos).." "..#tItemList.." "..hight..pading,1,width))
lastListPos = listPos
end
local event = {os.pullEvent()}
if event[1] == "mouse_scroll" then
listPos = math.max(math.min(listPos + event[2],(#tItemList+1) - hight),-1)
elseif event[1] == "mouse_click" then
if event[2] == 1 then -- left click
local itemNumber = event[4] + listPos -- to keep it neat
if tItemList[itemNumber] then
if tItemList[itemNumber].id == "folder" or tItemList[itemNumber].id == "disk" then
table.insert(path,tItemList[itemNumber].n)
elseif tItemList[itemNumber].id == "file" then
os.run(getfenv(),stringPath()..sSlash..tItemList[itemNumber].n)
elseif tItemList[itemNumber].id == "back" then
table.remove(path,#path)
end
newList()
end
else -- right click
end
elseif event[1] == "window_resize" then
width,hight = term.getSize()
lastListPos = nil
end
end