fix/workaround: removed glitches with scaling and quads
[uboot.git] / console.lua
blob0246b105c230ca99febd3f0194265e40d02916ca
1 Console = {}
3 function Console:new()
4 self.show = false
5 self.inputbuffer = ""
6 self.prompt = os.date("%H:%M> ")
7 self.togglekey = "^"
8 self.lines = {}
9 for i=1, 13 do
10 self.lines[i] = ""
11 end
12 self.lines[13] = self.prompt
13 local t = {}
14 setmetatable(t, self)
15 self.__index = self
16 return t
17 end
19 function Console:draw()
20 if not self.show then
21 return
22 end
23 love.graphics.setColor(30,30,30)
24 love.graphics.polygon("fill", 0, 0, 0, 200, 800, 200, 800, 0)
25 love.graphics.setColor(230,230,230)
26 for i,v in ipairs(self.lines) do
27 love.graphics.print(v, 10, i*15)
28 end
29 end
31 function Console:input(key)
33 -- handle opening and closing of console
34 if not self.show then
35 if key == self.togglekey then
36 self.show = true
37 return true
38 else
39 return false
40 end
41 end
43 if key == self.togglekey then
44 self.show = false
45 return false
46 end
49 --letters are just printed, other keys are special, handle this
51 --return: new inputline, execute old one, shift lines up
52 if key == "return" or key == "kp_enter" then
53 for i=3,13 do
54 if self.inputbuffer == "" then
55 self.lines[i-1] = self.lines[i]
56 else
57 self.lines[i-2] = self.lines[i]
58 end
59 end
60 self.lines[12] = self.inputbuffer --TODO nochmal richtig machen
61 self:execute(self.inputbuffer)
62 self.inputbuffer = ""
64 --just no action for these
65 elseif key == "tab" or key == "lalt" or key == "ralt" or key == "lctrl" or key == "rctrl" or key == "lshift" or key == "rshift" or key == "mode" or key == "lsuper" or key == "rsuper" or key == "capslock" or key == "menu" then
67 elseif key == "up" then
68 --previous command --TODO
69 elseif key == "down" then
70 --next command
71 elseif key == "left" then
72 --shift cursor left
73 elseif key == "right" then
74 --shift cursor right
77 else
78 --letters, big or small --TODO: convert symbols
79 if love.keyboard.isDown("rshift") or love.keyboard.isDown("lshift") then
80 key = string.upper(key)
81 end
82 self.inputbuffer = self.inputbuffer .. key
83 end
84 self.lines[13] = self.prompt .. self.inputbuffer
85 return true
86 end
88 function Console:execute(string)
89 p = 4
90 end