Advertisement
LDDestroier

cc reverse

Apr 16th, 2017
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.35 KB | None | 0 0
  1. -- reverses cc terminal output left to right
  2. -- pastebin get rxSRAq2h rev
  3.  
  4. local oldterm = {}
  5. local oldos = {}
  6. local oldio = {}
  7. local scr_x,scr_y = term.getSize()
  8.  
  9. local revTable = {
  10.     ["("] = ")",
  11.     [")"] = "(",
  12.     ["["] = "]",
  13.     ["]"] = "[",
  14.     ["{"] = "}",
  15.     ["}"] = "{",
  16.     ["<"] = ">",
  17.     [">"] = "<",
  18.     ["/"] = "\\",
  19.     ["\\"] = "/",
  20. }
  21.  
  22. local strReverse = function(str)
  23.     local output = str:reverse()
  24.     for k,v in pairs(revTable) do
  25.         output = output:gsub(k,v)
  26.     end
  27.     return output
  28. end
  29.  
  30. oldterm.getCursorPos = term.getCursorPos
  31. term.getCursorPos = function()
  32.     local cx,cy = oldterm.getCursorPos()
  33.     return scr_x-(cx-1),cy
  34. end
  35.  
  36. oldterm.setCursorPos = term.setCursorPos
  37. term.setCursorPos = function(x,y)
  38.     return oldterm.setCursorPos(scr_x-(x-1), y)
  39. end
  40.  
  41. oldio.write = io.write
  42. io.write = function(txt)
  43.     local cx,cy = term.getCursorPos()
  44.     oldterm.setCursorPos(cx-(txt:len()-0),cy)
  45.     oldio.write(strReverse(txt:reverse()))
  46.     oldterm.setCursorPos(cx-(txt:len()-0),cy)
  47. end
  48.  
  49. oldterm.write = term.write
  50. term.write = function(txt)
  51.     local cx,cy = getCursorPos()
  52.     oldterm.setCursorPos(cx-(txt:len()-0),cy)
  53.     oldterm.write(strReverse(txt:reverse()))
  54.     oldterm.setCursorPos(cx-(txt:len()-0),cy)
  55. end
  56.  
  57. oldterm.blit = term.blit
  58. term.blit = function(text,txt,bg)
  59.     if (#text == #txt) and (#txt == #bg) then
  60.         local cx,cy = term.getCursorPos()
  61.         oldterm.setCursorPos(cx-(text:len()-0),cy)
  62.         oldterm.blit(strReverse(text:reverse()),txt:reverse(),bg:reverse())
  63.         oldterm.setCursorPos(cx-(text:len()-0),cy)
  64.     else
  65.         error("Arguments must be the same length")
  66.     end
  67. end
  68.  
  69. oldos.pullEventRaw = os.pullEventRaw
  70. os.pullEventRaw = function(event)
  71.     local evt = oldos.pullEventRaw(event)
  72.     if (evt == "mouse_click") or (evt == "mouse_drag") then
  73.         return evt[1], evt[2], scr_x-(evt[3]-1), evt[4]
  74.     elseif evt == "mouse_up" then
  75.         return evt[1],scr_x-(evt[2]-1),evt[3]
  76.     else
  77.         return table.unpack(evt)
  78.     end
  79. end
  80.  
  81. oldos.pullEvent = os.pullEvent
  82. os.pullEvent = function(event)
  83.     local evt = oldos.pullEvent(event)
  84.     if (evt == "mouse_click") or (evt == "mouse_drag") then
  85.         return evt[1], evt[2], scr_x-(evt[3]-1), evt[4]
  86.     elseif evt == "mouse_up" then
  87.         return evt[1],scr_x-(evt[2]-1),evt[3]
  88.     else
  89.         return table.unpack(evt)
  90.     end
  91. end
  92.  
  93. local startShell = function(program)
  94.     term.clear()
  95.     term.setCursorPos(1,1)
  96.     dofile(program or "/rom/programs/shell")
  97. end
  98.  
  99. startShell()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement