diff options
author | Rob Hoelz <rob@hoelz.ro> | 2012-06-25 23:16:39 +0200 |
---|---|---|
committer | Rob Hoelz <rob@hoelz.ro> | 2012-06-25 23:16:39 +0200 |
commit | a6e9ded55fd2852168976ed4e2010e9a38726a74 (patch) | |
tree | a87be246a80ee65481c24c7d275c7569c1409984 | |
download | lua-term-a6e9ded55fd2852168976ed4e2010e9a38726a74.tar.gz lua-term-a6e9ded55fd2852168976ed4e2010e9a38726a74.tar.bz2 lua-term-a6e9ded55fd2852168976ed4e2010e9a38726a74.zip |
Import of first release of lua-term
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | COPYING | 19 | ||||
-rw-r--r-- | README.md | 23 | ||||
-rw-r--r-- | core.c | 22 | ||||
-rw-r--r-- | lua-term-0.1-1.rockspec | 21 | ||||
-rw-r--r-- | term/colors.lua | 84 | ||||
-rw-r--r-- | term/init.lua | 24 |
7 files changed, 195 insertions, 0 deletions
@@ -0,0 +1,2 @@ | |||
1 | 0.01 2012-06-25 23:30:00 | ||
2 | - Initial release. Includes colors and isatty. | ||
@@ -0,0 +1,19 @@ | |||
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. | ||
diff --git a/README.md b/README.md new file mode 100644 index 0000000..9b67a96 --- /dev/null +++ b/README.md | |||
@@ -0,0 +1,23 @@ | |||
1 | Overview | ||
2 | -------- | ||
3 | |||
4 | lua-term is a Lua module for manipulating a terminal. | ||
5 | |||
6 | Installation | ||
7 | ------------ | ||
8 | |||
9 | lua-term is available on Luarocks. | ||
10 | |||
11 | Usage | ||
12 | ----- | ||
13 | |||
14 | ```lua | ||
15 | local term = require 'term' | ||
16 | local colors = term.colors -- or require 'term.colors' | ||
17 | |||
18 | print(term.isatty(io.stdout)) -- true if standard output goes to the terminal | ||
19 | |||
20 | print(color.red 'hello') | ||
21 | print(color.red .. 'hello' .. color.reset) | ||
22 | print(color.red, 'hello', color.reset) | ||
23 | ``` | ||
@@ -0,0 +1,22 @@ | |||
1 | #include <lua.h> | ||
2 | #include <lauxlib.h> | ||
3 | #include <lualib.h> | ||
4 | |||
5 | static int | ||
6 | lua_isatty(lua_State *L) | ||
7 | { | ||
8 | FILE *fp = (FILE *) luaL_checkudata(L, -1, LUA_FILEHANDLE); | ||
9 | |||
10 | lua_pushboolean(L, isatty(fileno(fp))); | ||
11 | return 1; | ||
12 | } | ||
13 | |||
14 | int | ||
15 | luaopen_term_core(lua_State *L) | ||
16 | { | ||
17 | lua_newtable(L); | ||
18 | lua_pushcfunction(L, lua_isatty); | ||
19 | lua_setfield(L, -2, "isatty"); | ||
20 | |||
21 | return 1; | ||
22 | } | ||
diff --git a/lua-term-0.1-1.rockspec b/lua-term-0.1-1.rockspec new file mode 100644 index 0000000..3ae9092 --- /dev/null +++ b/lua-term-0.1-1.rockspec | |||
@@ -0,0 +1,21 @@ | |||
1 | package = 'lua-term' | ||
2 | version = '0.1-1' | ||
3 | |||
4 | source = { | ||
5 | url = 'https://github.com/hoelzro/lua-term.git', | ||
6 | } | ||
7 | |||
8 | description = { | ||
9 | summary = 'Terminal functions for Lua', | ||
10 | homepage = 'https://github.com/hoelzro/lua-term', | ||
11 | license = "MIT/X11", | ||
12 | } | ||
13 | |||
14 | build = { | ||
15 | modules = { | ||
16 | ['term'] = 'term/init.lua', | ||
17 | ['term.colors'] = 'term/colors.lua', | ||
18 | ['term.core'] = 'core.c', | ||
19 | }, | ||
20 | type = 'builtin', | ||
21 | } | ||
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 | ||