Guest User

Untitled

a guest
Jan 5th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.30 KB | None | 0 0
  1. term.setCursorBlink(true)
  2. text=""
  3. leftShift=false
  4.  
  5. lines={"hello!","how you do","l3","l4","l5","l6","l7","l8"}
  6. cursory=1
  7. cursorx=1
  8.  
  9. renderc=1
  10. function strsplit(inputstr, sep)
  11.         if sep == nil then
  12.                 sep = "%s"
  13.         end
  14.         local t={} ; i=1
  15.         for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  16.                 t[i] = str
  17.                 i = i + 1
  18.         end
  19.         return t
  20. end
  21. function insertPos(position,strun,insert)
  22.     part1=""
  23.     part2=""
  24.     for i = 1, strun:len() do
  25.         if i <= position then
  26.             part1=part1..strun:sub(i,i)
  27.         else
  28.             part2=part2..strun:sub(i,i)
  29.         end
  30.     end
  31.     return part1..insert..part2
  32. end
  33. function removePos(position,strun)
  34.     part1=""
  35.     part2=""
  36.     for i = 1, strun:len() do
  37.         if i <= position then
  38.             part1=part1..strun:sub(i,i)
  39.         else
  40.             part2=part2..strun:sub(i,i)
  41.         end
  42.     end
  43.     return part1:sub(1,-2)..part2
  44. end
  45. function tablelength(T)
  46.   local count = 0
  47.   for _ in pairs(T) do count = count + 1 end
  48.   return count
  49. end
  50. function shiftTable()
  51.     x=0
  52.     lines[tablelength(lines)+1]=lines[tablelength(lines)]
  53.     --tmp=lines[cursory+1]
  54.     for i=cursorx,tablelength(lines) do
  55.         x=(tablelength(lines)*-1+i-1)*-1
  56.         if x > cursory+3 then
  57.  
  58.             lines[x]=lines[x-1]
  59.         end
  60.     end
  61.     --lines[cursory]=tmp
  62.     --print(x-1)
  63.  
  64. end
  65. --[[strun="hello"
  66. position=2
  67. part1=""
  68.     part2=""
  69.     for i = 1, strun:len() do
  70.         if i <= position then
  71.             part1=part1..strun:sub(i,i)
  72.         else
  73.             part2=part2..strun:sub(i,i)
  74.         end
  75.     end
  76.  
  77.     print(part1.."1"..part2)
  78. ]]
  79. function makeRenderObjects()
  80. renderc=1
  81. renderObjects={}
  82. for k,v in pairs(lines) do
  83.  
  84.     beginp, endp = string.find(lines[k], 'function')
  85.     if beginp ~= nil then
  86.         for i = beginp, endp do
  87.             lines[k]=string.gsub(lines[k],'function','        ')
  88.         end
  89.         renderObjects[renderc] = {}
  90.         renderObjects[renderc]['text']="function"
  91.         renderObjects[renderc]['x'] = beginp
  92.         renderObjects[renderc]['y'] = k
  93.         renderObjects[renderc]['color']=colors.blue
  94.         os.setComputerLabel("yeak ok")
  95.     end
  96.  
  97. end
  98. end
  99.  
  100. shiftTable =
  101. {
  102.     [41]="~",
  103.     [2]="!",
  104.     [3]="@",
  105.     [4]="#",
  106.     [5]="$",
  107.     [6]="%",
  108.     [7]="^",
  109.     [8]="&",
  110.     [9]="*",
  111.     [10]="(",
  112.     [11]=")",
  113.     [12]="_",
  114.     [13]="+",
  115.     [16]="Q",
  116.     [17]="W",
  117.     [18]="E",
  118.     [19]="R",
  119.     [20]="T",
  120.     [21]="Y",
  121.     [22]="U",
  122.     [23]="I",
  123.     [24]="O",
  124.     [25]="P",
  125.     [26]="{",
  126.     [27]="}",
  127.     [43]="|",
  128.     [30]="A",
  129.     [31]="S",
  130.     [32]="D",
  131.     [33]="F",
  132.     [34]="G",
  133.     [35]="H",
  134.     [36]="J",
  135.     [37]="K",
  136.     [38]="L",
  137.     [39]=":",
  138.     [40]="\"",
  139.     [44]="Z",
  140.     [45]="X",
  141.     [46]="C",
  142.     [47]="V",
  143.     [48]="B",
  144.     [49]="N",
  145.     [50]="M",
  146.     [51]="<",
  147.     [52]=">",
  148.     [53]="?",
  149. }
  150. codeConversionTable =
  151. {
  152.  
  153.     [41]="`",
  154.     [2]="1",
  155.     [3]="2",
  156.     [4]="3",
  157.     [5]="4",
  158.     [6]="5",
  159.     [7]="6",
  160.     [8]="7",
  161.     [9]="8",
  162.     [10]="9",
  163.     [11]="0",
  164.     [12]="-",
  165.     [13]="=",
  166.     [16]="q",
  167.     [17]="w",
  168.     [18]="e",
  169.     [19]="r",
  170.     [20]="t",
  171.     [21]="y",
  172.     [22]="u",
  173.     [23]="i",
  174.     [24]="o",
  175.     [25]="p",
  176.     [26]="[",
  177.     [27]="]",
  178.     [43]="\\",
  179.     [30]="a",
  180.     [31]="s",
  181.     [32]="d",
  182.     [33]="f",
  183.     [34]="g",
  184.     [35]="h",
  185.     [36]="j",
  186.     [37]="k",
  187.     [38]="l",
  188.     [39]=";",
  189.     [40]="'",
  190.     [44]="z",
  191.     [45]="x",
  192.     [46]="c",
  193.     [47]="v",
  194.     [48]="b",
  195.     [49]="n",
  196.     [50]="m",
  197.     [51]=",",
  198.     [52]=".",
  199.     [53]="/",
  200.     [57]=" ",
  201.  
  202. }
  203.  
  204. --EditiorSTATE variables--
  205. --renderer re-write 2--
  206. uioff=2
  207. renderObjects={}
  208.  
  209. function uiDrawer()
  210.     paintutils.drawFilledBox(1,1,51,2,colors.lightGray)
  211.     term.setCursorPos(1,1)
  212.     term.write("File  Op1  Op2")
  213.     term.setCursorPos(4,2)
  214.     term.setBackgroundColor(colors.gray)
  215.     term.write("main.lua")
  216.  
  217. end
  218. function render()
  219.     --term.write(lines[k])
  220.     renderObjects={}
  221.     makeRenderObjects()
  222.     for k,v in pairs(lines) do
  223.         term.setBackgroundColor(colors.gray)
  224.         term.setCursorPos(1,k+uioff)
  225.         term.write(k)
  226.         --term.setBackgroundColor(colors.gray)
  227.         term.setCursorPos(4,k+uioff)
  228.         term.write(lines[k])
  229.  
  230.     end
  231.  
  232.     for k,v in pairs(renderObjects) do
  233.         os.setComputerLabel("yeak ok")
  234.         term.setCursorPos(renderObjects[k]['x']+3,renderObjects[k]['y']+uioff)
  235.         term.setTextColor(renderObjects[k]['color'])
  236.         term.write(renderObjects[k]['text'])
  237.  
  238.     end
  239.     term.setTextColor(colors.white)
  240.  
  241. end
  242. function draw()
  243.     if cursorx < 4 then
  244.         cursorx = lines[cursory]:len()+4
  245.     end
  246.     term.clear()
  247.     --paintutils.drawFilledBox(1,1+uioff,3,17+uioff,colors.gray)
  248.     paintutils.drawFilledBox(1,1+uioff,51,17+uioff,colors.gray)
  249.     render()
  250.  
  251.     uiDrawer()
  252.     term.setCursorPos(cursorx,cursory+uioff)
  253. end
  254.  
  255. function key()
  256.     while true do
  257.         local event,char=os.pullEvent("key")
  258.         if keys.getName(char)=="leftShift" or keys.getName(char) == "rightShift" then
  259.             leftShift = true
  260.         elseif keys.getName(char)=="backspace" then
  261.             if cursorx < 5 then
  262.                 if cursory > 1 then
  263.                     cursory=cursory-1
  264.                 end
  265.                 cursorx=1
  266.             end
  267.             lines[cursory]=removePos(cursorx-4,lines[cursory])
  268.             cursorx=cursorx-1
  269.         elseif keys.getName(char)=="enter" then
  270.             shiftTable()
  271.             lines[cursory+1]=""
  272.             cursory=cursory+1
  273.             cursorx=1
  274.         elseif keys.getName(char)=="down" then
  275.             cursory = cursory+1
  276.             if lines[cursory] == nil then
  277.                 lines[cursory]=""
  278.             end
  279.             if cursorx > lines[cursory]:len()+4 then
  280.                 cursorx=lines[cursory]:len()+4
  281.             end
  282.  
  283.         elseif keys.getName(char)=="up" then
  284.             if cursory > 1 then
  285.                 cursory = cursory-1
  286.             end
  287.             if lines[cursory] == nil then
  288.                 lines[cursory]=""
  289.             end
  290.             if cursorx > lines[cursory]:len()+4 then
  291.                 cursorx=lines[cursory]:len()+4
  292.             end
  293.         elseif keys.getName(char)=="left" then
  294.             cursorx=cursorx-1
  295.             if cursorx < 4 then
  296.                 cursorx=4
  297.             end
  298.         elseif keys.getName(char)=="right" then
  299.             cursorx=cursorx+1
  300.             if cursorx > lines[cursory]:len()+4 then
  301.                 cursorx=lines[cursory]:len()+4
  302.             end
  303.         elseif leftShift==true and shiftTable[char] ~= nil then
  304.             --lines[cursory]=lines[cursory]..shiftTable[char]
  305.             lines[cursory]=insertPos(cursorx-4,lines[cursory],shiftTable[char])
  306.             cursorx=cursorx+1
  307.         elseif codeConversionTable[char] ~= nil then
  308.             --lines[cursory]=lines[cursory]..codeConversionTable[char]
  309.             lines[cursory]=insertPos(cursorx-4,lines[cursory],codeConversionTable[char])
  310.             cursorx=cursorx+1
  311.         end
  312.         --lines[1]=lines[1]+keys.getName()
  313.         draw()
  314.     end
  315. end
  316. function keyUp()
  317.     while true do
  318.         local event,char=os.pullEvent("key_up")
  319.         if keys.getName(char)=="leftShift" or keys.getName(char) == "rightShift" then
  320.             leftShift = false
  321.         end
  322.     end
  323. end
  324. term.clear()
  325. draw()
  326. while true do
  327.     parallel.waitForAll(key,keyUp)
  328.     sleep(1)
  329. end
Advertisement
Add Comment
Please, Sign In to add comment