Advertisement
Guest User

[Computer Craft] Mouse File Browser 0.2 by BigSHinyToys

a guest
Oct 29th, 2012
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.23 KB | None | 0 0
  1. --[[
  2.         file selection and dilog box API / lib / other
  3.         by BigSHinyToys
  4.         note: send link to nightin9ale on CC forums
  5. ]]--
  6.  
  7. local tArgs = {...}
  8. local ver = "0.2"
  9.  
  10. local bugTest = false
  11.  
  12. if tArgs[1] and tArgs[1] == "-d" then
  13.     bugTest = true
  14. end
  15.  
  16. local function clear()
  17.     term.setBackgroundColor(colors.black)
  18.     term.setTextColor(colors.white)
  19.     term.clear()
  20.     term.setCursorBlink(false)
  21.     term.setCursorPos(1,1)
  22. end
  23.  
  24. local function dialogBox(title,message,options)
  25.     term.setCursorBlink(false)
  26.     local selected = 1
  27.     local boxW,boxH = 26,3
  28.     local termX,termY = term.getSize()
  29.     local ofsX,ofsY = (termX/2) - (boxW/2) , (termY/2) - (boxH/2) -- offset from top left
  30.    
  31.     local space = 0
  32.     local range = {}
  33.     for i = 1,#options do
  34.         range[i] = {s = space,f = space + string.len(options[i])}
  35.         space = space + string.len(options[i])+3
  36.     end
  37.     local ofC = (boxW/2) - (space/2)
  38.    
  39.     local function drawBox()
  40.         if term.isColor() then
  41.             term.setTextColor(colors.black)
  42.             term.setCursorPos(ofsX,ofsY)
  43.             term.setBackgroundColor(colors.blue)
  44.             term.write(" "..title..string.rep(" ",boxW-#title-5).."_[]")
  45.             term.setBackgroundColor(colors.red)
  46.             term.setTextColor(colors.white)
  47.             term.write("X")
  48.             term.setCursorPos(ofsX,ofsY+1)
  49.             term.setBackgroundColor(colors.white)
  50.             term.setTextColor(colors.black)
  51.             term.write(" "..message..string.rep(" ",boxW-#message-1))
  52.             term.setCursorPos(ofsX,ofsY+2)
  53.             term.write(string.rep(" ",boxW))
  54.             term.setCursorPos(ofsX,ofsY+3)
  55.            
  56.             term.write(string.rep(" ",boxW))
  57.             for i = 1,#options do
  58.                 if i == selected then
  59.                     term.setBackgroundColor(colors.lightGray)
  60.                     term.setCursorPos(range[i].s + ofC + ofsX - 1,ofsY + 3)
  61.                     term.write("["..options[i].."]")
  62.                     term.setBackgroundColor(colors.white)
  63.                     term.write(" ")
  64.                 else
  65.                     term.setCursorPos(range[i].s + ofC + ofsX - 1,ofsY + 3)
  66.                     term.write(" "..options[i].." ")
  67.                 end
  68.             end
  69.             term.setCursorPos(ofsX + ofC + space,ofsY + 3)
  70.             term.write(string.rep(" ",boxW - (ofC + space)))
  71.             term.setBackgroundColor(colors.black)
  72.             term.setTextColor(colors.white)
  73.         else
  74.            
  75.         end
  76.     end
  77.     while true do
  78.         drawBox()
  79.         event = {os.pullEvent()}
  80.         if event[1] == "key" then
  81.             if event[2] == 203 then -- left
  82.                 selected = selected - 1
  83.                 if selected < 1 then
  84.                     selected = #options
  85.                 end
  86.             elseif event[2] == 205 then -- right
  87.                 selected = selected + 1
  88.                 if selected > #options then
  89.                     selected = 1
  90.                 end
  91.             elseif event[2] == 28 then -- enter
  92.                 return selected , options[selected]
  93.             end
  94.         elseif event[1] == "mouse_click" then
  95.             term.setCursorPos(1,1)
  96.             term.clearLine()
  97.            
  98.             if bugTest then term.write("M "..event[2].." X "..event[3].." Y "..event[4]) end
  99.            
  100.             if event[2] == 1 then
  101.                 if event[4] == ofsY + 3 then
  102.                     for i = 1,#options do
  103.                         if event[3] >= range[i].s + ofC + ofsX - 1 and event[3] <= range[i].f + ofC + ofsX then
  104.                             return i , options[i]
  105.                         end
  106.                     end
  107.                 end
  108.             end
  109.         end
  110.     end
  111. end
  112.  
  113. -- modified read made to play nice with coroutines
  114.  
  115. local sLine = ""
  116.  
  117. local function readMOD( _sReplaceChar, _tHistory,_wdth)
  118.     term.setCursorBlink( true )
  119.  
  120.     local nHistoryPos = nil
  121.     local nPos = 0
  122.     if _sReplaceChar then
  123.         _sReplaceChar = string.sub( _sReplaceChar, 1, 1 )
  124.     end
  125.    
  126.     local w, h = term.getSize()
  127.     if _wdth and type(_wdth) == "number" then
  128.         w = _wdth
  129.     end
  130.     local sx, sy = term.getCursorPos() 
  131.    
  132.     local function redraw( _sCustomReplaceChar )
  133.         local nScroll = 0
  134.         if sx + nPos >= w then
  135.             nScroll = (sx + nPos) - w
  136.         end
  137.            
  138.         term.setCursorPos( sx, sy )
  139.         local sReplace = _sCustomReplaceChar or _sReplaceChar
  140.         if sReplace then
  141.             term.write( string.rep(sReplace, string.len(sLine) - nScroll) )
  142.         else
  143.             term.write( string.sub( sLine, nScroll + 1 ) )
  144.         end
  145.         term.setCursorPos( sx + nPos - nScroll, sy )
  146.     end
  147.    
  148.     while true do
  149.         local sEvent, param = os.pullEvent()
  150.         if sEvent == "char" then
  151.             sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
  152.             nPos = nPos + 1
  153.             redraw()
  154.            
  155.         elseif sEvent == "key" then
  156.             if param == keys.enter then
  157.                 -- Enter
  158.                 -- break
  159.                
  160.             elseif param == keys.left then
  161.                 -- Left
  162.                 if nPos > 0 then
  163.                     nPos = nPos - 1
  164.                     redraw()
  165.                 end
  166.                
  167.             elseif param == keys.right then
  168.                 -- Right               
  169.                 if nPos < string.len(sLine) then
  170.                     nPos = nPos + 1
  171.                     redraw()
  172.                 end
  173.            
  174.             elseif param == keys.up or param == keys.down then
  175.                 -- Up or down
  176.                 if _tHistory then
  177.                     redraw(" ");
  178.                     if param == keys.up then
  179.                         -- Up
  180.                         if nHistoryPos == nil then
  181.                             if #_tHistory > 0 then
  182.                                 nHistoryPos = #_tHistory
  183.                             end
  184.                         elseif nHistoryPos > 1 then
  185.                             nHistoryPos = nHistoryPos - 1
  186.                         end
  187.                     else
  188.                         -- Down
  189.                         if nHistoryPos == #_tHistory then
  190.                             nHistoryPos = nil
  191.                         elseif nHistoryPos ~= nil then
  192.                             nHistoryPos = nHistoryPos + 1
  193.                         end                    
  194.                     end
  195.                    
  196.                     if nHistoryPos then
  197.                         sLine = _tHistory[nHistoryPos]
  198.                         nPos = string.len( sLine )
  199.                     else
  200.                         sLine = ""
  201.                         nPos = 0
  202.                     end
  203.                     redraw()
  204.                 end
  205.             elseif param == keys.backspace then
  206.                 -- Backspace
  207.                 if nPos > 0 then
  208.                     redraw(" ");
  209.                     sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )
  210.                     nPos = nPos - 1                
  211.                     redraw()
  212.                 end
  213.             elseif param == keys.home then
  214.                 -- Home
  215.                 nPos = 0
  216.                 redraw()       
  217.             elseif param == keys.delete then
  218.                 if nPos < string.len(sLine) then
  219.                     redraw(" ");
  220.                     sLine = string.sub( sLine, 1, nPos ) .. string.sub( sLine, nPos + 2 )              
  221.                     redraw()
  222.                 end
  223.             elseif param == keys["end"] then
  224.                 -- End
  225.                 nPos = string.len(sLine)
  226.                 redraw()
  227.             end
  228.         elseif sEvent == "redraw" then
  229.             redraw()
  230.         end
  231.     end
  232.    
  233.     term.setCursorBlink( false )
  234.     -- term.setCursorPos( w + 1, sy )
  235.     -- print()
  236.    
  237.     return sLine
  238. end
  239.  
  240. -- end modified read
  241.  
  242. local function printC(posX,posY,textCol,backCol,text)
  243.     term.setCursorPos(posX,posY)
  244.     term.setTextColor(textCol)
  245.     term.setBackgroundColor(backCol)
  246.     term.write(text)
  247. end
  248.  
  249. local function rClickMenu(title,tList,posX,posY)
  250.  
  251.     term.setCursorBlink(false)
  252.     local BoxTitle = title
  253.     local choices = tList
  254.     local termX,termY = term.getSize()
  255.     local offX,offY
  256.    
  257.     local width = #BoxTitle + 2
  258.     local hight = #choices + 1
  259.    
  260.     for i = 1,#choices do
  261.         if width < #choices[i] + 2 then
  262.             width = #choices[i] + 2
  263.         end
  264.     end
  265.    
  266.     offX,offY = math.ceil((termX/2) - (width/2)),math.ceil((termY/2) - (hight/2))
  267.    
  268.     if posX and posY then -- offX,offY = posX,posY
  269.         if posX >= termX - width - 1 then
  270.             offX = termX - width - 1
  271.         else
  272.             offX = posX
  273.         end
  274.         if posY >= termY - hight then
  275.             offY = termY - hight
  276.         else
  277.             offY = posY
  278.         end
  279.     end
  280.    
  281.     local function reDrawer()
  282.         printC(offX,offY,colors.black,colors.blue," "..BoxTitle..string.rep(" ",width - #BoxTitle - 1))
  283.         for i = 1,#choices do
  284.             printC(offX,offY + i,colors.black,colors.white," "..choices[i]..string.rep(" ",width - #choices[i] - 1))
  285.         end
  286.     end
  287.    
  288.     while true do
  289.         reDrawer()
  290.         local event = {os.pullEvent()}
  291.         if event[1] == "mouse_click" then
  292.             if event[2] == 1 then -- event[3] = x event[4] = y
  293.                 if event[4] > offY and event[4] < hight + offY and event[3] >= offX and event[3] < width + offX then
  294.                     return choices[event[4] - offY]
  295.                 else
  296.                     return
  297.                 end
  298.             elseif event[2] == 2 then
  299.                 return
  300.             end
  301.         end
  302.     end
  303.    
  304. end
  305.  
  306. local function fileSelect(mode) -- save_file open_file browse < not yet implemented
  307.    
  308.     local title = "File Browser "..ver
  309.     local bRun = true
  310.     local flag = true
  311.    
  312.     local termX,termY = term.getSize()
  313.     local offsetX,offsetY = 1,1
  314.     local hight,width = math.ceil(termY-2),math.ceil(termX-2)
  315.     local oldHight,oldWidth
  316.    
  317.     local boxOffX,boxOffY = offsetX,offsetY + 2
  318.     local boxH,boxW = hight - 3 ,width - 2
  319.    
  320.     local barX,barY = offsetX + 1,offsetY + 2
  321.     local barH,barW = 1,width - 1
  322.    
  323.     local tbarX,tbarY = offsetX + 1,offsetY + 1
  324.     local tbarH,tbarW = 1,width - 1
  325.    
  326.     local exitX,exitY = offsetX + width - 1 ,offsetY + 1
  327.    
  328.     local parth = {}
  329.     local list
  330.    
  331.     local fSlash = [[\]]
  332.     local listOff = 0
  333.    
  334.     local function stringParth()
  335.         local temp = fSlash
  336.         for i = 1,#parth do
  337.             if i == #parth then
  338.                 temp = temp..parth[i]
  339.             else
  340.                 temp = temp..parth[i]..fSlash
  341.             end
  342.         end
  343.         return temp
  344.     end
  345.    
  346.     local sParth = stringParth()
  347.     local files = {}
  348.     local folders = {}
  349.     local disks = {}
  350.  
  351.     local function NewList()
  352.         flag = true
  353.         listOff = 0
  354.         sParth = stringParth()
  355.         files = {}
  356.         folders = {}
  357.         disks = {}
  358.         test,list = pcall(fs.list,sParth)
  359.         -- print(" + "..tostring(test).." "..tostring(list))
  360.         for i = 1,#list do
  361.             if fs.isDir(sParth..fSlash..list[i]) then
  362.                 table.insert(folders,list[i])
  363.             else
  364.                 table.insert(files,list[i])
  365.             end
  366.         end
  367.         if #parth == 0 then
  368.             for i,v in pairs(rs.getSides()) do
  369.                 if disk.isPresent(v) and disk.hasData(v) then
  370.                     disks[disk.getMountPath(v)] = v
  371.                 end
  372.             end
  373.         end
  374.         table.sort(disks)
  375.         table.sort(folders)
  376.         table.sort(files)
  377.     end
  378.    
  379.     NewList()
  380.    
  381.     local function size(test)
  382.         if #test > boxW - 3 then
  383.             return string.sub(test,1,boxW-3)
  384.         end
  385.         return test
  386.     end
  387.    
  388.     local tRead = coroutine.create(function()
  389.         term.setCursorPos(boxOffX + 2,boxOffY + boxH + 1)
  390.         readMOD(nil,nil,boxOffX + boxW)
  391.     end)
  392.    
  393.     local function resume(...)
  394.         term.setTextColor(colors.black)
  395.         term.setBackgroundColor(colors.white)
  396.         term.setCursorPos(boxOffX + 1,boxOffY + boxH + 1)
  397.         term.write(string.rep(" ",boxW+1))
  398.         coroutine.resume(tRead,...)
  399.         term.setTextColor(colors.white)
  400.         term.setBackgroundColor(colors.black)
  401.     end
  402.    
  403.    
  404.     while bRun do
  405.         if flag then
  406.             flag = false
  407.             -- clear
  408.             if oldHight ~= hight and oldWidth ~= width then
  409.                 term.setBackgroundColor(colors.black)
  410.                 term.clear()
  411.                 oldHight,oldWidth = hight,width
  412.             end
  413.             -- draw top title bar
  414.             term.setCursorPos(tbarX,tbarY)
  415.             term.setTextColor(colors.black)
  416.             term.setBackgroundColor(colors.blue)
  417.             local b = tbarW - #title -2
  418.             if b < 0 then
  419.                 b = 0
  420.             end
  421.             term.write(string.sub(" "..title,1,tbarW)..string.rep(" ",b))
  422.             term.setTextColor(colors.white)
  423.             term.setBackgroundColor(colors.red)
  424.             term.write("X")
  425.            
  426.             -- draw location bar
  427.            
  428.             term.setCursorPos(barX,barY)
  429.             term.setTextColor(colors.black)
  430.             term.setBackgroundColor(colors.lightGray)
  431.             local a = barW - #sParth - 1
  432.             if a < 0 then
  433.                 a = 0
  434.             end
  435.             term.write(string.sub(" "..sParth,1,barW)..string.rep(" ",a))
  436.            
  437.             -- draw scroll bar
  438.            
  439.             if #folders + #files > boxH then
  440.                 term.setBackgroundColor(colors.lightGray)
  441.                 for i = 1,boxH do
  442.                     term.setCursorPos(boxOffX+boxW+1,i + boxOffY)
  443.                     local scroll = math.floor( boxH* (listOff/(#folders + #files-boxH+2)) )+1
  444.                     if i == scroll then
  445.                         term.setBackgroundColor(colors.gray)
  446.                         term.write(" ")
  447.                         term.setBackgroundColor(colors.lightGray)
  448.                     else
  449.                         term.write(" ")
  450.                     end
  451.                 end
  452.             else
  453.                 term.setBackgroundColor(colors.gray)
  454.                 for i = 1,boxH do
  455.                     term.setCursorPos(boxOffX+boxW+1,i + boxOffY)
  456.                     term.write(" ")
  457.                 end
  458.             end
  459.            
  460.             -- draw main section
  461.            
  462.             term.setTextColor(colors.black)
  463.             term.setBackgroundColor(colors.cyan)
  464.             for i = 1,boxH do
  465.                 term.setCursorPos(1+boxOffX,i+boxOffY)
  466.                 if folders[i+listOff] then
  467.                     if disks[folders[i+listOff]] then
  468.                         term.setTextColor(colors.orange)
  469.                         term.setBackgroundColor(colors.blue)
  470.                         term.write("D!")
  471.                     else
  472.                         term.setTextColor(colors.blue)
  473.                         term.setBackgroundColor(colors.lightBlue)
  474.                         term.write("[]")
  475.                     end
  476.                     term.setTextColor(colors.black)
  477.                     term.setBackgroundColor(colors.cyan)
  478.                     local repTimes = boxW - #folders[i+listOff] - 3
  479.                     if repTimes < 0 then
  480.                         repTimes = 0
  481.                     end
  482.                     term.write(" "..size(folders[i+listOff])..string.rep(" ",repTimes))
  483.                 elseif files[i-#folders+listOff] then
  484.                     local repTimes = boxW - #files[i-#folders+listOff] - 3
  485.                     if repTimes < 0 then
  486.                         repTimes = 0
  487.                     end
  488.                     term.write("   "..size(files[i-#folders+listOff])..string.rep(" ",repTimes))
  489.                 else
  490.                     term.write(string.rep(" ",boxW))
  491.                 end
  492.             end
  493.             term.setTextColor(colors.white)
  494.             term.setBackgroundColor(colors.black)
  495.            
  496.             if bugTest then
  497.                 term.setCursorPos(1,1)
  498.                 term.write(listOff.." "..boxOffY.." "..boxH)
  499.             end
  500.            
  501.             resume("redraw")
  502.         end
  503.         -- react to events
  504.        
  505.         local event = {os.pullEvent()}
  506.        
  507.         if event[1] == "mouse_click" then
  508.             if event[2] == 1 then -- left mouse
  509.                 local temp = nil
  510.                 if event[4] > boxOffY and event[4] <= boxH + boxOffY then
  511.                     temp = folders[event[4]+listOff-boxOffY] or files[event[4]-#folders+listOff-boxOffY]
  512.                 end
  513.                 if temp and event[3] > boxOffX and event[3] <= #temp + 3 + boxOffX and event[3] < boxOffX + boxW then
  514.                     if fs.isDir(stringParth()..fSlash..temp) then
  515.                         table.insert(parth,temp)
  516.                         NewList()
  517.                     else
  518.                         if fs.exists(stringParth()..fSlash..temp) then
  519.                             if dialogBox("Run file ?",temp,{"yes","no"}) == 1 then
  520.                                 local test,info = shell.run(stringParth()..fSlash..temp)
  521.                                 term.setCursorBlink(false)
  522.                                 if not test then
  523.                                     dialogBox("ERROR",tostring(info),{"ok"})
  524.                                 end
  525.                             end
  526.                             flag = true
  527.                         end
  528.                     end
  529.                 elseif event[3] == boxOffX+boxW+1 and event[4] > boxOffY and event[4] <= boxOffY+boxH then
  530.                     if #folders + #files > boxH then
  531.                         if event[4] == boxOffY + 1 then
  532.                             listOff = 0
  533.                         elseif event[4] == boxOffY+boxH then
  534.                             listOff = #folders + #files + 1 - boxH
  535.                         else
  536.                             listOff = math.ceil((event[4] - boxOffY - 1 )*(((#folders + #files - boxH+2)/boxH)))
  537.                         end
  538.                         flag = true
  539.                     end
  540.                 elseif event[3] == exitX and event[4] == exitY then
  541.                     if dialogBox("Confirm","Exit application",{"yes","no"}) == 1 then
  542.                         bRun = false
  543.                     end
  544.                     flag = true
  545.                 end
  546.             elseif event[2] == 2 then -- right mouse
  547.                 local temp = nil
  548.                 if event[4] > boxOffY and event[4] <= boxH + boxOffY then
  549.                     temp = folders[event[4]+listOff-boxOffY] or files[event[4]-#folders+listOff-boxOffY]
  550.                 end
  551.                 if temp and event[3] > boxOffX and event[3] <= #temp + 3 + boxOffX and event[3] < boxOffX + boxW then
  552.                     local sType = "File"
  553.                    
  554.                     if fs.isDir(stringParth()..fSlash..temp) then
  555.                         sType = "Folder"
  556.                     end
  557.                    
  558.                     local sChoice = nil
  559.                    
  560.                     if disks[temp] then
  561.                         sChoice = rClickMenu("Options",{"Open","Eject"},event[3]+1,event[4]+1)
  562.                     else
  563.                         if sType == "Folder" then
  564.                             sChoice = rClickMenu("Options",{"Open","Delete"},event[3]+1,event[4]+1)
  565.                         else
  566.                             sChoice = rClickMenu("Options",{"Run","Run CMD","Edit","Paint","Delete"},event[3]+1,event[4]+1)
  567.                         end
  568.                     end
  569.                    
  570.                     if sChoice == "Open" then
  571.                         table.insert(parth,temp)
  572.                         NewList()
  573.                     elseif sChoice == "Run" then
  574.                         clear()
  575.                         local test,info = shell.run(stringParth()..fSlash..temp)
  576.                         term.setCursorBlink(false)
  577.                         if not test then
  578.                             dialogBox("ERROR",tostring(info),{"ok"})
  579.                         end
  580.                     elseif sChoice == "Run CMD" then
  581.                         clear()
  582.                         print("Enter Commands")
  583.                         local cmd = read()
  584.                         clear()
  585.                         local test,info = shell.run(stringParth()..fSlash..temp,cmd)
  586.                         term.setCursorBlink(false)
  587.                         if not test then
  588.                             dialogBox("ERROR",tostring(info),{"ok"})
  589.                         end
  590.                     elseif sChoice == "Edit" then
  591.                         if sType == "File" then
  592.                             shell.run("edit",stringParth()..fSlash..temp) -- stringParth()..fSlash..temp
  593.                         else
  594.                             dialogBox("ERROR","Can't edit a Folder",{"ok"})
  595.                         end
  596.                     elseif sChoice == "Delete" then
  597.                         if dialogBox("Confirm","Delete "..sType.." "..temp,{"yes","no"}) == 1 then
  598.                             if fs.isReadOnly(stringParth()..fSlash..temp) then
  599.                                 dialogBox("ERROR",sType.." Is read Only",{"ok"})
  600.                             else
  601.                                 fs.delete(stringParth()..fSlash..temp)
  602.                                 NewList()
  603.                             end
  604.                         end
  605.                     elseif sChoice == "Paint" then
  606.                         if sType == "File" then
  607.                             shell.run("paint",stringParth()..fSlash..temp)
  608.                         else
  609.                             dialogBox("ERROR","Can't edit a Folder",{"ok"})
  610.                         end
  611.                     elseif sChoice == "Eject" then
  612.                         if dialogBox("Confirm","Eject disk "..disks[temp].." "..fSlash..temp,{"yes","no"}) == 1 then
  613.                             disk.eject(disks[temp])
  614.                             NewList()
  615.                         end
  616.                     end
  617.                     flag = true
  618.                 else
  619.                     table.remove(parth,#parth)
  620.                     NewList()
  621.                 end
  622.             end
  623.         elseif event[1] == "mouse_scroll" then -- flag
  624.             local old = listOff
  625.             listOff = listOff + event[2]
  626.             if listOff < 0 then
  627.                 listOff = 0
  628.             end
  629.             if #folders + #files + 1 - boxH > 0 and listOff > #folders + #files + 1 - boxH then
  630.                 listOff = #folders + #files + 1 - boxH
  631.             elseif listOff > 0 and #folders + #files + 1 - boxH < 0 then
  632.                 listOff = 0
  633.             end
  634.             if listOff ~= old then
  635.                 flag = true
  636.             end
  637.            
  638.         elseif event[1] == "key" then
  639.             --[[
  640.             if event[2] == 200 then boxOffY = boxOffY -1 -- up
  641.             elseif event[2] == 208 then boxOffY = boxOffY +1 -- down
  642.             elseif event[2] == 203 then boxOffX = boxOffX -1 -- left
  643.             elseif event[2] == 205 then boxOffX = boxOffX +1 -- right
  644.             end
  645.             ]]--
  646.             resume(unpack(event))
  647.             flag = true
  648.            
  649.         elseif event[1] == "char" then
  650.             --[[
  651.             if event[2] == "w" then boxH = boxH + 1
  652.             elseif event[2] == "s" then boxH = boxH - 1
  653.             elseif event[2] == "a" then boxW = boxW - 1
  654.             elseif event[2] == "d" then boxW = boxW + 1
  655.             end
  656.             ]]--
  657.             resume(unpack(event))
  658.             flag = true
  659.            
  660.         elseif event[1] == "disk" or event[1] == "disk_eject" then
  661.             NewList()
  662.         elseif event[1] == "window_resize" then
  663.             termX,termY = term.getSize()
  664.             offsetX,offsetY = 1,1
  665.             hight,width = math.ceil(termY-2),math.ceil(termX-2)
  666.            
  667.             boxOffX,boxOffY = offsetX,offsetY + 2
  668.             boxH,boxW = hight - 3 ,width - 2
  669.            
  670.             barX,barY = offsetX + 1,offsetY + 2
  671.             barH,barW = 1,width - 1
  672.            
  673.             tbarX,tbarY = offsetX + 1,offsetY + 1
  674.             tbarH,tbarW = 1,width - 1
  675.            
  676.             exitX,exitY = offsetX + width - 1 ,offsetY + 1
  677.            
  678.             flag = true
  679.         end
  680.     end
  681. end
  682.  
  683.  
  684.  
  685. clear()
  686.  
  687. fileSelect(mode)
  688. clear()
  689.  
  690.  
  691. --[[
  692. local test = {
  693. {t = "test1",m = "is the working",s = {"yes","no"}},
  694. {t = "test2",m = "is everthing ok",s = {"ok"}},
  695. }
  696.  
  697. for i = 1, #test do
  698.     local n,word = dialogBox(test[i].t,test[i].m,test[i].s)
  699.     print(n.." "..word)
  700. end
  701. ]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement