aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Hoelz <rob@hoelz.ro>2012-06-25 23:16:39 +0200
committerRob Hoelz <rob@hoelz.ro>2012-06-25 23:16:39 +0200
commita6e9ded55fd2852168976ed4e2010e9a38726a74 (patch)
treea87be246a80ee65481c24c7d275c7569c1409984
downloadlua-term-a6e9ded55fd2852168976ed4e2010e9a38726a74.tar.gz
lua-term-a6e9ded55fd2852168976ed4e2010e9a38726a74.tar.bz2
lua-term-a6e9ded55fd2852168976ed4e2010e9a38726a74.zip
Import of first release of lua-term
-rw-r--r--CHANGES2
-rw-r--r--COPYING19
-rw-r--r--README.md23
-rw-r--r--core.c22
-rw-r--r--lua-term-0.1-1.rockspec21
-rw-r--r--term/colors.lua84
-rw-r--r--term/init.lua24
7 files changed, 195 insertions, 0 deletions
diff --git a/CHANGES b/CHANGES
new file mode 100644
index 0000000..e334205
--- /dev/null
+++ b/CHANGES
@@ -0,0 +1,2 @@
10.01 2012-06-25 23:30:00
2 - Initial release. Includes colors and isatty.
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..48de251
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,19 @@
1Copyright (c) 2009 Rob Hoelz <rob@hoelzro.net>
2
3Permission is hereby granted, free of charge, to any person obtaining a copy
4of this software and associated documentation files (the "Software"), to deal
5in the Software without restriction, including without limitation the rights
6to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7copies of the Software, and to permit persons to whom the Software is
8furnished to do so, subject to the following conditions:
9
10The above copyright notice and this permission notice shall be included in
11all copies or substantial portions of the Software.
12
13THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19THE 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 @@
1Overview
2--------
3
4lua-term is a Lua module for manipulating a terminal.
5
6Installation
7------------
8
9lua-term is available on Luarocks.
10
11Usage
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```
diff --git a/core.c b/core.c
new file mode 100644
index 0000000..04ff4ef
--- /dev/null
+++ b/core.c
@@ -0,0 +1,22 @@
1#include <lua.h>
2#include <lauxlib.h>
3#include <lualib.h>
4
5static int
6lua_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
14int
15luaopen_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 @@
1package = 'lua-term'
2version = '0.1-1'
3
4source = {
5 url = 'https://github.com/hoelzro/lua-term.git',
6}
7
8description = {
9 summary = 'Terminal functions for Lua',
10 homepage = 'https://github.com/hoelzro/lua-term',
11 license = "MIT/X11",
12}
13
14build = {
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
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