pax_global_header00006660000000000000000000000064123270345630014517gustar00rootroot0000000000000052 comment=e1914344916d59c7afa967827f95515bccf5624a lua-term-0.03.20140426.g1ba9a8e/000077500000000000000000000000001232703456300153705ustar00rootroot00000000000000lua-term-0.03.20140426.g1ba9a8e/.gitignore000066400000000000000000000000201232703456300173500ustar00rootroot00000000000000*.o *.so *.rock lua-term-0.03.20140426.g1ba9a8e/CHANGES000066400000000000000000000006721232703456300163700ustar00rootroot000000000000000.03 2014-04-02 08:00:00 - Fix syntax error for term.cursor.goto for Lua 5.2 - Add jump as an alias for goto 0.02 2013-02-21 21:15:00 - Add cursor functions. - Add clear functions. - Deprecate term.isatty. Use luaposix instead. - Add colors.default as a synonym for colors.reset. - The metatable for colors is no longer hidden. 0.01 2012-06-25 23:30:00 - Initial release. Includes colors and isatty. lua-term-0.03.20140426.g1ba9a8e/COPYING000066400000000000000000000020571232703456300164270ustar00rootroot00000000000000Copyright (c) 2009 Rob Hoelz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. lua-term-0.03.20140426.g1ba9a8e/Makefile000066400000000000000000000015321232703456300170310ustar00rootroot00000000000000#this file builds lua-term \o/ LUA_VER := 5.1 LUA_DIR := /usr LUA_LIBDIR := $(LUA_DIR)/lib/lua/$(LUA_VER)/term LUA_INC := $(LUA_DIR)/include/lua$(LUA_VER) LUA_SHARE := $(LUA_DIR)/share/lua/$(LUA_VER)/term CWARNS := -Wall -pedantic CFLAGS := $(CWARNS) -ansi -O3 -I$(LUA_INC) -fPIC LIB_OPTION := -shared SONAME := core.so SONAMEV := $(SONAME).1 LIBRARY := $(SONAMEV).0.1 SRC := core.c OBJ := $(patsubst %.c, %.o, $(SRC)) FILES := term/init.lua term/cursor.lua term/colors.lua all: $(LIBRARY) $(SONAMEV) $(SONAME) $(SONAMEV): ln -s $(LIBRARY) $@ $(SONAME): ln -s $(SONAMEV) $@ $(LIBRARY): $(OBJ) $(CC) $(CFLAGS) $(LIB_OPTION) -o $(LIBRARY) $(OBJ) -lc install: mkdir -p $(LUA_LIBDIR) cp $(SONAME) $(LUA_LIBDIR) mkdir -p $(LUA_SHARE) cp $(FILES) $(LUA_SHARE) clean: $(RM) $(LIBRARY) $(SONAMEV) $(SONAME) *.o lua-term-0.03.20140426.g1ba9a8e/README.md000066400000000000000000000062261232703456300166550ustar00rootroot00000000000000Overview -------- lua-term is a Lua module for manipulating a terminal. Installation ------------ lua-term is available on Luarocks. Usage ----- ```lua local term = require 'term' local colors = term.colors -- or require 'term.colors' print(term.isatty(io.stdout)) -- true if standard output goes to the terminal print(colors.red 'hello') print(colors.red .. 'hello' .. colors.reset) print(colors.red, 'hello', colors.reset) -- The following functions take an optional IO handle (like io.stdout); -- io.stdout is the default if you don't specify one term.clear() -- clears the screen term.cleareol() -- clears from the cursor to the end of the line term.cursor.goto(1, 1) term.cursor.jump(1, 1) -- jump is just an alias for goto term.cursor.goto(io.stdout, 1, 1) term.cursor.goup(1) term.cursor.godown(1) term.cursor.goright(1) term.cursor.goleft(1) term.cursor.save() -- save position term.cursor.restore() -- restore position ``` `term` Functions -------------- Some functions in lua-term take an optional file handle argument; if this is not provided, `io.stdout` is used. ### `term.clear([opt_file])` Clear the terminal's contents. ### `term.cleareol([opt_file])` Clear from the current cursor position to the end of the current line. ### `term.isatty(file)` Returns `true` if `file` is a TTY; `false` otherwise. *NOTE*: This function has been deprecated in favor of luaposix's implementation. If you would like this functionality in the future, please use luaposix. `term.colors` Values ------------------ The following values are available in `term.colors`: ### Terminal Attributes * reset * clear (a synonym for reset) * default (a synonym for reset) * bright * dim * underscore * blink * reverse * hidden ### Foreground Colors * black * red * green * yellow * blue * magenta * cyan * white ### Background Colors * onblack * onred * ongreen * onyellow * onblue * onmagenta * oncyan * onwhite Every value in `term.colors` may be used in several ways: ### As a Function ```lua print(colors.red 'hello') ``` ### As a String ```lua print(colors.red .. 'hello' .. colors.reset) print(colors.red, 'hello', colors.reset) ``` `term.cursor` Functions --------------------- ### `term.cursor.goto([opt_file], x, y)` Place the cursor at (`x`, `y`). ### `term.cursor.jump([opt_file], x, y)` An alias for `term.cursor.goto`. ### `term.cursor.goup([opt_file], nlines)` Moves the cursor up `nlines` lines. ### `term.cursor.godown([opt_file], nlines)` Moves the cursor down `nlines` lines. ### `term.cursor.goright([opt_file], ncols)` Moves the cursor right `ncols` columns. ### `term.cursor.goleft([opt_file], ncols)` Moves the cursor left `ncols` columns. ### `term.cursor.save([opt_file])` Saves the cursor position. ### `term.cursor.restore([opt_file])` Restores the cursor position. Alternatives ------------ If you are looking to simply provide coloration to a terminal application and would like to use a more "tag-like" API (ex. `colors '%{red}hello%{reset}'`), there is a Lua rock named ansicolors: https://github.com/kikito/ansicolors.lua lua-term-0.03.20140426.g1ba9a8e/core.c000066400000000000000000000005671232703456300164740ustar00rootroot00000000000000#include #include #include static int lua_isatty(lua_State *L) { FILE **fp = (FILE **) luaL_checkudata(L, -1, LUA_FILEHANDLE); lua_pushboolean(L, isatty(fileno(*fp))); return 1; } int luaopen_term_core(lua_State *L) { lua_newtable(L); lua_pushcfunction(L, lua_isatty); lua_setfield(L, -2, "isatty"); return 1; } lua-term-0.03.20140426.g1ba9a8e/lua-term-0.3-1.rockspec000066400000000000000000000007501232703456300213070ustar00rootroot00000000000000package = 'lua-term' version = '0.3-1' source = { url = 'https://github.com/hoelzro/lua-term/archive/0.03.tar.gz', dir = 'lua-term-0.03', } description = { summary = 'Terminal functions for Lua', homepage = 'https://github.com/hoelzro/lua-term', license = "MIT/X11", } build = { modules = { ['term'] = 'term/init.lua', ['term.colors'] = 'term/colors.lua', ['term.cursor'] = 'term/cursor.lua', ['term.core'] = 'core.c', }, type = 'builtin', } lua-term-0.03.20140426.g1ba9a8e/term/000077500000000000000000000000001232703456300163375ustar00rootroot00000000000000lua-term-0.03.20140426.g1ba9a8e/term/colors.lua000066400000000000000000000043161232703456300203470ustar00rootroot00000000000000-- Copyright (c) 2009 Rob Hoelz -- -- Permission is hereby granted, free of charge, to any person obtaining a copy -- of this software and associated documentation files (the "Software"), to deal -- in the Software without restriction, including without limitation the rights -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -- copies of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be included in -- all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -- THE SOFTWARE. local pairs = pairs local tostring = tostring local setmetatable = setmetatable local schar = string.char local colors = {} local colormt = {} function colormt:__tostring() return self.value end function colormt:__concat(other) return tostring(self) .. tostring(other) end function colormt:__call(s) return self .. s .. colors.reset end local function makecolor(value) return setmetatable({ value = schar(27) .. '[' .. tostring(value) .. 'm' }, colormt) end local colorvalues = { -- attributes reset = 0, clear = 0, default = 0, bright = 1, dim = 2, underscore = 4, blink = 5, reverse = 7, hidden = 8, -- foreground black = 30, red = 31, green = 32, yellow = 33, blue = 34, magenta = 35, cyan = 36, white = 37, -- background onblack = 40, onred = 41, ongreen = 42, onyellow = 43, onblue = 44, onmagenta = 45, oncyan = 46, onwhite = 47, } for c, v in pairs(colorvalues) do colors[c] = makecolor(v) end return colors lua-term-0.03.20140426.g1ba9a8e/term/cursor.lua000066400000000000000000000027251232703456300203650ustar00rootroot00000000000000-- Copyright (c) 2009 Rob Hoelz -- -- Permission is hereby granted, free of charge, to any person obtaining a copy -- of this software and associated documentation files (the "Software"), to deal -- in the Software without restriction, including without limitation the rights -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -- copies of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be included in -- all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -- THE SOFTWARE. local term = require 'term.core' local cursor = { ['goto'] = term.maketermfunc '%d;%dH', goup = term.maketermfunc '%d;A', godown = term.maketermfunc '%d;B', goright = term.maketermfunc '%d;C', goleft = term.maketermfunc '%d;D', save = term.maketermfunc 's', restore = term.maketermfunc 'u', } cursor.jump = cursor['goto'] return cursor lua-term-0.03.20140426.g1ba9a8e/term/init.lua000066400000000000000000000032721232703456300200110ustar00rootroot00000000000000-- Copyright (c) 2009 Rob Hoelz -- -- Permission is hereby granted, free of charge, to any person obtaining a copy -- of this software and associated documentation files (the "Software"), to deal -- in the Software without restriction, including without limitation the rights -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -- copies of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be included in -- all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -- THE SOFTWARE. local term = require 'term.core' local sformat = string.format local iotype = io.type local stdout = io.stdout function term.maketermfunc(sequence_fmt) sequence_fmt = '\027[' .. sequence_fmt local func func = function(handle, ...) if iotype(handle) ~= 'file' then return func(stdout, handle, ...) end return handle:write(sformat(sequence_fmt, ...)) end return func end term.colors = require 'term.colors' term.cursor = require 'term.cursor' term.clear = term.maketermfunc '2J' term.cleareol = term.maketermfunc 'K' term.maketermfunc = nil return term