diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2026-10-04 20:02:15 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2026-10-04 20:02:15 +0200 |
| commit | 2e31cbeb70d93bb0f5512064f181990db189d1f6 (patch) | |
| tree | 049f137715b692bcac0fd402fcbf04ef703523f0 /README.md | |
| download | hare-termbox2-2e31cbeb70d93bb0f5512064f181990db189d1f6.tar.gz hare-termbox2-2e31cbeb70d93bb0f5512064f181990db189d1f6.zip | |
Initial commit
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..7620429 --- /dev/null +++ b/README.md | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | # Hare bindings for termbox2 | ||
| 2 | |||
| 3 | This repository contains [hare](https://harelang.org) bindings for the | ||
| 4 | terminal I/O library [termbox2](https://github.com/termbox/termbox2). | ||
| 5 | |||
| 6 | There are some differences between the Hare bindings and the original | ||
| 7 | C code, for example the fact that the prefixes `tb_` and `TB_` have been | ||
| 8 | replaced by the namespace `termbox2::`. See the haredoc documentation | ||
| 9 | in `termbox2/README` for more information. | ||
| 10 | |||
| 11 | ## Using this library | ||
| 12 | |||
| 13 | There are two ways to build termbox2 for this library. Both involve | ||
| 14 | building termbox2 as a standalone library or object file, rather than | ||
| 15 | including it as a header-only library as one could do in a C program. | ||
| 16 | |||
| 17 | ### Using the system's termbox2 (default) | ||
| 18 | |||
| 19 | This method assumes that termbox2 is already installed as a library | ||
| 20 | system-wide, for example by using your OS's package manager or by | ||
| 21 | installing it from source using `make install_lib`. | ||
| 22 | |||
| 23 | Once termbox2 is installed, you can run `make install`. This will | ||
| 24 | copy the hare bindings to `/usr/local/src/hare/third-party/` so that | ||
| 25 | you can include them in your Hare project as any other module. Do | ||
| 26 | not forget to add the `-ltermbox2` option to build any program that | ||
| 27 | uses this library. | ||
| 28 | |||
| 29 | To uninstall the bindings, run `make uninstall`. | ||
| 30 | |||
| 31 | You can also run `make demos` (or simply `make`) to build the demo | ||
| 32 | programs contained in `demo/`, and then you can run them from the | ||
| 33 | `build/` folder. For example, to run the `hjkl` demo you can run | ||
| 34 | `make && ./build/demo/hjkl`. | ||
| 35 | |||
| 36 | ### Using a local termbox2 | ||
| 37 | |||
| 38 | This method is useful if you just want to experiment with termbox2 | ||
| 39 | programming in Hare, for example by running and modifying the demos | ||
| 40 | in `demo/`, without installing anything system-wide. | ||
| 41 | |||
| 42 | To do this, the original library is provided as a | ||
| 43 | [git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules) | ||
| 44 | in this repository. You can download it with: | ||
| 45 | |||
| 46 | ``` | ||
| 47 | git submodule init | ||
| 48 | ``` | ||
| 49 | |||
| 50 | (Alternative, you can place the source code for termbox2 in | ||
| 51 | `vendor/termbox2`). Then you can build termbox2 locally with | ||
| 52 | |||
| 53 | ``` | ||
| 54 | make local | ||
| 55 | ``` | ||
| 56 | |||
| 57 | This will directly build all the demo programs from `demo/`, placing | ||
| 58 | the resulting binaries in `build/demo`. | ||
| 59 | |||
| 60 | Technical note: this will include the compiled termbox object file | ||
| 61 | `termbox.o` directly in the compiled binaries. | ||
| 62 | |||
| 63 | To build the demo programs using this method, run `make local-demos`. | ||
| 64 | |||
| 65 | ## Notes on build options | ||
| 66 | |||
| 67 | The original termbox2 library offers several build options via `TB_OPT_*` | ||
| 68 | constants. Two of them, `TB_OPT_ATTR_W` and `TB_OPT_EGC`, are relevant for | ||
| 69 | the API. | ||
| 70 | |||
| 71 | * `TB_OPT_ATTR_W` (in the Hare bindings: `termbox2::OPT_ATTR_W`) can be | ||
| 72 | either `16`, `32` or `64`, and is used to enable more output attributer | ||
| 73 | (e.g. truecolor). The termbox2 sources claim that the default value is | ||
| 74 | `16`, but this is only true when including termbox2 as a header-only | ||
| 75 | library. When building it as an external library, the default is `64`. | ||
| 76 | Since these bindings are meant to be used with termbox2 compiled as an | ||
| 77 | external library, we use `64` as default. The hare build tags `attrw16` | ||
| 78 | and `attrw32` are offered if one wants to use a different value. | ||
| 79 | |||
| 80 | * `TB_OPT_EGC` (in the Hare bindings: `termbox2::OPT_EGC`) can be set or | ||
| 81 | not set (in the bindings: it is a boolean value, `true` for set, `false` | ||
| 82 | for not set). Similarly to `TB_OPT_ATTR_W`, it is by default set when | ||
| 83 | building termbox2 as an external library, unlike when including it as a | ||
| 84 | header-only library. An `noegc` tag is available to disable this option. | ||
| 85 | |||
| 86 | Note: the consistency of these two build options between the C library | ||
| 87 | and the Hare bindings is checked and enforced in `termbox2::init()`. | ||
