aboutsummaryrefslogtreecommitdiff
path: root/term
diff options
context:
space:
mode:
Diffstat (limited to 'term')
-rw-r--r--term/colors.lua84
-rw-r--r--term/init.lua24
2 files changed, 108 insertions, 0 deletions
diff --git a/term/colors.lua b/term/colors.lua
new file mode 100644
index 0000000..4ab9140
--- /dev/null
+++ b/term/colors.lua
@@ -0,0 +1,84 @@
1-- Copyright (c) 2009 Rob Hoelz <rob@hoelzro.net>
2--
3-- Permission is hereby granted, free of charge, to any person obtaining a copy
4-- of this software and associated documentation files (the "Software"), to deal
5-- in the Software without restriction, including without limitation the rights
6-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7-- copies of the Software, and to permit persons to whom the Software is
8-- furnished to do so, subject to the following conditions:
9--
10-- The above copyright notice and this permission notice shall be included in
11-- all copies or substantial portions of the Software.
12--
13-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-- THE SOFTWARE.
20
21local pairs = pairs
22local tostring = tostring
23local setmetatable = setmetatable
24local schar = string.char
25
26local colors = {}
27
28local colormt = {}
29
30function colormt:__tostring()
31 return self.value
32end
33
34function colormt:__concat(other)
35 return tostring(self) .. tostring(other)
36end
37
38function colormt:__call(s)
39 return self .. s .. colors.reset
40end
41
42colormt.__metatable = {}
43
44local function makecolor(value)
45 return setmetatable({ value = schar(27) .. '[' .. tostring(value) .. 'm' }, colormt)
46end
47
48local colorvalues = {
49 -- attributes
50 reset = 0,
51 clear = 0,
52 bright = 1,
53 dim = 2,
54 underscore = 4,
55 blink = 5,
56 reverse = 7,
57 hidden = 8,
58
59 -- foreground
60 black = 30,
61 red = 31,
62 green = 32,
63 yellow = 33,
64 blue = 34,
65 magenta = 35,
66 cyan = 36,
67 white = 37,
68
69 -- background
70 onblack = 40,
71 onred = 41,
72 ongreen = 42,
73 onyellow = 43,
74 onblue = 44,
75 onmagenta = 45,
76 oncyan = 46,
77 onwhite = 47,
78}
79
80for c, v in pairs(colorvalues) do
81 colors[c] = makecolor(v)
82end
83
84return colors
diff --git a/term/init.lua b/term/init.lua
new file mode 100644
index 0000000..07be081
--- /dev/null
+++ b/term/init.lua
@@ -0,0 +1,24 @@
1-- Copyright (c) 2009 Rob Hoelz <rob@hoelzro.net>
2--
3-- Permission is hereby granted, free of charge, to any person obtaining a copy
4-- of this software and associated documentation files (the "Software"), to deal
5-- in the Software without restriction, including without limitation the rights
6-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7-- copies of the Software, and to permit persons to whom the Software is
8-- furnished to do so, subject to the following conditions:
9--
10-- The above copyright notice and this permission notice shall be included in
11-- all copies or substantial portions of the Software.
12--
13-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-- THE SOFTWARE.
20
21local term = require 'term.core'
22term.colors = require 'term.colors'
23
24return term