Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.setCursorBlink(true)
- text=""
- leftShift=false
- lines={"hello!","how you do","l3","l4","l5","l6","l7","l8"}
- cursory=1
- cursorx=1
- renderc=1
- function strsplit(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={} ; i=1
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- t[i] = str
- i = i + 1
- end
- return t
- end
- function insertPos(position,strun,insert)
- part1=""
- part2=""
- for i = 1, strun:len() do
- if i <= position then
- part1=part1..strun:sub(i,i)
- else
- part2=part2..strun:sub(i,i)
- end
- end
- return part1..insert..part2
- end
- function removePos(position,strun)
- part1=""
- part2=""
- for i = 1, strun:len() do
- if i <= position then
- part1=part1..strun:sub(i,i)
- else
- part2=part2..strun:sub(i,i)
- end
- end
- return part1:sub(1,-2)..part2
- end
- function tablelength(T)
- local count = 0
- for _ in pairs(T) do count = count + 1 end
- return count
- end
- function shiftTable()
- x=0
- lines[tablelength(lines)+1]=lines[tablelength(lines)]
- --tmp=lines[cursory+1]
- for i=cursorx,tablelength(lines) do
- x=(tablelength(lines)*-1+i-1)*-1
- if x > cursory+3 then
- lines[x]=lines[x-1]
- end
- end
- --lines[cursory]=tmp
- --print(x-1)
- end
- --[[strun="hello"
- position=2
- part1=""
- part2=""
- for i = 1, strun:len() do
- if i <= position then
- part1=part1..strun:sub(i,i)
- else
- part2=part2..strun:sub(i,i)
- end
- end
- print(part1.."1"..part2)
- ]]
- function makeRenderObjects()
- renderc=1
- renderObjects={}
- for k,v in pairs(lines) do
- beginp, endp = string.find(lines[k], 'function')
- if beginp ~= nil then
- for i = beginp, endp do
- lines[k]=string.gsub(lines[k],'function',' ')
- end
- renderObjects[renderc] = {}
- renderObjects[renderc]['text']="function"
- renderObjects[renderc]['x'] = beginp
- renderObjects[renderc]['y'] = k
- renderObjects[renderc]['color']=colors.blue
- os.setComputerLabel("yeak ok")
- end
- end
- end
- shiftTable =
- {
- [41]="~",
- [2]="!",
- [3]="@",
- [4]="#",
- [5]="$",
- [6]="%",
- [7]="^",
- [8]="&",
- [9]="*",
- [10]="(",
- [11]=")",
- [12]="_",
- [13]="+",
- [16]="Q",
- [17]="W",
- [18]="E",
- [19]="R",
- [20]="T",
- [21]="Y",
- [22]="U",
- [23]="I",
- [24]="O",
- [25]="P",
- [26]="{",
- [27]="}",
- [43]="|",
- [30]="A",
- [31]="S",
- [32]="D",
- [33]="F",
- [34]="G",
- [35]="H",
- [36]="J",
- [37]="K",
- [38]="L",
- [39]=":",
- [40]="\"",
- [44]="Z",
- [45]="X",
- [46]="C",
- [47]="V",
- [48]="B",
- [49]="N",
- [50]="M",
- [51]="<",
- [52]=">",
- [53]="?",
- }
- codeConversionTable =
- {
- [41]="`",
- [2]="1",
- [3]="2",
- [4]="3",
- [5]="4",
- [6]="5",
- [7]="6",
- [8]="7",
- [9]="8",
- [10]="9",
- [11]="0",
- [12]="-",
- [13]="=",
- [16]="q",
- [17]="w",
- [18]="e",
- [19]="r",
- [20]="t",
- [21]="y",
- [22]="u",
- [23]="i",
- [24]="o",
- [25]="p",
- [26]="[",
- [27]="]",
- [43]="\\",
- [30]="a",
- [31]="s",
- [32]="d",
- [33]="f",
- [34]="g",
- [35]="h",
- [36]="j",
- [37]="k",
- [38]="l",
- [39]=";",
- [40]="'",
- [44]="z",
- [45]="x",
- [46]="c",
- [47]="v",
- [48]="b",
- [49]="n",
- [50]="m",
- [51]=",",
- [52]=".",
- [53]="/",
- [57]=" ",
- }
- --EditiorSTATE variables--
- --renderer re-write 2--
- uioff=2
- renderObjects={}
- function uiDrawer()
- paintutils.drawFilledBox(1,1,51,2,colors.lightGray)
- term.setCursorPos(1,1)
- term.write("File Op1 Op2")
- term.setCursorPos(4,2)
- term.setBackgroundColor(colors.gray)
- term.write("main.lua")
- end
- function render()
- --term.write(lines[k])
- renderObjects={}
- makeRenderObjects()
- for k,v in pairs(lines) do
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(1,k+uioff)
- term.write(k)
- --term.setBackgroundColor(colors.gray)
- term.setCursorPos(4,k+uioff)
- term.write(lines[k])
- end
- for k,v in pairs(renderObjects) do
- os.setComputerLabel("yeak ok")
- term.setCursorPos(renderObjects[k]['x']+3,renderObjects[k]['y']+uioff)
- term.setTextColor(renderObjects[k]['color'])
- term.write(renderObjects[k]['text'])
- end
- term.setTextColor(colors.white)
- end
- function draw()
- if cursorx < 4 then
- cursorx = lines[cursory]:len()+4
- end
- term.clear()
- --paintutils.drawFilledBox(1,1+uioff,3,17+uioff,colors.gray)
- paintutils.drawFilledBox(1,1+uioff,51,17+uioff,colors.gray)
- render()
- uiDrawer()
- term.setCursorPos(cursorx,cursory+uioff)
- end
- function key()
- while true do
- local event,char=os.pullEvent("key")
- if keys.getName(char)=="leftShift" or keys.getName(char) == "rightShift" then
- leftShift = true
- elseif keys.getName(char)=="backspace" then
- if cursorx < 5 then
- if cursory > 1 then
- cursory=cursory-1
- end
- cursorx=1
- end
- lines[cursory]=removePos(cursorx-4,lines[cursory])
- cursorx=cursorx-1
- elseif keys.getName(char)=="enter" then
- shiftTable()
- lines[cursory+1]=""
- cursory=cursory+1
- cursorx=1
- elseif keys.getName(char)=="down" then
- cursory = cursory+1
- if lines[cursory] == nil then
- lines[cursory]=""
- end
- if cursorx > lines[cursory]:len()+4 then
- cursorx=lines[cursory]:len()+4
- end
- elseif keys.getName(char)=="up" then
- if cursory > 1 then
- cursory = cursory-1
- end
- if lines[cursory] == nil then
- lines[cursory]=""
- end
- if cursorx > lines[cursory]:len()+4 then
- cursorx=lines[cursory]:len()+4
- end
- elseif keys.getName(char)=="left" then
- cursorx=cursorx-1
- if cursorx < 4 then
- cursorx=4
- end
- elseif keys.getName(char)=="right" then
- cursorx=cursorx+1
- if cursorx > lines[cursory]:len()+4 then
- cursorx=lines[cursory]:len()+4
- end
- elseif leftShift==true and shiftTable[char] ~= nil then
- --lines[cursory]=lines[cursory]..shiftTable[char]
- lines[cursory]=insertPos(cursorx-4,lines[cursory],shiftTable[char])
- cursorx=cursorx+1
- elseif codeConversionTable[char] ~= nil then
- --lines[cursory]=lines[cursory]..codeConversionTable[char]
- lines[cursory]=insertPos(cursorx-4,lines[cursory],codeConversionTable[char])
- cursorx=cursorx+1
- end
- --lines[1]=lines[1]+keys.getName()
- draw()
- end
- end
- function keyUp()
- while true do
- local event,char=os.pullEvent("key_up")
- if keys.getName(char)=="leftShift" or keys.getName(char) == "rightShift" then
- leftShift = false
- end
- end
- end
- term.clear()
- draw()
- while true do
- parallel.waitForAll(key,keyUp)
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment