Small cross-platform Lua bindings for terminal inspection.
Supports Lua 5.1, 5.2, 5.3, 5.4, 5.5, and LuaJIT.
luarocks install ttylocal tty = require "tty"
print(tty.isatty()) --> stdout
print(tty.isatty(2)) --> stderrlocal tty = require "tty"
local rows, cols = tty.size() --> stdout
local erows, ecols = tty.size(2) --> stderrfd is optional. Default: 1 (stdout). tty.size() raises if size lookup fails. Both functions also raise on invalid arguments or closed file handles.
- Enable color or interactive output only when running in a real terminal
- Use richer log formatting in terminals and simpler output when logs are redirected
- Adjust CLI layouts to the current terminal width and height
- Detect redirected output and switch to plain, non-interactive formatting
- Build terminal UIs, status views, or progress displays that depend on terminal size