This is Civboot's VT100 terminal interface library. It implements (and also
defines) the API that civboot terminal emulators must implement to be
considered Civboot compliant.
It has the following core types and constants:
- Term object, see below
- AsciiColor which is a map from single ascii lowercase characters to the
color name (i.e. w -> white). These can be used in Term.fg and Term.bg to
set the relvant colors.
- FgColor and BgColor contains a map from the color name to the VT100 color
code (for external libraries).
- Various key utility functions and maps for checking and working with the
values sent by Term:input()
To be civboot compliant the
Term type exported must have the following API:
- ds.Grid fields text, fg, bg for terminal text, foreground color and
background color respectively
- l, c fields for setting the cursor location (which is drawn)
- h, w (height width) fields (see resize())
- :input(keysend) method which asyncronously (LAP) sends any user-inputed keys
- :draw() method which draws the text
- :resize() method that (if nothing is passed to it) retrieves the h, w
fields and updates and clears child grids.
- :clear() method which clears all child grids.
- run boolean (default=true) which can be set to false to stop related
coroutines (best effort)
Civboot vt100 Terminal library that supports LAP protocol.
Module for interacting with the vt100 via keys and AsciiColors.
License CC0 / UNLICENSE
Originally written 2022 Phil Leblanc, modified 2023 Rett Berg (Civboot.org)
Authorized for relicense in: http://github.com/philanc/plterm/issues/4
Types: ctrl Term
Functions
Direct terminal control functions
Functions
- fn show(name, fmt)
- fn color(name, fmt)
- fn reset(name, fmt)
- fn save(name, fmt)
- fn nextline(name, fmt)
- fn restore(name, fmt)
- fn golc(name, fmt)
- fn left(name, fmt)
- fn getlc(name, fmt)
- fn hide(name, fmt)
- fn clear(name, fmt)
- fn cleareol(name, fmt)
- fn colorFB(name, fmt)
- fn up(name, fmt)
- fn right(name, fmt)
- fn down(name, fmt)
- fn size(f)
causes terminal to send size as (escaped) cursor position
VT100 Terminal Emulator
- Write the text to display
- Write the foreground/background colors to fg/bg
- Then call :draw() to draw to terminal.
Requires
vt100.start() have been called to initiate raw mode.
Fields:
- .fdfile to write output to in draw()
- .l =1cursor line
- .c =1cursor column
- .h =40height
- .w =80width
- .textthe text to display
- .fgforeground color (ASCII coded)
- .bgbackground color (ASCII coded)
- .run =trueset to false to stop coroutines
- .styleroptional styler
Methods
- fn clear(tm)
- fn resize(tm)
request size and clear children
This can only be run with an active (LAP) input coroutine
- fn draw(tm)
draw the text and color(fg/bg) grids to the screen
- fn input(tm, send) -> infinite loop (run in coroutine)
function to run in a (LAP) coroutine.
send() is called with each key recieved. Typically this is a lap.Send.
Fields:
- .f
- .fg ="z"current foreground ac letter
- .bg ="z"current background ac letter
Methods
- fn flush(aw) -> aw.f:flush()
- fn acwrite(aw, fgstr, bgstr, ...) -> write(...)
:acwrite(fgstr, bgstr, str, ...): writes str with style of fg/bg str
- fn write(aw, ...) -> aw:acwrite(nil, nil, ...)
write plain
helpers for testing/demoing vt100
Types: Fake
Functions
- fn startTmp() -> out, err
start rawmode using tmpfiles
- fn run(fn)
Run function in a LAP environment with terminal started
and std in/out set correctly.
Fields:
- .fdfile to write output to in draw()
- .l =1cursor line
- .c =1cursor column
- .h =40height
- .w =80width
- .textthe text to display
- .fgforeground color (ASCII coded)
- .bgbackground color (ASCII coded)
- .run =trueset to false to stop coroutines
- .styleroptional styler
Methods