termbox
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
- termbox-initprocedure
- termbox-shutdownprocedure
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.
- termbox-widthprocedure
- termbox-heightprocedure
Returns the size of the internal back buffer (which is the same as terminal's window size in characters).
- termbox-clearprocedure
Clears the internal back buffer using default color or the color/attributes set by termbox-set-clear function.
- (termbox-set-clear [fg u16] [bg u16] ) procedure
Specifies the values that will be applied when calling termbox-clear.
- termbox-presentprocedure
Synchronizes the internal back buffer with the terminal. In other words, presents changes to the terminal.
- (termbox-change-cell [x integer] [y integer] [c char] [fg u16] [bg u16])procedure
Changes cell's parameters in the internal back buffer at the specified position.
- (termbox-set-cursor [x integer] [y integer])procedure
Sets the position of the cursor. Upper-left character is (0, 0). Cursor is hidden by default.
- termbox-hide-cursorprocedure
Hides the cursor. Cursor can be shown again by calling termbox-set-cursor.
- termbox-poll-eventprocedure
Wait for an event forever and fill the 'event' structure with it, when the event is available. See below for event structure.
- (termbox-peek-event [timeout-millis integer]) -> list procedure
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).
- (termbox-copy-buffer [char-buffer u32vector] [fg-buffer u32vector] [bg-vector u32vector]) procedure
Copy data from vectors into the internal buffer. The char-buffer is the character codes for the characters.
- (termbox-blit [x integer] [y integer] [char-buffer u32vector] [fg-buffer u32vector] [bg-vector u32vector]) procedure
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.
- (termbox-select-input-mode [mode integer]) procedure
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.
- (termbox-select-output-mode [mode integer]) procedure
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:
- 0x00 - 0x07: the 8 colors as in tb/output/normal
- 0x08 - 0x0f: tb/color/_* | tb/attrib/bold
- 0x10 - 0xe7: 216 different colors
- 0xe8 - 0xff: 24 different shades of grey
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
- tb/mod/altconstant
- tb/mod/motionconstant
Colors
- tb/color/defaultconstant
- tb/color/blackconstant
- tb/color/redconstant
- tb/color/greenconstant
- tb/color/yellowconstant
- tb/color/blueconstant
- tb/color/magentaconstant
- tb/color/cyanconstant
- tb/color/whiteconstant
Attributes
- tb/attrib/boldconstant
- tb/attrib/underlineconstant
- tb/attrib/reverseconstant
Examples
Convert string to character buffer:
(list->u32vector (map char->integer (string-list "hello world")))