• Stars
    star
    134
  • Rank 261,187 (Top 6 %)
  • Language
    Lua
  • License
    MIT License
  • Created almost 12 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Terminal operations for Lua

Overview

lua-term is a Lua module for manipulating a terminal.

Installation

lua-term is available on Luarocks.

OpenBSD

lua-term is available as an OpenBSD package. Use the proper Lua flavour to get the package for your Lua version:

# For Lua 5.1
$ doas pkg_add -r lua-term
# For Lua 5.2
$ doas pkg_add -r lua52-term
# For Lua 5.3
$ doas pkg_add -r lua53-term

Or install from ports:

$ cd /usr/ports/devel/lua-term
$ env FLAVOR=lua51 doas make install

openSUSE

lua-term is available in the devel:languages:lua devel project on OBS.

Add the repository and install lua-term via:

zypper addrepo http://download.opensuse.org/repositories/devel:/languages:/lua/openSUSE_Tumbleweed/devel:languages:lua.repo
zypper refresh
zypper in lua-luaterm

Adjust the repository URL to your version of openSUSE by substituting openSUSE_Tumbleweed with your actual version eg opensSUSE_42.2.

Usage

    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) -- It will fail in Lua >= 5.2 because goto is a reserved word.
    term.cursor['goto'](1, 1) -- This will work on Lua >= 5.2, please use jump instead
    term.cursor.jump(1, 1) -- jump is just an alias for goto
    term.cursor.jump(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

print(colors.red 'hello')

As a String

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

More Repositories

1

lua-repl

A Lua REPL implemented in Lua for embedding in other programs
Lua
157
star
2

linotify

Inotify bindings for Lua
C
95
star
3

pluto

Heavy Duty Persistence for Lua
C
79
star
4

obvious

Widget library for the awesome window manager
Lua
65
star
5

lua-linenoise

Lua bindings for linenoise with UTF-8 support (https://github.com/yhirose/linenoise/tree/utf8-support)
C
46
star
6

linux-fake-battery-module

Fake Battery Module for the Linux kernel
C
39
star
7

tw-full-text-search

Full text search plugin for TiddlyWiki powered by lunr.js
JavaScript
24
star
8

ansicolors

ANSI terminal color manipulation for Lua.
Lua
23
star
9

sqlite-lua-extension

A SQLite extension that embeds a Lua interpreter into SQLite
C
19
star
10

lunr-mutable-indexes

Mutable indexes for lunr.js 2.1.x
JavaScript
19
star
11

git-pisect

Parallel regression finder for Git
Perl
19
star
12

lua-procure

A Pure Lua implementation of require()
Perl
18
star
13

idea-fight

A web application for helping you decide the priorities of your ideas
Elm
17
star
14

useful-scripts

Scripts from my private ~/bin-tage
Perl
16
star
15

vim-split-navigate

An experimental method for jumping to lines on screen
Vim Script
11
star
16

ruby-keepass

Ruby binding for libkpass
C
11
star
17

lua-typical

Fancy type names for Lua
Lua
10
star
18

awesome-config

My Awesome configuration
Lua
10
star
19

dotfiles

My dotfiles
Perl
9
star
20

queqiao

A higher-level interface for writing Vim plugins in Lua
Lua
9
star
21

twitter-reply-tracker

Provides a mechanism for tracking replies to a tweet, as well as a UI for searching them
TypeScript
8
star
22

luabdb

A Berkeley DB binding for Lua.
C
8
star
23

term-drawille

Draw to your terminal using Braille characters
Perl
8
star
24

vimfiles

My $HOME/.vim directory
Vim Script
7
star
25

vim-elm-help

Offline Elm documentation access in your editor
Perl
7
star
26

sahara-sync

A free software (AGPL) alternative to Dropbox
Perl
7
star
27

luaperl

A Lua-Perl bridge for Lua
C
7
star
28

luael

Libedit bindings for Lua.
C
7
star
29

tiddlywiki-first-class-urls

An experimental plugin to make importing tiddlers easier
JavaScript
7
star
30

elm-drag

Track dragging motions when the mouse is down
Elm
6
star
31

tw-progress-bar

Progress bar widget for TiddlyWiki
JavaScript
6
star
32

elm-typing-tutor

A typing tutor for Russian written in Elm
Elm
6
star
33

firefox-keepass-autofill

Automatically fill in username/password combinations from a Keepass database.
JavaScript
5
star
34

language-of-the-month

Programming projects for language of the month (http://hoelz.ro/blog/language-of-the-month)
Elixir
5
star
35

autopilot

A daemon that allows you to automate actions to occur on changes in your computer's state
C
4
star
36

vim-temporal-marks

Temporal marks for Vim
Vim Script
4
star
37

harbour-sudoku

Sudoku application for SailfishOS
QML
4
star
38

lua-proctitle

Set your process' name from Lua so that it shows up differently in programs like ps or netstat
C
4
star
39

p6-io-string

IO::String for Perl6
Perl 6
4
star
40

semantic-diff

Semantic diff tool for Python 2
Python
4
star
41

zsh-config

My ZSH configuration
Shell
4
star
42

inline-lua

Perl extension for embedding Lua scripts into Perl code
C
4
star
43

app-musicfind

Musicfind is a tool similar to find(1), but for manipulating music files
Perl
3
star
44

tw-modern-jasmine

Jasmine 3.x plugin for TiddlyWiki
JavaScript
3
star
45

p6-xapian

Xapian bindings for Perl 6
Perl 6
3
star
46

dist-zilla-plugin-test-localbrew

Verify that your distribution tests well in a fresh perlbrew
Perl
3
star
47

plack-middleware-options

Implements HTTP OPTIONS method for Plack
Perl
3
star
48

sqlite-attribute-vtable

Attributes virtual table extension for SQLite
C
3
star
49

Mac-FSEvents

Release history of Mac-FSEvents
C
3
star
50

p6-native-resources

Boilerplate helper for bundling native code
Perl 6
3
star
51

bashrc

Bash configuration
Shell
3
star
52

hexe

An XMPP chatbot written in Perl 6
Perl 6
3
star
53

devel-repl-plugin-editor

Drop into your favorite editor from Devel::REPL
Perl
3
star
54

wwid

A todo list manager that tells you what to do
Perl
2
star
55

track-spotify-plays

Lambda function to log my recently played songs from Spotify
Python
2
star
56

sqlite-lua-vtable

Implement SQLite virtual tables using Lua
C
2
star
57

text-dokuwiki

Perl implementation of the DokuWiki parser
Perl
2
star
58

p6-priorityqueue

A priority queue data structure for Perl 6
Perl 6
2
star
59

lua-iterators

A Lua library for manipulating iterators
2
star
60

bash-completion-plugins-perlbrew

Perlbrew completion for bash
Perl
2
star
61

plack-test-anyevent

Test streaming PSGI-based applications using AnyEvent
Perl
2
star
62

lua-tracer

Reload-free print debugging for Lua
Lua
2
star
63

plack-middleware-recorder

PSGI middleware for recording requests
Perl
2
star
64

p6-test-meta

A test library for testing test libraries
Perl
2
star
65

advent-of-code

Solutions to Advent of Code
Go
2
star
66

perl6-syntax

Editor support for Perl 6
Vim Script
2
star
67

elm-jargon

A repository of terminology used by the Elm community.
2
star
68

p6-algorithm-lcs

Implementation of longest common subsequence in Perl 6
Perl 6
2
star
69

p6-pod-eod

Moves declarative POD blocks to the end of the POD
Perl 6
2
star
70

devel-repl-plugin-lazyload

Lazily load modules in your Devel::REPL
Perl
1
star
71

dzil-config

My Dist::Zilla configuration
Perl
1
star
72

mytrace

strace for MySQL
C
1
star
73

app-intelligentsia

Intelligentsia is a Identica/Twitter client written in Perl.
Perl
1
star
74

cpan-highlight

Google Chrome extension to highlight source code viewed on the CPAN
JavaScript
1
star
75

p6-rbtree

Red-black tree implementation for Perl 6
Perl 6
1
star
76

bash-completion-plugins-dzil

Bash::Completion support for Dist::Zilla
Perl
1
star
77

xmpp-talk

The XMPP presentation I'm giving at MadMongers in December
TeX
1
star
78

smart-alloc

A memory allocator for C
C
1
star
79

dzil-talk

The Dist::Zilla talk I'm giving at MadMongers in September
1
star
80

perl-power-tools

Slides for my Perl Power Tools Talk
JavaScript
1
star
81

bash-completion-plugin-test

Module for testing Bash::Completion plugins
Perl
1
star
82

perl-objectivec

Objective-C bridge for Perl
C
1
star
83

p6-class-contract

Class invariants for Perl 6
Perl 6
1
star
84

elm-tetris

An implementation of Tetris in Elm
Elm
1
star
85

dancer-plugin-couchdb

CouchDB plugin for Dancer
Perl
1
star
86

pyweek-2014

PyWeek entry for 2014
Python
1
star
87

fx-visit-history

Shows your first and most recent visit to a page
JavaScript
1
star
88

dev-study

Implementations of algorithms for study exercises
C
1
star
89

term-emulator

A Perl module to interpret and handle terminal escape sequences
Perl
1
star
90

blog

Source code and pages for my blog
JavaScript
1
star
91

plack-middleware-acme-yadayada

Middleware for handling the yada yada operator
Perl
1
star
92

luarepl-evlib

Use luarepl with an asynchronous event loop
C
1
star
93

vimlint

A lint-style tool for Vimscript
1
star
94

p6-algorithm-elo

Implementation of the Elo chess algorithm for Perl 6
Perl 6
1
star
95

mazes-for-programmers

https://pragprog.com/titles/jbmaze/mazes-for-programmers/
Rust
1
star
96

plack-middleware-setaccept

Sets the Accept header based on the suffix or query params of a request
Perl
1
star
97

mail-scripts

Perl scripts for organizing my e-mail
Perl
1
star
98

fx-zoom-lock

Prevents zooming on webpages
JavaScript
1
star
99

lua-talk

The sources for the talk I'm giving to HackersNL in November 2012
Lua
1
star
100

p6-test-differences

Test::Differences for Perl 6
Perl
1
star