Advertisement
pedrosgali

konSoul

Sep 7th, 2014
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.67 KB | None | 0 0
  1. local scr = require("screen")
  2. local shell = require("shell")
  3. local fs = require("filesystem")
  4. local term = require("term")
  5. local comp = require("component")
  6. local keyboard = require("keyboard")
  7. local gpu = comp.gpu
  8. local col = 0x009999
  9. local bCol = 0x000000
  10. local tCol = 0x009900
  11.  
  12. local cs = scr:newPane(cs, 60, 20)
  13. cs.selected = true
  14. cs.priority = 9
  15. cs.label = "konSoul"
  16. cs.isPane = true
  17. cs.colour = col
  18. cs.id = #st + 1
  19. cs.fsx, cs.fsy = gpu.getResolution()
  20. cs.needRender = true
  21. cs.upCount = 0
  22. cs:center()
  23. cs:box(1, 1, cs.width, cs.height, 0x999999, "scale")
  24. cs:box(1, 1, cs.width, 1, col, "scale")
  25. cs:centerText(1, 1, cs.width, col, 0x000000, "konSoul")
  26. cs:inputBox("shell", 2, 3, cs.width - 2, cs.height - 3, "scale", bCol, tCol)
  27. cs.textInputs[1]["text"][1] = shell.getWorkingDirectory().."# "
  28. cs.textInputs[1]["cursorY"] = 1
  29. cs.textInputs[1]["cursorX"] = #cs.textInputs[1]["text"][1] + 1
  30.  
  31. function cs:newLine()
  32.     self.textInputs[1]["cursorY"] = self.textInputs[1]["cursorY"] + 1
  33.     self.textInputs[1]["text"][self.textInputs[1]["cursorY"]] = shell.getWorkingDirectory().."# "
  34.     self.textInputs[1]["cursorX"] = #self.textInputs[1]["text"][self.textInputs[1]["cursorY"]] + 1
  35. end
  36.  
  37. function cs:run(ev, p1, p2, p3, p4, p5)
  38.     if ev == "touch" then
  39.         if self:clicked(p2, p3) then
  40.             self.needRender = true
  41.             if p4 == 0 then
  42.                 if self:textInputClicked(p2, p3) then
  43.                     return true
  44.                 end
  45.             else
  46.                
  47.             end
  48.             self.grabbed = not self.grabbed
  49.             return true
  50.         end
  51.     elseif ev == "drag" then
  52.         if self.grabbed then
  53.             term.clear()
  54.             self:move(p2, p3)
  55.             self.needRender = true
  56.             return true
  57.         end
  58.     elseif ev == "key_down" then
  59.         if self.selected then
  60.             local char = keyboard.keys[p3]
  61.             if char == "enter" then
  62.                 local com = string.sub(self.textInputs[1]["text"][self.textInputs[1]["cursorY"]], #shell.getWorkingDirectory() + 2, #self.textInputs[1]["text"][self.textInputs[1]["cursorY"]])
  63.                 if com == "clear" then
  64.                     self.textInputs = nil
  65.                     cs:inputBox("shell", 2, 3, cs.width - 2, cs.height - 3, "scale", bCol, tCol)
  66.                     self.textInputs[1]["text"][1] = shell.getWorkingDirectory().."# "
  67.                     self.textInputs[1]["cursorY"] = 1
  68.                     self.textInputs[1]["cursorX"] = #self.textInputs[1]["text"][1] + 1
  69.                     self:render()
  70.                     print(com)
  71.                     return true
  72.                 end
  73.                 local bool, err = shell.execute(com)
  74.                 self:newLine()
  75.                 if err ~= nil then
  76.                     self.textInputs[1]["text"][self.textInputs[1]["cursorY"]] = self.textInputs[1]["text"][self.textInputs[1]["cursorY"]].." "..err
  77.                     self:newLine()
  78.                 end
  79.                 self.needRender = true
  80.                 self.upCount = 0
  81.                 return true
  82.             elseif char == "back" then
  83.                 gpu.setBackground(self.textInputs[1]["bgCol"])
  84.                 gpu.setForeground(self.textInputs[1]["fgCol"])
  85.                 if self.textInputs[1]["cursorX"] > #shell.getWorkingDirectory() + 3 then
  86.                     if self.textInputs[1]["cursorX"] <= #self.textInputs[1]["text"][self.textInputs[1]["cursorY"]] then
  87.                         local pLine = self.textInputs[1]["text"][self.textInputs[1]["cursorY"]]
  88.                         local preLine = string.sub(pLine, 1, self.textInputs[1]["cursorX"] - 2)
  89.                         local postLine = string.sub(pLine, self.textInputs[1]["cursorX"], #pLine)
  90.                         self.textInputs[1]["text"][self.textInputs[1]["cursorY"]] = preLine..postLine
  91.                         self.textInputs[1]["cursorX"] = self.textInputs[1]["cursorX"] - 1
  92.                         self.needRender = true
  93.                     else
  94.                         self.textInputs[1]["cursorX"] = self.textInputs[1]["cursorX"] - 1
  95.                         self.textInputs[1]["text"][self.textInputs[1]["cursorY"]] = string.sub(self.textInputs[1]["text"][self.textInputs[1]["cursorY"]], 1, #self.textInputs[1]["text"][self.textInputs[1]["cursorY"]] - 1)
  96.                         self:render()
  97.                     end
  98.                 end
  99.                 gpu.setBackground(0x000000)
  100.                 gpu.setForeground(0xFFFFFF)
  101.                 return true
  102.             elseif char == "up" then
  103.                 if self.upCount < #self.textInputs[1]["text"] - 1 then
  104.                     self.upCount = self.upCount + 1
  105.                     self.textInputs[1]["text"][self.textInputs[1]["cursorY"]] = self.textInputs[1]["text"][self.textInputs[1]["cursorY"] - self.upCount]
  106.                     self.textInputs[1]["cursorX"] = #self.textInputs[1]["text"][self.textInputs[1]["cursorY"]] + 1
  107.                 else
  108.                     self.textInputs[1]["text"][self.textInputs[1]["cursorY"]] = shell.getWorkingDirectory().."# "
  109.                 end
  110.                 self.needRender = true
  111.                 return true
  112.             elseif char == "down" then
  113.                 if self.upCount <= 0 then
  114.                     self.upCount = 0
  115.                     self.textInputs[1]["text"][self.textInputs[1]["cursorY"]] = shell.getWorkingDirectory().."# "
  116.                 else
  117.                     self.upCount = self.upCount - 1
  118.                     self.textInputs[1]["text"][self.textInputs[1]["cursorY"]] = self.textInputs[1]["text"][self.textInputs[1]["cursorY"] - self.upCount]
  119.                 end
  120.                 self.needRender = true
  121.                 return true
  122.             elseif char == "lshift" or char == "rshift" then
  123.                 return true
  124.             elseif char == "left" then
  125.                 if self.textInputs[1]["cursorX"] > #shell.getWorkingDirectory() + 3 then
  126.                     self.textInputs[1]["cursorX"] = self.textInputs[1]["cursorX"] - 1
  127.                 end
  128.                 self.needRender = true
  129.                 return true
  130.             elseif char == "right" then
  131.                 if self.textInputs[1]["cursorX"] < #self.textInputs[1]["text"][self.textInputs[1]["cursorY"]] + 1 then
  132.                     self.textInputs[1]["cursorX"] = self.textInputs[1]["cursorX"] + 1
  133.                 end
  134.                 self.needRender = true
  135.                 return true
  136.             end
  137.             if keyboard.isShiftDown() then
  138.                 self:addText(string.upper(keyboard.keys[p3]))
  139.             else
  140.                 self:addText(keyboard.keys[p3])
  141.             end
  142.             return true
  143.         end
  144.     end
  145.     return false
  146. end
  147.  
  148. st[cs.id] = cs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement