Library/SDK

A reference implementation of the ctx protocol is provided as a single header library. Interactive Applications written using the C library can run either inside the ctx terminal, or stand-alone using SDL2, fbdev/KMS, directly on a micro controller or over tcp to a ctx terminal/renderer running on a micro controller.

To experiment with ctx, the demo clients included in a release tarball is probably the best starting point.

More ports/examples are available in the git repo:

~/src/ $ git clone https://ctx.graphics/.git/
Fetching objects: 10294, done.
~/src$ cd ctx.graphics/
~/src/ctx.graphics$ ./configure.sh
configuration of optional depenencies complete:
    SDL2 yes
    babl yes
    alsa yes
 libcurl yes

Ready to build
~/src/ctx.graphics$ make 

When done you should be able to run the ctx terminal with

~/src/ctx.graphics$ ./ctx

The ctx binary is a busybox like binary with many features - and is used as part of the ctx regression tracking by generating unicode braille and grayscale raster tests, it can act as a standalone image viewer and text editor both inside and outside the ctx terminal if you pass it the path to a file.

The clients folder contains demo programs and scripts for the terminal.

HTML5 canvas 2D context
Binding friendly C API and protocol building on this standard, along with extensions from SVG. Compositing and blending is according to compositing and blending level 2; ctx permits all blending modes to be combined with all compositing modes.
backends: ctx, linux/openbsd KMS, linux/netbsd framebuffer, SDL2, braille
ctx comes with 5 interactive backends, the ctx backend renders the ctx protocol to stdout, and reads input, this provides the client interface for interactive vector clients running in the ctx terminal.
DRM and fbdev tries using /dev/input/ for keyboard/touchscreen with fallback to using stdin for keyboard and tries mouse events from /dev/input/mice. The SDL2 backend permits using ctx clients under wayland/X11 and probably other platforms, a dedicated wayland backend not using opengl would be a nice addition.
RGB and CMYK, 8pc and 32bit floating point
Supporting RGB332, RGB565 and grayscale + 1bit mode render targets. ICC based color management of RGB user/device spaces through babl as an optional dependency. CMYK colors can be generated on the fly from RGB or set and retained in CMYK mode - when set in CMYK mode the colors correspond directly to the device colors in CMYK mode.

deferred rendering
These drawlist representations are used for scanline/chunk-based rendering on microcontrollers where framebuffer is to large to fit in RAM and tiles and threaded rendering on multi-core systems with SDL2 and /dev/fb0 backends and network transparent rendering inside ctx terminal. Another way to drive larger than RAM is to re-render the frame for each segment instead of buffering it, buffering is however useful when doing networked rendering, ctx can be configured and adapted to deal with a wide range of scenarios. .
text rendering
Four font loading backends, harfbuzz, stb_truetype, native-ctx and ctx-fs. The ctx.h header ships with a built-in native-ctx font. The text-shaping is done per-word with harfbuzz when harfbuzz based fonts are used. Otherwise only basic fi fl ff ligatures are applied. Along with horizontal advances and kerning, RTL or vertical glyph advances.
sixels
DEC terminal family standard for raster graphics transfer
kitty graphics
kitty style raster graphics transfer
iterm2 inline images
iterm2 style raster grarphics transfer
atty
audio recording and playback (only raw pcm for now, opus codec NYI)
SDL2
Optional backend and support code that that gets build when SDL.h is included before ctx.h

The single header and static binaries for download are autogenerated together with this website each time the git repository is synched.

ctx-0.1.4.tar.bz2~900kbRelease of ctx library/terminal and some code samples.
ctx.h1.5mbThe singleheader library ctx, batteries included.
git repo
$ git clone https://ctx.graphics/.git
                                      
The repository contains the sources for examples and tests, and the implementation of 2D vector rasterization and protocl parser and serializer.

Environment variables

CTX_BACKEND
Override the backend used for interactive ctx applications, possible values:
auto (default)
try - in order: ctx, SDL2, kms, fb, term
ctx sdl sdl-cb sdl-fb sdl-fb-full kms fb term tcp:ip:port
ctx
use the ctx protocol, takes over the current tab in ctx-terminal as display window.
kms
linux kms
fb
linux framebuffer opening /dev/fb or /dev/fb0
term
output by converting to terminal graphics, with text at default font size mapped to actual text.
sdl-cb
sdl backend that uploads portions of texture at a time, similar to how menu SPI displays are driven.
sdl-fb
sdl backend with a framebuffer backing the texture
sdl-fb-full
with framebuffer, doing full redraws per frame - useful for debug, checking if artifacts are due to tile hash cache
tcp:ip.ip.ip.ip:port
open a TCP connection to a display at a given ip addres and port.
CTX_DAMAGE_CONTROL
Visualize which cached pixels are pushed to display

Binary protocol encoding

There is a corresponding binary encoding, it is somewhat stable but it is is better to rely on the text format for compatible exchange. In the binary form the commands and their arguments are broken down into 9 byte long chunks, where the first byte is the short-form from the table above and parameters are encoded.

future work

pressing issues

When this list is nearing 0 it is time for a tarball/versioned release of ctx. The single header ctx.h linked from this page is a rolling release.

desirable improvements