Guest User

ALL lua console for Powder Toy

a guest
Mar 26th, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.31 KB | None | 0 0
  1. --[[  This program is free software. It comes without any warranty, to
  2.  the extent permitted by applicable law. You can redistribute it
  3.  and/or modify it under the terms of the Do What The Fuck You Want
  4.  To Public License, Version 2, as published by Sam Hocevar. See
  5.  http://sam.zoy.org/wtfpl/COPYING for more details. --]]
  6.  
  7. -- The ALL lua-console v4
  8. --   by devast8a
  9.  
  10. console = {
  11.     -- Current state of console
  12.     -- 0 = Closed
  13.     -- 1 = Opened
  14.     -- 2 = Old console opened
  15.     -- [READONLY]
  16.     active = 0,
  17.  
  18.     -- Debug state of console, 1 if active, 0 if not
  19.     -- In no way effected by tpt.setdebug
  20.     -- [READONLY]
  21.     debugmode = 0,
  22.  
  23.     -- Current command line text for console
  24.     currentCommand = "",
  25.  
  26.     buffer = {},    -- Handle writing output to a larger display than screen can show
  27.     colors = {},    -- store console colors & resolve text colors to RGB
  28.     history = {},   -- command history
  29.     keys = {},      -- handle key input
  30.     old = {},       -- support for old console
  31.     quick = {},     -- Quick commands (commands that being with !)
  32.     screen = {},    -- Handle drawing to the screen
  33. }
  34.  
  35. ------------------------------------------------
  36. -- GLOBAL API ----------------------------------
  37. ------------------------------------------------
  38. function print(message)
  39.     console.writeln(message)
  40.     --console.screen.buffer = console.screen.buffer .. "\n" .. message
  41. end
  42.  
  43. function error(message)
  44.     console.writeln(message, "error", "errorbg")
  45. end
  46.  
  47. -- Call cmd & automatically call error (w/ error message) upon error
  48. function ecall(cmd, ...)
  49.     _, result = pcall(cmd, unpack(arg))
  50.  
  51.     if _ == false then
  52.         error(result)
  53.     end
  54.  
  55.     return _, result
  56. end
  57.  
  58. -- Execute a commnad
  59. function runcommand(command)
  60.     -- Handle quick commands
  61.     if string.sub(command, 1, 1) == "!" then
  62.         local l = string.find(command, " ")
  63.  
  64.         if l == nil then
  65.             command = string.sub(command, 2)
  66.             args = ""
  67.         else
  68.             args = string.trim(string.sub(command, l))
  69.             command = string.sub(command, 2, l - 1)
  70.         end
  71.        
  72.         cmd = console.quick[command]
  73.         message = "No command by the name of '" .. command .. "' exists"
  74.        
  75.     -- Short hand for return
  76.     elseif string.sub(command, 1, 1) == "@" then
  77.         command = "return " .. string.sub(command, 2)
  78.         cmd, message = loadstring(command)
  79.    
  80.     -- Compile the string to a function
  81.     else
  82.         cmd, message = loadstring(command)
  83.     end
  84.    
  85.     -- Handle errors
  86.     if cmd == nil then
  87.         error(message)
  88.     else
  89.         if args == nil then
  90.             _, result = pcall(cmd)
  91.         else
  92.             _, result = pcall(cmd, args)
  93.         end
  94.  
  95.         print(result)
  96.     end
  97. end
  98.  
  99. ------------------------------------------------
  100. -- string --------------------------------------
  101. ------------------------------------------------
  102. string.trim = function (str)
  103.     return (string.gsub(str, "^%s*(.-)%s*$", "%1"))
  104. end
  105.  
  106. string.split = function (str, split)
  107.     local output = {}
  108.    
  109.     lastpos = 1
  110.     while true do
  111.         pos = string.find(str, split, lastpos)
  112.         if pos == nil then
  113.             table.insert(output, string.sub(str, lastpos))
  114.             return output
  115.         end
  116.  
  117.         table.insert(output, string.sub(str, lastpos, pos-1))
  118.         lastpos = pos + 1
  119.     end
  120.  
  121.     return { str }
  122. end
  123.  
  124. ------------------------------------------------
  125. -- console -------------------------------------
  126. ------------------------------------------------
  127. console.set = function(value)
  128.     if console.active == 2 then
  129.         if value == 0 then
  130.             console.active = 0
  131.         else
  132.             console.active = 2
  133.         end
  134.  
  135.         return console.old.set_console(value)
  136.     end
  137.  
  138.     if value == 0 then
  139.         console.active = 0
  140.         tpt.hud(1)
  141.     else
  142.         console.old.set_pause(1)
  143.         tpt.hud(0)
  144.         console.active = 1
  145.     end
  146. end
  147.  
  148. console.toggle = function()
  149.     console.set(1-console.active)
  150. end
  151.  
  152. ------------------------------------------------
  153. -- console.old ---------------------------------
  154. ------------------------------------------------
  155. console.old = {
  156.     active = 0,
  157.     hud_value = 1,
  158. }
  159.  
  160. console.old.open = function()
  161.     -- Old console quirks
  162.     tpt.hud(1)
  163.  
  164.     -- Open the old console
  165.     console.active = 2
  166.     console.old.set_console(1)
  167. end
  168.  
  169. ------------------------------------------------
  170. -- console.old.interop -------------------------
  171. ------------------------------------------------
  172. console.old.interop = {}
  173.  
  174. -- tpt.set_pause
  175. console.old.interop.set_pause = function(value)
  176.     if console.active == 0 then
  177.         console.old.set_pause(value)
  178.     end
  179. end
  180. console.old.set_pause = tpt.set_pause
  181. tpt.set_pause = console.old.interop.set_pause
  182.  
  183. -- tpt.log
  184. console.old.interop.log = function(message)
  185.     if console.active == 2 then
  186.         return console.old.log(message)
  187.     end
  188.  
  189.     return print(message)
  190. end
  191. console.old.log = tpt.log
  192. tpt.log = console.old.interop.log
  193.  
  194. -- tpt.hud
  195. console.old.interop.hud = function(value)
  196.     if value == 0 then
  197.         console.old.hud_value = 0
  198.     else
  199.         console.old.hud_value = 1
  200.     end
  201.    
  202.     console.old.hud(value)    
  203. end
  204. console.old.hud = tpt.hud
  205. tpt.hud = console.old.interop.hud
  206.  
  207. -- tpt.set_console
  208. console.old.set_console = tpt.set_console
  209. tpt.set_console = console.set
  210.  
  211. ------------------------------------------------
  212. -- console.buffer ------------------------------
  213. ------------------------------------------------
  214. console.buffer = {
  215.     x = 1,
  216.     y = 1,
  217.     newline = 0,
  218.     width = 85,
  219.     height = 500,
  220.     lines = {},
  221.  
  222.     more = {
  223.         enabled = false,
  224.     }
  225. }
  226.  
  227. console.buffer.draw = function(self, screen, xoffset, yoffset)
  228.     fontx = 7
  229.     fonty = 9
  230.  
  231.     y = 0
  232.     for i = screen.y+(1+self.y-screen.height), screen.y+self.y do
  233.         if i < 1 then
  234.             line = self.lines[self.height + i]
  235.         else
  236.             if i > self.height then
  237.                 line = self.lines[i-self.height]
  238.             else
  239.                 line = self.lines[i]
  240.             end
  241.         end
  242.  
  243.         if line ~= nil then
  244.             x = 0
  245.             for ch = screen.x + 1, screen.x+screen.width do
  246.                 char = line[ch]
  247.                
  248.                 if char == 0 then
  249.                     break
  250.                 end
  251.  
  252.                 if char ~= nil then
  253.                     fg = console.colors.get(char[2], console.colors.foreground)
  254.                     bg = console.colors.get(char[3], console.colors.background)
  255.                    
  256.                     if bg ~= 0 then
  257.                         if x == 0 then
  258.                             tpt.fillrect(xoffset + x * fontx - 3, yoffset + y * fonty - 2, fontx + 3, fonty + 1, bg[1], bg[2], bg[3], bg[4])
  259.                         else
  260.                             tpt.fillrect(xoffset + x * fontx - 1, yoffset + y * fonty - 2, fontx + 1, fonty + 1, bg[1], bg[2], bg[3], bg[4])
  261.                         end
  262.                     end
  263.  
  264.                     tpt.drawtext(xoffset + x * fontx, yoffset + y * fonty, char[1], fg[1], fg[2], fg[3], fg[4])
  265.                 end
  266.  
  267.                 x = x + 1
  268.             end
  269.         end
  270.  
  271.         y = y + 1
  272.     end
  273. end
  274.  
  275. console.buffer._write = function(char)
  276.     self = console.buffer
  277.  
  278.     if self.newline == true then
  279.         self.y = self.y + 1
  280.         self.newline = false
  281.     end
  282.  
  283.     if char == "\n" then
  284.         self.newline = true
  285.         self.x = 1
  286.     elseif char == "\r" then
  287.         self.x = 1
  288.     else
  289.         line = self.lines[self.y]
  290.        
  291.         if line == nil then line = {} self.lines[self.y] = line end
  292.    
  293.         line[self.x] = {char, self.cf, self.cb}
  294.        
  295.         self.x = self.x + 1    
  296.         if self.x > self.width then
  297.             self.y = self.y + 1
  298.             self.x = 1
  299.             self.lines[self.y] = {}
  300.         end
  301.     end
  302.  
  303.     if self.y > self.height then
  304.         self.y = 1
  305.     end
  306. end
  307.  
  308. console.buffer.write = function(text, colorF, colorB)
  309.     if text == nil then
  310.         return
  311.     end
  312.  
  313.     self = console.buffer
  314.  
  315.     tpt.drawtext(0, 0, "test")
  316.  
  317.     self.cf = colorF
  318.     self.cb = colorB
  319.  
  320.     string.gsub(text, ".", console.buffer._write)
  321. end
  322.  
  323. console.write = console.buffer.write
  324.  
  325. console.buffer.writeln = function(text, colorF, colorB)
  326.     if text == nil then
  327.         return
  328.     end
  329.  
  330.     console.buffer.write(text .. "\n", colorF, colorB)
  331. end
  332. console.writeln = console.buffer.writeln
  333.  
  334. ------------------------------------------------
  335. -- console.screen ------------------------------
  336. ------------------------------------------------
  337. console.screen = {
  338.     x = 0,
  339.     y = 0,
  340.     height = 40,
  341.     width  = 85,
  342. }
  343.  
  344. console.screen.right = function(self)
  345.     self.x = self.x + 1
  346.     if self.x > console.buffer.width - self.width then
  347.         self.x = 0
  348.     end
  349. end
  350.  
  351. console.screen.left = function(self)
  352.     self.x = self.x - 1
  353.     if self.x < 0 then
  354.         self.x = 0
  355.     end
  356. end
  357.  
  358. console.screen.down = function(self)
  359.     self.y = self.y + 1
  360.     if self.y > console.buffer.height - 1 then
  361.         self.y = 0
  362.     end
  363. end
  364.  
  365. console.screen.up = function(self)
  366.     self.y = self.y - 1
  367.     if self.y < 0 then
  368.         self.y = console.buffer.height - 1
  369.     end
  370. end
  371.  
  372. console.screen.draw = function(self)
  373.     cbk = console.colors.backdrop
  374.     cbr = console.colors.border
  375.     cln = console.colors.line
  376.  
  377.     tpt.fillrect(5,   5, 600, 570, cbk[1], cbk[2], cbk[3], cbk[4])
  378.     tpt.drawline(5, 372, 605, 372, cln[1], cln[2], cln[3], cln[4])
  379.     tpt.drawrect(5,   5, 600, 570, cbr[1], cbr[2], cbr[3], cbr[4])
  380.  
  381.    
  382.     if console.currentCommand == nil then
  383.         tpt.drawtext(8, 375, "> FATAL ERROR - currentCommand = <nil>", 255, 0, 0)
  384.     else
  385.         c = console.colors.command
  386.  
  387.         tpt.drawtext(8, 375, "> " .. console.currentCommand, c[1], c[2], c[3], c[4])
  388.     end
  389.  
  390.     ecall(console.buffer.draw, console.buffer, console.screen, 8, 10)
  391.  
  392.     tpt.drawtext(0, 0, error_message)
  393. end
  394.  
  395. ------------------------------------------------
  396. -- console.colors ------------------------------
  397. ------------------------------------------------
  398. console.colors = {
  399.     blue        = {  0,   0, 255, 255},
  400.     cyan        = {  0, 255, 255, 255},
  401.     darkblue    = {  0,   0, 178, 255},
  402.     darkcyan    = {  0, 178, 178, 255},
  403.     darkgreen   = {  0, 178,   0, 255},
  404.     darkred     = {178,   0,   0, 255},
  405.     darkyellow  = {178, 178,   0, 255},
  406.     darkpurple  = {178,   0, 178, 255},
  407.     default     = {178,  32, 255, 255},
  408.     gray        = {178, 178, 178, 255},
  409.     green       = {  0, 255,   0, 255},
  410.     purple      = {255,   0, 255, 255},
  411.     red         = {255,   0,   0, 255},
  412.     white       = {255, 255, 255, 255},
  413.     yellow      = {255, 255,   0, 255},
  414. }
  415.  
  416. -- bound colors
  417. console.colors.command    = console.colors.default -- color for current command
  418. console.colors.foreground = console.colors.default -- default foreground color
  419. console.colors.background = 0                      -- background of nil won't draw anything
  420. console.colors.error      = console.colors.red     -- default foreground for errors
  421. console.colors.errorbg    = 0                      -- default background for errors
  422. console.colors.backdrop   = {0,0,0,178}            -- backdrop, the color behind the text
  423. console.colors.border     = console.colors.white   -- border to the console
  424. console.colors.line       = console.colors.white   -- line which seperates console output from input
  425. console.colors.hud_motd   = console.colors.default -- message of the day display
  426. console.colors.hud_debug  = console.colors.default -- debug display
  427. console.colors.hud_close  = console.colors.default -- close message when old console is opened
  428.  
  429. console.colors.get = function(color, default)
  430.     if color == nil then
  431.         return default
  432.     end
  433.  
  434.     if type(color) == "table" then
  435.         if #color == 3 then
  436.             table.insert(color, 255)
  437.         elseif #color ~= 4 then
  438.             error("Color must be a table of 3 or 4 numbers")
  439.             return default
  440.         end
  441.        
  442.         return color
  443.     end
  444.  
  445.     c = console.colors[color]
  446.  
  447.     if c == nil then
  448.         error("Unknown color '" .. color .. "'")
  449.         return default
  450.     end
  451.  
  452.     return c
  453. end
  454.  
  455. ------------------------------------------------
  456. -- console.keys --------------------------------
  457. ------------------------------------------------
  458. console.keys = {
  459.     binds = {},
  460.     numbers = {},
  461.     symbols = {},
  462.     lastkey = 0,
  463.     down = 0,
  464.     downstart = 0,
  465.     repeatDelay = 0.5,
  466.     repeatTimer = 0.05
  467. }
  468.  
  469. console.keys.clear = function(self)
  470.     self.binds = {}
  471.     self.numbers = {}
  472.     self.symbols = {}
  473. end
  474.  
  475. console.keys.default = function(self)
  476.     self:clear()
  477.     -- Shifted Numbers Map
  478.     self.numbers = {")", "!", "@", "#", "$", "%", "^", "&", "*", "("}
  479.     -- Shifted Symbols Map
  480.     self.symbols["-"] = "_"
  481.     self.symbols["="] = "+"
  482.     self.symbols["["] = "{"
  483.     self.symbols["]"] = "}"
  484.     self.symbols[";"] = ":"
  485.     self.symbols["'"] = "\""
  486.     self.symbols[","] = "<"
  487.     self.symbols["."] = ">"
  488.     self.symbols["/"] = "?"
  489.     self.symbols["\\"] = "|"
  490.     -- Set binds
  491.     self.binds[27] = function() console.set(0) end          -- Esc
  492.     self.binds[96] = function() console.set(0) end          -- ` - Console Key
  493.     self.binds[273] = function() console.history:next() end -- Up
  494.     self.binds[274] = function() console.history:prev() end -- Down
  495.     self.binds[278] = function() console.screen:left() end  -- Home
  496.     self.binds[279] = function() console.screen:right() end -- End
  497.     self.binds[280] = function() console.screen:up() end    -- Page Up
  498.     self.binds[281] = function() console.screen:down() end  -- Page Down
  499. end
  500.  
  501. -- default keys should work for US style keyboards
  502. console.keys.us = console.keys.default
  503.  
  504. -- Repeat the key if held down for longer than 0.5 seconds
  505. console.keys.heldkey = function(self)
  506.     if self.down == 1 then
  507.         if os.clock() - self.downstart > self.repeatDelay then
  508.             self.down = 2
  509.         end
  510.     end
  511.     if self.down == 2 and (os.clock() - self.downstart) > self.repeatTimer then
  512.         downstart = os.clock()
  513.         console.keys:process(self.lastks, self.lastkey, self.lastmod, 3)
  514.  
  515.         -- HACK: down is set within console.keys.process, set it back to 2
  516.         self.down = 2
  517.     end
  518. end
  519.  
  520. console.keys.process = function(self, keyString, key, modifier, event)
  521.     self.lastkey = key
  522.     self.lastks = keyString
  523.     self.lastmod = modifier
  524.    
  525.     self.down = 2 - event
  526.     self.downstart = os.clock()
  527.    
  528.     -- Handle keys closing old console
  529.     if console.active == 2 and (key == 96 or key == 27) then
  530.         console.active = 0
  531.     end
  532.  
  533.     -- Override keys
  534.     if console.active == 0 and event == 1 then
  535.         -- ` - Console Key
  536.         if key == 96 then
  537.             if console.active == 0 and (modifier == 1 or modifier == 2) then
  538.                 console.old.open()
  539.                 return false
  540.             end
  541.  
  542.             console.toggle()        
  543.             return false
  544.         end
  545.  
  546.         -- d - Debug Mode
  547.         if key == 100 and event == 1 then
  548.             console.debugmode = 1 - console.debugmode
  549.         end
  550.  
  551.         -- h - Hud Toggle
  552.         if key == 104 and event == 1 then
  553.             tpt.hud(1 - console.old.hud_value)
  554.             return false
  555.         end
  556.     end
  557.    
  558.     if console.active == 1 then
  559.         if event == 2 then
  560.             return false
  561.         end
  562.        
  563.         -- Handle backspace
  564.         if key == 8 then
  565.             console.currentCommand = string.sub(console.currentCommand, 1, string.len(console.currentCommand)-1)
  566.             return false
  567.         end
  568.        
  569.         -- Process console.currentCommand
  570.         if key == 13 then
  571.             console.history:store(console.currentCommand)
  572.             local temp = console.currentCommand
  573.             console.currentCommand = ""
  574.             runcommand(temp)
  575.             return false
  576.         end
  577.  
  578.         -- Execute bind for key
  579.         bind = self.binds[key]
  580.         if bind ~= nil then
  581.             ecall(bind, keyString, key, modifier, event)
  582.             return false
  583.         end
  584.        
  585.         -- Ignore any special keys
  586.         if key >= 256 then
  587.             return false
  588.         end
  589.  
  590.         -- Mappings for shifted keys
  591.         if modifier == 1 or modifier == 2 then
  592.             if key >= 48 and key <= 57 then
  593.                 keyString = self.numbers[key - 47]
  594.             elseif key >= 97 and key <= 122 then
  595.                 keyString = string.char(key - 97 + 65)
  596.             else
  597.                 local temp = self.symbols[keyString]
  598.                
  599.                 if temp ~= nil then
  600.                     keyString = temp
  601.                 end
  602.             end
  603.         end
  604.        
  605.         console.currentCommand = console.currentCommand .. keyString
  606.         return false
  607.     end
  608. end
  609.  
  610. ------------------------------------------------
  611. -- console.history -----------------------------
  612. ------------------------------------------------
  613. console.history = {
  614.     contents = {},
  615.     maxsize = 30,
  616.     size = 0,
  617. }
  618.  
  619. console.history.store = function(self, value)
  620.     self.size = self.size + 1
  621.     table.insert(self.contents, 1, value)
  622.     self.selected = 0
  623. end
  624.  
  625. console.history.next = function(self)
  626.     if self.size == 0 then
  627.         return
  628.     end
  629.     self.selected = self.selected + 1
  630.  
  631.     if self.selected > self.size then
  632.         self.selected = 1
  633.     end
  634.  
  635.     console.currentCommand = self.contents[self.selected]
  636. end
  637.  
  638. console.history.prev = function(self)
  639.     if self.size == 0 then
  640.         return
  641.     end
  642.     self.selected = self.selected - 1
  643.  
  644.     if self.selected <= 0 then
  645.         self.selected = self.size
  646.     end
  647.  
  648.     console.currentCommand = self.contents[self.selected]
  649. end
  650.  
  651. console.history.select = function(self, n)
  652.     if self.size == 0 then
  653.         return
  654.     end
  655.  
  656.     n = n%self.size
  657.     print(n)
  658.     self.selected = (self.selected + n)
  659.  
  660.     print(self.selected)
  661.     console.currentCommand = self.contents[self.selected]
  662. end
  663.  
  664. ------------------------------------------------
  665. -- console.quick -------------------------------
  666. ------------------------------------------------
  667. local function console_quick_help()
  668.     print("!color [name] <color>")
  669.     print("!e <text>  - Echo text")
  670.     print("!r <file>  - Run a file")
  671.     print("!help      - Display this")
  672. end
  673.  
  674. console.quick[""] = console_quick_help
  675. console.quick["help"] = console_quick_help
  676.  
  677. console.quick["e"] = function(arguments)
  678.     console.buffer.write(arguments)
  679. end
  680.  
  681. console.quick["color"] = function(arguments)
  682.     args = string.split(arguments, " ")
  683.  
  684.     if #args == 1 then
  685.         name = "foreground"
  686.         color = args[1]
  687.     elseif #args == 2 then
  688.         name = args[1]
  689.         color = args[2]
  690.     else
  691.         error("!color [name] <color>")
  692.         return
  693.     end
  694.  
  695.     c = string.split(color,",")
  696.    
  697.     if #c == 1 then
  698.         if color == "nil" then
  699.             console.colors[name] = 0
  700.             return
  701.         end
  702.  
  703.         c = console.colors.get(color)
  704.        
  705.         if c == nil then
  706.             return
  707.         end
  708.     elseif #c == 3 or #c == 4 then
  709.         alpha = 255
  710.  
  711.         if #c == 4 then
  712.             alpha = tonumber(c[4])
  713.         end
  714.        
  715.         c = {
  716.             tonumber(c[1]),
  717.             tonumber(c[2]),
  718.             tonumber(c[3]),
  719.             alpha
  720.         }
  721.     end
  722.  
  723.     console.colors[name] = c
  724. end
  725.  
  726. -- Function for running a file named filename or filename.lua
  727. console.quick["r"] = function(filename)
  728.     if string.sub(filename, -4) ~= ".lua" then
  729.         f, msg = io.open(filename, "r")
  730.  
  731.         if not f then
  732.             f, msg = io.open(filename .. ".lua", "r")
  733.             if f then
  734.                 f:close()
  735.                 return dofile(filename .. ".lua")
  736.             end
  737.         else
  738.             f:close()
  739.         end
  740.     end
  741.     return dofile(filename)
  742. end
  743.  
  744. ------------------------------------------------
  745. -- LETS DO THIS! -------------------------------
  746. ------------------------------------------------
  747. local function keyHandler(keyString, key, modifier, event)
  748.     return console.keys:process(keyString, key, modifier, event)
  749. end
  750.  
  751. motd = 1
  752. motdstart = 0
  753.  
  754. local function mouseHandler(mousex, mousey, button, event)
  755.     if motd == 1 then
  756.         motdstart = os.clock()
  757.         motd = 0
  758.     end
  759.  
  760.     if console.active == 1 then
  761.         return false
  762.     end
  763.    
  764.     return true
  765. end
  766.  
  767. local function draw()
  768.     if console.active == 1 then
  769.         ecall(console.keys.heldkey, console.keys)
  770.         console.screen:draw()
  771.     end
  772.  
  773.     if motd == 1 then
  774.         alpha = 1
  775.     else
  776.         alpha = 1 - (os.clock() - motdstart)
  777.     end
  778.    
  779.     if alpha ~= 0 then
  780.         c = console.colors.hud_motd
  781.         tpt.drawtext(17, 335, "The all lua-console V5 by devast8a is installed!", c[1], c[2], c[3], c[4] * alpha)
  782.     end
  783.        
  784.     if console.debugmode == 1 then
  785.         x = 16
  786.         y = 27
  787.  
  788.         c = console.colors.hud_debug
  789.         if console.old.hud_value == 1 then
  790.             tpt.drawtext(16, 27, "lua-console (V5) (" .. console.active .. ", " .. console.keys.lastkey .. ")", c[1], c[2], c[3], c[4])
  791.         end
  792.         if console.active == 1 then
  793.             tpt.drawtext(575, 8, "[" .. console.keys.lastkey .. "]", c[1], c[2], c[3], c[4])
  794.         end
  795.     end
  796.  
  797.     if console.active == 2 then
  798.         c = console.colors.hud_close
  799.         tpt.drawtext(5, 228, "Old console [Press escape to close] -- lua-console", c[1], c[2], c[3], c[4])
  800.     end
  801. end
  802.  
  803. tpt.register_step(draw)
  804. tpt.register_keypress(keyHandler)
  805. tpt.register_mouseclick(mouseHandler)
  806.  
  807. console.old.log("lua-console loaded successfully")
  808.  
  809. tpt.log("The all lua-console V5")
  810. tpt.log("  by devast8a")
  811. tpt.log("")
  812. tpt.log("Page Up/Down - move console screen up/down")
  813. -- Home/End - move console left/right (Only useful when buffer is larger than screen)
  814. tpt.log("Up/Down - cycle through command history")
  815. tpt.log("")
  816. tpt.log("Commands starting with ! don't work, instead close this console")
  817. tpt.log(" and press shift + console key to use the old console.")
  818.  
  819. ------------------------------------------------
  820. -- Last initialization steps -------------------
  821. ------------------------------------------------
  822. console.keys:us() -- keyboard mapping
Advertisement
Add Comment
Please, Sign In to add comment