Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local increase = 5
- local function tConcat(t1,t2)
- for i=1,#t2 do
- t1[#t1+1] = t2[i]
- end
- return t1
- end
- local tArgs = { ... }
- if #tArgs >= 1 then
- if math.floor(tonumber(tArgs[1])) > 0 then --error checking
- increase = math.floor(tonumber(tArgs[1]))
- end
- end
- local tFilesUsed = {} --preventing repetition
- local tKeywords = {
- ["and"] = true,
- ["break"] = true,
- ["do"] = true,
- ["else"] = true,
- ["elseif"] = true,
- ["end"] = true,
- ["false"] = true,
- ["for"] = true,
- ["function"] = true,
- ["if"] = true,
- ["in"] = true,
- ["local"] = true,
- ["nil"] = true,
- ["not"] = true,
- ["or"] = true,
- ["repeat"] = true,
- ["return"] = true,
- ["then"] = true,
- ["true"] = true,
- ["until"] = true,
- ["while"] = true
- }
- local w,h = term.getSize()
- local X, Y = 1, 2
- local tLines = {}
- -- Colours
- local highlightColour, keywordColour, commentColour, textColour, bgColour
- if term.isColour() then
- bgColour = colours.black
- textColour = colours.white
- highlightColour = colours.yellow
- keywordColour = colours.blue
- commentColour = colours.green
- stringColour = colours.red
- else
- bgColour = colours.black
- textColour = colours.white
- highlightColour = colours.white
- keywordColour = colours.white
- commentColour = colours.white
- stringColour = colours.white
- end
- local function tryWrite( sLine, regex, colour )
- local match = string.match( sLine, regex )
- if match then
- if type(colour) == "number" then
- term.setTextColour( colour )
- else
- term.setTextColour( colour(match) )
- end
- term.write( match )
- term.setTextColour( textColour )
- return string.sub( sLine, string.len(match) + 1 )
- end
- return nil
- end
- local function writeHighlighted( sLine )
- while string.len(sLine) > 0 do
- sLine =
- tryWrite( sLine, "^%-%-%[%[.-%]%]", commentColour ) or
- tryWrite( sLine, "^%-%-.*", commentColour ) or
- tryWrite( sLine, "^\".-[^\\]\"", stringColour ) or
- tryWrite( sLine, "^\'.-[^\\]\'", stringColour ) or
- tryWrite( sLine, "^%[%[.-%]%]", stringColour ) or
- tryWrite( sLine, "^[%w_]+", function( match )
- if tKeywords[ match ] then
- return keywordColour
- end
- return textColour
- end ) or
- tryWrite( sLine, "^[^%w_]", textColour )
- end
- end
- local function redrawLine() --this is taken from edit, since I tried to do this myself but bios.lua kept throwing a fit
- local sLine = tLines[Y]
- --print(Y, ';')
- term.setCursorPos( 1, math.min(h, Y) )
- term.clearLine()
- writeHighlighted( sLine )
- end
- while true do
- term.clear()
- term.setCursorPos(1, 1)
- if term.isColor() then
- term.setTextColor(colors.yellow)
- end
- tFiles = tConcat(fs.find('/rom/apis/*'), fs.find('/rom/programs/*'))
- if #tFilesUsed == #tFiles then
- tFilesUsed = {}
- end
- local i = 0
- repeat
- i = math.random(#tFiles)
- until tFilesUsed[i] == nil
- local f = fs.open(tFiles[i], 'r')
- --local f2 = fs.open(fs.combine('/rom/programs', tFiles[i]), 'r')
- --if f2 then f = f2 end
- if f then --protecting against specific apis, such as turtle or advanced that is not in use
- tLines = {}
- Y = 1
- X = 1
- table.insert(tLines, 'Creating ' .. tFiles[i])
- redrawLine()
- Y = 2
- table.insert(tLines, ' ')
- redrawLine()
- local str = f.readAll()
- f.close()
- if term.isColor() then
- term.setTextColor(colors.white)
- end
- local pos = 1
- local continue = true
- local currentStr = ''
- local currentPos = 0
- local linePos = 0
- while str:sub(pos, pos + increase - 1) ~= '' and continue do
- local sEvent, nKey = os.pullEvent()
- if sEvent == 'key' then
- if nKey == 1 then --esc
- term.clear()
- term.setCursorPos(1, 1)
- if term.isColor() then
- term.setTextColor(colors.white)
- end
- return --exit
- elseif nKey == 14 or nKey == 211 then --backspace or delete
- --pretend this does something, i haven't figured out what to do
- elseif nKey == 28 then --enter
- continue = false --next file
- else
- for i = 1, increase do
- local c = str:sub(pos, pos)
- currentPos = currentPos + 1
- linePos = linePos + 1
- X = (currentPos % w - 1) + 1
- --Y = Y + math.floor(linePos / w)
- if c == '\n' or #tLines == 0 or math.floor(linePos / w) == 1 then
- table.insert(tLines, '')
- currentStr = ''
- currentPos = 0
- linePos = 0
- Y = Y + 1
- X = 1
- if Y >= h then print(' ') end
- else
- currentStr = currentStr .. c
- tLines[#tLines] = currentStr
- --print('fef')
- redrawLine()
- --print('feef')
- end
- pos = pos + 1
- --write(c)
- end
- end
- end
- end
- end
- tFilesUsed[i] = tFiles[i] --adding it to the table
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement