Advertisement
guitarplayer616

EZ Console

Jun 23rd, 2015
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.79 KB | None | 0 0
  1. local w,h = term.getSize()
  2. term.clear()
  3. local console = window.create(term.current(),w/2,1,w,h/2)
  4. console.setCursorBlink(false)
  5.  
  6. function showConsole()
  7.     if visible then
  8.         console.setVisible(false)
  9.         visible = false
  10.         console.redraw()
  11.     else
  12.         console.setVisible(true)
  13.         visible = true
  14.         console.redraw()
  15.     end
  16. end
  17.  
  18.  
  19. function clear()
  20.   console.setBackgroundColor(colors.white)
  21.   console.setTextColor(colors.blue)
  22.   console.clear()
  23.   console.setCursorPos(1,1)
  24.   console.write(" Console v0.1")
  25.   local _,y = console.getCursorPos()
  26.   console.setCursorPos(1,y+1)
  27. end
  28.  
  29. function log(words,col,back)
  30.     words = tostring(words)
  31.     words = " > "..words
  32.     col = col or colors.gray
  33.     back = back or colors.white
  34.     console.setTextColor(col)
  35.     console.setBackgroundColor(back)
  36.     console.write(words)
  37.     local _,y = console.getCursorPos()
  38.     console.setCursorPos(1,y+1)
  39. end
  40.  
  41. clear()
  42. log("heres some fresh words")
  43. log("more stuff")
  44. log("even more stugf")
  45. log("cant keep up")
  46. log("have a log")
  47.  
  48.  
  49. function displayEvents()
  50.     while true do
  51.         local e = {os.pullEvent()} --bcuz terminating is actually gud
  52.         if e then
  53.             for i=2,5 do
  54.                 console.setCursorPos(1,i)
  55.                 console.clearLine()
  56.             end
  57.             console.setCursorPos(1,2)
  58.             for _,v in ipairs(e) do
  59.                 log(v)
  60.             end
  61.         end
  62.     end
  63. end
  64.  
  65. function waitForScroll()
  66.     local keyPress = {
  67.         up = {200,-1},
  68.         down = {208,1},
  69.     }  
  70.     while true do
  71.         local e = {os.pullEvent()}
  72.         local x,y = console.getCursorPos()
  73.         local h = fs.open("trp","a")
  74.         h.writeLine(x," ",y)
  75.         h.close()
  76.         if e[1] == "mouse_scroll" or "key" then
  77.             for i=1,2 do
  78.                 if e[2] == keyPress.up[i] and y~=1 then
  79.                     console.scroll(1)
  80.                 elseif e[2] == keyPress.down[i] and y~=h then
  81.                     console.scroll(-1)
  82.                 end
  83.             end
  84.         end
  85.     end
  86. end
  87.  
  88. fs.open("trp","w")
  89. waitForScroll()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement