Raku Land

Termbox

cpan:JJATRIA

NAME

Termbox

DESCRIPTION

Termbox is "a library for writing text-based user interfaces". This module provides Raku bindings to this library.

SYNOPSIS

use Termbox :ALL;

if tb-init() -> $ret {
    note "tb-init() failed with error code $ret";
    exit 1;
}

END tb-shutdown;

for "Press ESC to exit!".encode.list -> $c {
    state $x = 5;
    tb-change-cell( $x++, 5, $c, TB_COLOR_BLACK, TB_COLOR_WHITE );
}

tb-present;

my $events = Supplier.new;
start {
    while tb-poll-event( my $ev = Termbox::Event.new ) { $events.emit: $ev }
}

react whenever $events.Supply -> $ev {
    given $ev.type {
        when TB_EVENT_KEY {
            given $ev.key {
                when TB_KEY_ESC { done }
            }
        }
    }
}

FUNCTIONS

None of the following functions are exported by default. They can be accessed through the Termbox package (as in Termbox::init) or imported with the :subs tag. When imported, they gain the tb- prefix (such that init becomes tb-init, etc).

Basic functions

init

shutdown

width

height

clear

present

put-cell

change-cell

blit

cell-buffer

select-input-mode

select-output-mode

peek-event

poll-event

utf8-char-to-unicode

See also encode-string for a higher-level version of this function.

utf8-unicode-to-char

See also decode-string for a higher-level version of this function.

Additional functions

The following functions are added as a convenience for the UTF-8 helpers provided by Termbox itself. These are likely much simpler to use in Raku code.

encode-string

Takes a non-empty string and returns an Int representing the number used to encode it by Termbox.

On error throws an exception.

decode-string

Takes an Int with the integer representation of a string (such as that returned by encode-string and returns it decoded as a Str.

On error throws an exception.

CONSTANTS

Like with the functions described above, none of the following constants are exported by default. They can be accessed through the Termbox package (as in Termbox::WHITE) or imported with the different tags described below.

When imported, they gain the TB_ prefix (such that WHITE becomes TB_WHITE, etc).

Keys

Imported with the :keys tag.

These are a safe subset of terminfo keys, which exist on all popular terminals. Use only these to stay "truly portable", according to the Termbox documentation.

The rest are ASCII code points below SPACE character and a BACKSPACE key.

These are modifier constants. MOD_MOTION in a mouse event indicates a dragging event.

Styles

Imported with the :styles tag.

These are font attributes. It is possible to use multiple attributes by combining them using bitwise OR (+|). Although, colors cannot be combined, you can combine attributes and a single color.

Errors

Imported with the :errors tag.

Events

Imported with the :events tag.

Modes

Imported with the :modes tag.

AUTHOR

José Joaquín Atria jjatria@cpan.org

COPYRIGHT AND LICENSE

Copyright 2020 José Joaquín Atria

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.