Advertisement
SergOmarov

WorkGlasses - виртуальный рабочий стол

Aug 15th, 2015
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.75 KB | None | 0 0
  1. --WorkGlasses - виртуальный рабочий стол
  2. --(c) SergOmarov, 2015
  3. local shell=require("shell")
  4. local event=require("event")
  5. local term=require("term")
  6. local c=require("component")
  7. local computer=require("computer")
  8.  
  9. local chat=c.chat_box
  10. local textFieldsList={}
  11.  
  12. local textFields={}
  13.  
  14. local glasses=c.glasses
  15. local gpu=c.gpu
  16.  
  17. local w,h=gpu.getResolution()
  18.  
  19. local textNull=""
  20. --[[while #text~=w
  21. i=i+1
  22. if(#text<w)then
  23. text=text..text
  24. elseif(#text<w)then
  25. text=string.sub(text,1,#text-1)
  26. end
  27. end
  28. print(i)]]
  29. for i=1,w do
  30. textNull=textNull.." "
  31. end
  32.  
  33. local function reset()
  34. for i=1,h do
  35. textFields[i]=glasses.addTextLabel()
  36. textFields[i].setText(textNull)
  37. textFields[i].setPosition(1,i*7)
  38.  
  39. end
  40. end
  41. reset()
  42. local function get(x,y)
  43. return textFields[y].getText():sub(x,x)
  44. end
  45.  
  46. local function setSimbol(x,y,simbol)
  47. simbol=simbol:sub(1,1)
  48. local textField=textFields[y]
  49. local text0=textField.getText()
  50. local text1=text0:sub(1,x)
  51. local text2=text0:sub(x+1,math.huge)
  52. text0=text1..simbol..text2
  53. textField.setText(text0)
  54.  
  55. end
  56.  
  57. local function set(x,y,text)
  58. local textField=textFields[y]
  59. local text0=textField.getText()
  60. local text1=text0:sub(1,x)
  61. local ltext=#text
  62. local text2=text0:sub(x+#text,math.huge)
  63. text=text1..text..text2
  64. textField.setText(text)
  65. end
  66.  
  67. local function copy(x,y,w,h,x1,y1)
  68. local len=h+y
  69. for i=y,len do
  70. set(x+x1,i+y1,textFields[i].getText():sub(x,x+w))
  71. end
  72. end
  73.  
  74. term.setCursorBlink(false)
  75. term.setCursorBlink=function()end
  76.  
  77. local gpu_set=gpu_set or gpu.set
  78. local gpu_setBackground=gpu_setBackground or gpu.setBackground
  79. local gpu_setForeground=gpu_setForeground or gpu.setForeground
  80. local gpu_copy=gpu_copy or gpu.copy
  81.  
  82. gpu.set=function(x,y,text)
  83. gpu_set(x,y,text)
  84. set(x,y,text)
  85.  
  86. end
  87. gpu.copy=function(x,y,w,h,x1,y1)
  88. gpu_copy(x,y,w,h,x1,y1)
  89. copy(x,y,w,h,x1,y1)
  90.  
  91. end
  92. local glasses_removeAll=glasses.removeAll
  93. glasses.removeAll=function()
  94. glasses_removeAll()
  95. reset()
  96.  
  97. end
  98.  
  99. local term_clearLine=term.clearLine
  100. term.clearLine=function(line)
  101. textFields[line].setText(textNull)
  102. term_clearLine()
  103. end
  104.  
  105. local term_clear=term.clear
  106. term.clear=function()
  107. glasses.removeAll()
  108. term_clear()
  109. end
  110.  
  111. function Set(list)
  112.   local set = {}
  113.   for l=1,#list do set[list[l]] = true end
  114.   return set
  115. end
  116.  
  117. local pullSignal = pullSignal or computer.pullSignal
  118.  
  119. computer.pullSignal = function (...)
  120. local eventObject={pullSignal(...)}
  121. if eventObject[1]=='chat_message' then
  122. local users=Set({computer.users()})
  123. if(users[eventObject[3]])then
  124. local stringS=eventObject[4]
  125. if(stringS:find("--")==1)then
  126. if(stringS:find("/")==3)then
  127. stringS=string.sub(stringS,4,#stringS)
  128. shell.execute(stringS)
  129. else
  130. print(string.sub(stringS,3,#stringS))
  131.  
  132. end
  133.  
  134. end
  135.  
  136. end
  137. end
  138. return table.unpack(eventObject)
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement