Skip to content

luamod/tty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tty

Small cross-platform Lua bindings for terminal inspection.

Supports Lua 5.1, 5.2, 5.3, 5.4, 5.5, and LuaJIT.

Install

luarocks install tty

API

tty.isatty(fd?) -> boolean

local tty = require "tty"
print(tty.isatty())  --> stdout
print(tty.isatty(2)) --> stderr

tty.size(fd?) -> rows, cols

local tty = require "tty"
local rows, cols = tty.size()    --> stdout
local erows, ecols = tty.size(2) --> stderr

fd is optional. Default: 1 (stdout). tty.size() raises if size lookup fails. Both functions also raise on invalid arguments or closed file handles.

Use Cases

  • 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

About

Cross-platform Lua bindings for terminal inspection

Topics

Resources

License

Stars

Watchers

Forks

Contributors