EXPORTS
Nothing per default, but can export the following per request:
:all
:api
Init
Close
Interrupt
Flush
SetCursor
HideCursor
SetCell
GetCell
SetChar
SetFg
SetBg
CellBuffer
ParseEvent
PollRawEvent
PollEvent
Size
Clear
SetInputMode
SetOutputMode
Sync
NAME
Termbox::Go::Terminal - Terminal Termbox implementation
DESCRIPTION
This document describes the Termbox library for Perl, for the use of *nix terminal applications.
The advantage of the Termbox library is the use of an standard. Termbox contains a few functions with which terminal applications can be developed with high portability and interoperability.
COPYRIGHT AND LICENCE
This file is part of the port of Termbox.
Copyright (C) 2012 by termbox-go authors
This library content was taken from the termbox-go implementation of Termbox
which is licensed under MIT licence.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
AUTHORS
2024,2025 by J. Schneider https://github.com/brickpool/
DISCLAIMER OF WARRANTIES
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
REQUIRES
SEE ALSO
SUBROUTINES
CellBuffer
my \@arrayref = CellBuffer();
Returns a slice into the termbox's back buffer. You can get its dimensions using "Size" function. The slice remains valid as long as no "Clear" or "Flush" function calls were made after call to this function.
Clear
my $errno = Clear($fg, $bg);
Clears the internal back buffer.
Close
my $errno = Close();
Finalizes termbox library, should be called after successful initialization when termbox's functionality isn't required anymore.
Flush
my $errno = Flush();
Synchronizes the internal back buffer with the terminal.
GetCell
my \%Cell = GetCell($x, $y);
Returns the specified cell from the internal back buffer.
HideCursor
my $errno = HideCursor();
The shortcut for SetCursor(-1, -1).
Init
my $errno = Init();
Initializes termbox library. This function should be called before any other functions. After successful initialization, the library must be finalized using "Close" function.
Example usage:
my $err = Init();
if ($err != 0) {
die "Error: $err"
}
Close();
Interrupt
my $errno = Interrupt();
Interrupt an in-progress call to "PollEvent" by causing it to return EventInterrupt. Note that this function will block until the "PollEvent" function has successfully been interrupted.
ParseEvent
my \%event = ParseEvent($data);
After getting a raw event from PollRawEvent function call, you can parse it again into an ordinary one using termbox logic. That is parse an event as termbox would do it. Returned event in addition to usual Event struct fields sets N field to the amount of bytes used within data slice. If the length of data slice is zero or event cannot be parsed for some other reason, the function will return a special event type: EventNone.
IMPORTANT: EventNone may contain a non-zero N, which means you should skip these bytes, because termbox cannot recognize them.
NOTE: This API is experimental and may change in future.
PollEvent
my \%Event = PollEvent();
Wait for an event and return it. This is a blocking function call.
PollRawEvent
my \%event = PollRawEvent($data);
Wait for an event and return it. This is a blocking function call. Instead of EventKey and EventMouse it returns EventRaw events. Raw event is written into data slice and Event's N field is set to the amount of bytes written. The minimum required length of the data slice is 1. This requirement may vary on different platforms.
NOTE: This API is experimental and may change in future.
SetBg
my $errno = SetBg($x, $y, $bg);
Changes cell's background attributes in the internal back buffer at the specified position.
SetCell
my $errno = SetCell($x, $y, $ch, $fg, $bg);
Changes cell's parameters in the internal back buffer at the specified position.
SetChar
my $errno = SetChar($x, $y, $ch);
Changes cell's character (utf8) in the internal back buffer at the specified position.
SetCursor
my $errno = SetCursor($x, $y);
Sets the position of the cursor. See also "HideCursor".
SetFg
my $errno = SetFg($x, $y, $fg);
Changes cell's foreground attributes in the internal back buffer at the specified position.
SetInputMode
my $current = SetInputMode($mode);
Sets termbox input mode. Termbox has two input modes:
1. Esc input mode. When ESC sequence is in the buffer and it doesn't match any known sequence. ESC means 'KeyEsc'. This is the default input mode.
2. Alt input mode. When ESC sequence is in the buffer and it doesn't match any known sequence. ESC enables 'ModAlt' modifier for the next keyboard event.
Both input modes can be OR'ed with Mouse mode. Setting Mouse mode bit up will enable mouse button press/release and drag events.
If $mode is 'InputCurrent', returns the current input mode. See also 'Input*' constants.
SetOutputMode
my $current = SetOutputMode($mode);
Sets the termbox output mode. Termbox has four output options:
1. OutputNormal => [1..8] This mode provides 8 different colors: black, red, green, yellow, blue, magenta, cyan, white Shortcut: ColorBlack, ColorRed, ... Attributes: AttrBold, AttrUnderline, AttrReverse
Example usage:
SetCell($x, $y, '@', ColorBlack | AttrBold, ColorRed);
2. Output256 => [1..256] In this mode you can leverage the 256 terminal mode: 0x01 - 0x08: the 8 colors as in OutputNormal 0x09 - 0x10: Color* | AttrBold 0x11 - 0xe8: 216 different colors 0xe9 - 0x1ff: 24 different shades of grey
Example usage:
SetCell($x, $y, '@', 184, 240);
SetCell($x, $y, '@', 0xb8, 0xf0);
3. Output216 => [1..216] This mode supports the 3rd range of the 256 mode only. But you don't need to provide an offset.
4. OutputGrayscale => [1..26] This mode supports the 4th range of the 256 mode and black and white colors from 3th range of the 256 mode But you don't need to provide an offset.
In all modes, 0x00 represents the default color.
perl examples/output.pl to see its impact on your terminal.
If $mode is 'OutputCurrent', it returns the current output mode.
Note that this may return a different OutputMode than the one requested, as the requested mode may not be available on the target platform.
Size
my ($x, $y) = Size();
Returns the size of the internal back buffer (which is mostly the same as terminal's window size in characters). But it doesn't always match the size of the terminal window, after the terminal size has changed, the internal back buffer will get in sync only after "Clear" or "Flush" function calls.
Sync
my $errno = Sync();
Sync comes handy when something causes desync between termbox's understanding of a terminal buffer and the reality. Such as a third party process. Sync forces a complete resync between the termbox and a terminal, it may not be visually pretty though.