zgo.at/termfo Index | Files | Directories

package termfo

import "zgo.at/termfo"

Index

Package Files

load.go param.go termfo.go

type Event

type Event struct {
    Key keys.Key // Processed key that was pressed.
    Seq []byte   // Unprocessed text; only usedful for debugging really.
    Err error    // Error; only set for read errors.
}

Event sent by FindKeys.

type Terminfo

type Terminfo struct {
    Name     string   // Main name as listed in the terminfo file.
    Desc     string   // Some textual description.
    Aliases  []string // Aliases for this terminal.
    Location string   // Where it was loaded from; path or "builtin".

    Bools   map[*caps.Cap]struct{} // Boolean capabilities.
    Numbers map[*caps.Cap]int32    // Number capabilities.
    Strings map[*caps.Cap]string   // String capabilities.

    // Capabilities listed in the "extended" section. The values are in the
    // Bools, Numbers, and Strings maps.
    Extended []*caps.Cap

    // The default format uses int16, but the "extended number format" uses
    // int32. This lists the integer size as 2 or 4.
    IntSize int

    // List of keys, as sequence → Key mapping. e.g. "\x1b[OP" → KeyF1.
    //
    // This contains all key_* capabilities, plus a few generated ones for
    // modifier keys and such.
    Keys map[string]keys.Key
}

Terminfo describes the terminfo database for a single terminal.

func New

func New(term string) (*Terminfo, error)

New reads the terminfo for term. If term is an empty string then the value of the TERM environment variable is used.

It tries to load a terminfo file according to these rules:

  1. Use the path in TERMINFO if it's set and don't search any other locations.

  2. Try built-in ones unless set NO_BUILTIN_TERMINFO is set.

  3. Try ~/.terminfo/ as the database path.

  4. Look in the paths listed in TERMINFO_DIRS.

  5. Look in /lib/terminfo/

  6. Look in /usr/share/terminfo/

These are the same rules as ncurses, except that step 2 was added.

TODO: curses allows setting a different path at compile-time; we can use infocmp -D to get this. Probably want to add this as step 7(?)

func (Terminfo) FindKey

func (ti Terminfo) FindKey(b []byte) (keys.Key, int)

Find the first valid keypress in s.

Returns the key and number of bytes processed. On errors it will return UnknownSequence and the length of the string.

func (Terminfo) FindKeys

func (ti Terminfo) FindKeys(fp io.Reader) <-chan Event

FindKeys finds all keys in the given reader (usually stdin) and sends them in the channel.

Any read error will send an Event with Err set and it will stop reading keys.

func (Terminfo) Get

func (ti Terminfo) Get(c *caps.Cap, args ...int) string

Get a capability.

func (Terminfo) Put

func (ti Terminfo) Put(w io.Writer, c *caps.Cap, args ...int)

func (Terminfo) String

func (ti Terminfo) String() string

func (Terminfo) Supports

func (ti Terminfo) Supports(c *caps.Cap) bool

Supports reports if this terminal supports the given capability.

Directories

PathSynopsis
capsPackage caps contains a list of all terminfo capabilities.
cmd
cmd/termfoProgram termfo prints information about the terminfo database.
cmd/termfo/internal
keys
scapsPackage scaps contains a list of all terminfo capabilities.
Version
v0.0.0-20211026013349-562012204b75 (latest)
Published
Oct 26, 2021
Platform
linux/amd64
Imports
14 packages (graph)
Last checked
1 month ago

Tools for package owners.