[ANN] new release of LuaSystem: terminal functions

98 views
Skip to first unread message

Thijs Schreijer

unread,
Jun 20, 2024, 6:30:58 PM (12 days ago) Jun 20
to lu...@googlegroups.com
Hi list,

I'm happy to announce a new release of LuaSystem. LuaSystem is a library that provides bindings to OS functions in an (if possible) platform agnostic way.

The new release 0.4.0 adds a lot of new terminal functions. Since version 0.3.0 wasn't announced I'll include that in this update as well.

0.3.0 main features:
- isatty: is a file a tty?
- setenv: set environment variables
- getenvs: list environment variables
- random: get solid random bytes (from /dev/urandom or CryptGenRandom)

0.4.0 main features:
- configure the console (tcsetattr/tcgetattr or get/setconsoleflags)
- getting terminal size
- utf8 character display-width
- reading (non-blocking) keyboard input

Since terminals are fundamentally different, most terminal functions are not cross-platform but per-platform. But this still provides the capability to produce cross-platform terminal applications.

Docs are here: https://lunarmodules.github.io/luasystem/index.html
If interested in the terminal specifics then definitely read this: https://lunarmodules.github.io/luasystem/topics/03-terminal.md.html

Installation is easiest using LuaRocks.

Feedback welcome.

Thijs

Sainan

unread,
Jun 20, 2024, 6:58:19 PM (12 days ago) Jun 20
to lu...@googlegroups.com
Non-blocking STDIN read is pretty based, and feels like something that would fit pretty well in Lua itself since coroutines are pretty solid, but I guess it's not too portable. I should look into it a bit in the future.

Martin Eden

unread,
Jun 21, 2024, 9:50:50 AM (12 days ago) Jun 21
to lu...@googlegroups.com

On 2024-06-21 00:30, 'Thijs Schreijer' via lua-l wrote:
> Hi list,
>
> I'm happy to announce a new release of LuaSystem. LuaSystem is a library that provides bindings to OS functions in an (if possible) platform agnostic way.
>
> [...]
> [...]
>
> Feedback welcome.
>
> Thijs
Hi Thijs, nice docs layout!

I'm surprised you've not abstracted ANSI text calls. I've done it in
[1] for pstra() and in [2] for GotoXY() and GetScreenSize().

ANSI codes is a can of worms actually. No real sane standard and lot of
ad hoc extensions. But anyway, encapsulating functionality you need
is not hard and better than writing 'local move_left = "\27[1D"'
in game code.

[1]:
https://github.com/martin-eden/workshop/blob/master/frontend/ansitext/get_ansi_str.lua
[2]:
https://github.com/martin-eden/workshop/blob/master/frontend/AnsiTerm/Interface.lua

-- Martin

Rett Berg

unread,
Jun 21, 2024, 5:36:22 PM (11 days ago) Jun 21
to lua-l
You might be interested in my implementation of term input in https://github.com/civboot/civlua/blob/63f7c3f8f1d1064b52996f5ca33bdfad82d39c6e/lib/civix/civix/term.lua#L108

It was originally based on http://github.com/philanc/plterm but I've added a bunch of features, like auto-converting to human-readable/writeable keys (i.e. return instead of the number 13)

It also has functions `literal()` to convert these to strings (when possible, i.e. 'tab' -> '\t') and `checkKey()` so that you can validate your editor's bindings.

Best,
Rett

Thijs Schreijer

unread,
Jun 21, 2024, 5:59:10 PM (11 days ago) Jun 21
to lu...@googlegroups.com


On Fri, 21 Jun 2024, at 15:50, 'Martin Eden' via lua-l wrote:
> Hi Thijs, nice docs layout!

Thx. but that is just plain old Ldoc.

>
> I'm surprised you've not abstracted ANSI text calls. I've done it in
> [1] for pstra() and in [2] for GotoXY() and GetScreenSize().
>
> ANSI codes is a can of worms actually.

LuaSystem does the interface part, or the primitives you can use to build your own if you like. It handles the C part, the stuff that cannot be done in Lua. Similar to luafilesystem, or luasocket if you like. This is mostly where the random numbers, time functions and listing environment variables come in.

All terminal code I've seen so far is Posix only. LuaSystem also supports terminals on Windows. Due to the completely different type of implementations it can unfortunately not be done "cross platform" like the rest, hence most functions are "per platform".

Especially the input part is hard, since Windows pretty much does everything thread-based, and hence is always blocking. Whereas Posix does it file-based, (optionally) non-blocking. So very hard to abstract away.


> No real sane standard and lot of
> ad hoc extensions. But anyway, encapsulating functionality you need
> is not hard and better than writing 'local move_left = "\27[1D"'
> in game code.
>

This can be done on top of LuaSystem.

regards
Thijs

Thijs Schreijer

unread,
Jun 21, 2024, 6:01:08 PM (11 days ago) Jun 21
to lu...@googlegroups.com


On Fri, 21 Jun 2024, at 23:36, Rett Berg wrote:

It was originally based on http://github.com/philanc/plterm but I've added a bunch of features, like auto-converting to human-readable/writeable keys (i.e. return instead of the number 13)

It also has functions `literal()` to convert these to strings (when possible, i.e. 'tab' -> '\t') and `checkKey()` so that you can validate your editor's bindings.

Also here: it lacks Windows support.

Reply all
Reply to author
Forward
0 new messages