/notcurses-clojure-example

Demo showing how to use Notcurses library for building terminal UIs with Clojure

Primary LanguageCThe UnlicenseUnlicense

Notcurses Clojure example

Notcurses is a moderm library for building terminal UIs with advanced graphics support. This is a demo showing how to use it with Clojure.

Bindings are generated with SWIG and compiled using Zig (any C compiler could be used, but I find Zig easiest to use because it includes powerful yet simple build system instead of relying on additional complex tools). GraalVM native-image is used to compile it to a binary executable.

Notcurses demo

Tested on Linux, might require some tweaks to run on macOS. Please let me know or open a PR if you get the demo running on macOS.

Dependencies

  • Easiest way to get dependencies is to install Nix package manager.
    Running nix-shell will drop you in a shell with all dependencies pulled in.

  • Otherwise install Clojure, SWIG, Zig, GraalVM and Notcurses deps using a preferred way for your OS.

Pull in Notcurses source code

Since packaged versions of Notcurses are often outdated, we pull and build it from source:

git clone https://github.com/dankamongmen/notcurses.git deps/notcurses
cd deps/notcurses
git checkout v3.0.9 # latest release at the time of writing
mkdir build && cd build
cmake -DUSE_MULTIMEDIA=none -DUSE_QRCODEGEN=off -DUSE_PANDOC=off -DUSE_DOCTEST=off ..
# We just need `cmake` to generate some headers, no need to actually `make` since rest will be handled by Zig.

Build and run

Build everything with:

scripts/compile

Run the binary:

target/demo

With the bindings compiled demo can be also run with the Clojure CLI:

clojure -Mnative -m demo.main

Limitations

  • Notcurses API for setters often uses pointers to primitive types to set their value, which does not work in Java since it only supports passing primitive types by value. Therefore functions to set channels properties like ncchannels_set_* need to be reimplemented in Clojure or Java.
  • I didn't go through the whole API, some bindings might need additional tweaks to work.

Related

See also the demo implemented in Zig.

License

Dual-licensed under MIT or the Unlicense.

Includes Native Utils licensed under MIT.