https://github.com/max1220/lua-tmt
Simple lua binding for libtmt
https://github.com/max1220/lua-tmt
lua lua-bindings terminal-emulator terminal-emulators
Last synced: 3 months ago
JSON representation
Simple lua binding for libtmt
- Host: GitHub
- URL: https://github.com/max1220/lua-tmt
- Owner: max1220
- Created: 2018-07-19T09:27:29.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-25T23:02:41.000Z (almost 6 years ago)
- Last Synced: 2025-02-02T13:16:25.291Z (4 months ago)
- Topics: lua, lua-bindings, terminal-emulator, terminal-emulators
- Language: C
- Size: 12.7 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
lua-tmt
-------Simple lua binding for [libtmt](https://github.com/deadpixi/libtmt), the tiny mock terminal library.
This is a terminal emulation library, it takes strings with terminal escape sequences, and updates a cell-matrix and a few paramters accordingly.
With a library like [lpty](http://tset.de/lpty/index.html), one can create terminal multiplexers, or GUI terminal emulators.
Installation
------------After cloning the repository, or downloading the .zip, modify the makefile if needed. By default, it compiles using the Lua 5.1 headers.
Then build the project by running `make` in this folder.
The generated `tmt.so` is the Lua library and can be copied to your project path, or(to install systemwide) somewhere in lua's package.cpath.
To list Lua's default package.cpath from bash: `lua -e "print((package.cpath:gsub(';', '\n')))"`
Usage
-----The library(`tmt = require("tmt")`) exports one function(`tmt.new(w,h)`) and a lookup table(`tmt.special_keys[KEY_NAME] = terminal_escape_code`):
A terminal returned by `term = tmt.new` supports the following functions:* `events = term:write(str)` writes the string `str` to the terminal.
The string can contain terminal escape sequences supported by libtmt.
events is a table containing a list of events. Each events has a type.
The following events might be generated:* `screen` the screen content has been updated
* `bell` the terminal should do whatever bell should do
* `answer` the terminal has recived an answer. The answer is in the `answer`-field in the event's table
* `cursor` the cursor has moved. The new x,y is stored in the event's table at `x` and `y`.* `screen = term:get_screen()` gets the current screen content as a table.
The returned table contains 3 fields, `width`(screen width), `height`(screen height), and `lines`.
lines is a list of line-tables, each a list of cells, so that
`lines[y]` contains a line-table(list of cells), and
`lines[y][x]` contains a cell.Each line also contains a field `dirty`, which is true if the line was changed since it was last drawn.
Each cell is a table and has the following fields:
`char` (integer) The character number(convert to string using string.char)
`fg` (integer) The foreground ANSI terminal color
`bg` (integer) The background ANSI terminal color
`bold`, `dim`, `underline`, `blink`, `reverse`, `invisible` (boolean) character attributes* `x, y = term:get_cursor()` Gets the current cursor position.
* `width, height = term:get_size()` Gets the terminal size(columns, rows)
* `term:set_size(width, height)` Sets the terminal size to width, height(columns, rows)
Example
-------For a more complete example, see example_dump_screen.lua.
```
local tmt = require("tmt")
local term = tmt.new(80, 25)
term:write("Hello World!")
local screen = term:get_screen()
for _, cell in ipairs(screen.lines[1]) do
io.write(string.char(cell.char))
end
io.write("\n")
```