termbox

  1. termbox
    1. API
      1. Constants
    2. Examples
    3. Author
    4. Source Repository
    5. License

Chicken Scheme bindings for the library termbox. The API attempts to match the original library as closely as possible, with some slight scheme conveniences. This is done to maximize compatiblity and performance, but can appear a bit too "low-level". It is expected that you will write higher level abstractions, see the examples section.

The original header may provide helpful information as well.

API

[procedure] (termbox-init) -> Integer
[procedure] (termbox-shutdown)

Initializes the termbox library and returns 0 if succeeded. The init function should be called before any other functions. Shutdown must be called before exiting, otherwise the terminal may be left in an unusable state.

[procedure] (termbox-width) -> integer
[procedure] (termbox-height) -> integer

Returns the size of the internal back buffer (which is the same as terminal's window size in characters).

[procedure] (termbox-clear)

Clears the internal back buffer using default color or the color/attributes set by termbox-set-clear function.

[procedure] (termbox-set-clear [fg u16] [bg u16] )

Specifies the values that will be applied when calling termbox-clear.

[procedure] (termbox-present)

Synchronizes the internal back buffer with the terminal. In other words, presents changes to the terminal.

[procedure] (termbox-change-cell [x integer] [y integer] [c char] [fg u16] [bg u16])

Changes cell's parameters in the internal back buffer at the specified position.

[procedure] (termbox-set-cursor [x integer] [y integer])

Sets the position of the cursor. Upper-left character is (0, 0). Cursor is hidden by default.

[procedure] (termbox-hide-cursor)

Hides the cursor. Cursor can be shown again by calling termbox-set-cursor.

[procedure] (termbox-poll-event) -> list

Wait for an event forever and fill the 'event' structure with it, when the event is available. See below for event structure.

[procedure] (termbox-peek-event [timeout-millis integer]) -> list

Wait for an event up to 'timeout' milliseconds and return the event when available. An event is a list containing the following:

   (TYPE MOD KEY CHAR W H X Y).
[procedure] (termbox-copy-buffer [char-buffer u32vector] [fg-buffer u32vector] [bg-vector u32vector])

Copy data from vectors into the internal buffer. The char-buffer is the character codes for the characters.

[procedure] (termbox-blit [x integer] [y integer] [char-buffer u32vector] [fg-buffer u32vector] [bg-vector u32vector])

Copy data from vectors into a part of the internal buffer at a specific location. The char-buffer is the character codes for the characters.

[procedure] (termbox-select-input-mode [mode integer])

Sets the 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 ESC sequence => ESC means tb/key/esc.

2. Alt input mode. When ESC sequence is in the buffer and it doesn't match any known sequence => ESC enables tb/mod/alt modifier for the next keyboard event.

You can also apply tb/input/mouse via bitwise OR operation to either of the modes (e.g. tb/input/esc | tb/input/mouse). If none of the main two modes were set, but the mouse mode was, tb/input/esc mode is used. If for some reason you've decided to use (tb/input/esc | tb/input/alt) combination, it will behave as if only tb/input/esc was selected.

If 'mode' is tb/input/current, it returns the current input mode. Default termbox input mode is tb/input/esc.

[procedure] (termbox-select-output-mode [mode integer])

Sets the termbox output mode. Termbox has three output options: 1. tb/output/normal => [1..8] This mode provides 8 different colors: black, red, green, yellow, blue, magenta, cyan, white

Shortcut: tb/color/black, tb/color/red, ... Attributes: tb/attrib/bold, tb/attrib/underline, tb/attrib/reverse'''

Example usage:

   (tb-change-cell x y #\@ (bitwise-ior tb/color/black tb/attrib/bold) tb/color/red)

2. tb/output/256 => [0..256] In this mode you can leverage the 256 terminal mode:

Example usage:

   (tb-change-cell x  y #\@ 184 240)
   (tb-change-cell x  y #\@ #xb8 #xf0)

3. tb/output/216 => [0..216] This mode supports the 3rd range of the 256 mode only. But you don't need to provide an offset.

4. tb/output/grayscale => [0..23] This mode supports the 4th range of the 256 mode only. But you dont need to provide an offset.

If 'mode' is tb/output/current, it returns the current output mode. Default termbox output mode is tb/output/normal

Constants

Modifiers

[constant] tb/mod/alt
[constant] tb/mod/motion

Colors

[constant] tb/color/default
[constant] tb/color/black
[constant] tb/color/red
[constant] tb/color/green
[constant] tb/color/yellow
[constant] tb/color/blue
[constant] tb/color/magenta
[constant] tb/color/cyan
[constant] tb/color/white

Attributes

[constant] tb/attrib/bold
[constant] tb/attrib/underline
[constant] tb/attrib/reverse

Examples

Convert string to character buffer:

   (list->u32vector (map char->integer (string-list "hello world")))

Author

Justin Meiners

Source Repository

termbox

License

MIT license