diff options
Diffstat (limited to 'term')
| -rw-r--r-- | term/colors.lua | 84 | ||||
| -rw-r--r-- | term/init.lua | 24 |
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 | |||
| 21 | local pairs = pairs | ||
| 22 | local tostring = tostring | ||
| 23 | local setmetatable = setmetatable | ||
| 24 | local schar = string.char | ||
| 25 | |||
| 26 | local colors = {} | ||
| 27 | |||
| 28 | local colormt = {} | ||
| 29 | |||
| 30 | function colormt:__tostring() | ||
| 31 | return self.value | ||
| 32 | end | ||
| 33 | |||
| 34 | function colormt:__concat(other) | ||
| 35 | return tostring(self) .. tostring(other) | ||
| 36 | end | ||
| 37 | |||
| 38 | function colormt:__call(s) | ||
| 39 | return self .. s .. colors.reset | ||
| 40 | end | ||
| 41 | |||
| 42 | colormt.__metatable = {} | ||
| 43 | |||
| 44 | local function makecolor(value) | ||
| 45 | return setmetatable({ value = schar(27) .. '[' .. tostring(value) .. 'm' }, colormt) | ||
| 46 | end | ||
| 47 | |||
| 48 | local 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 | |||
| 80 | for c, v in pairs(colorvalues) do | ||
| 81 | colors[c] = makecolor(v) | ||
| 82 | end | ||
| 83 | |||
| 84 | return 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 | |||
| 21 | local term = require 'term.core' | ||
| 22 | term.colors = require 'term.colors' | ||
| 23 | |||
| 24 | return term | ||
