Development¶
Contents
- Environment
- Checks
- Continuous integration
- Licenses
- Releasing
- AUR
- Tests
- Running jotty headless
- Benchmarks
- Debugging
- Code layout and conventions
Environment¶
The flake's dev shell provides the Rust toolchain (cargo, rustc, clippy, rustfmt, rust-analyzer), pkg-config, and the native libraries: wayland, libxkbcommon, libGL (libglvnd) and fontconfig.
nix develop # or: direnv allow (the repo has an .envrc)
cargo build
cargo run -- -e htop
Without Nix, install the development packages for those four libraries and a Rust toolchain of version 1.88 or newer.
The dev shell also compiles extra/jotty.terminfo into
target/share/terminfo, next to target/{debug,release}/jotty, so
cargo run uses TERM=jotty. Without the dev shell, jotty falls back to
xterm-256color unless the entry is installed elsewhere.
Checks¶
Run these before committing. nix flake check runs all three in the
sandbox.
cargo test # unit tests
cargo clippy --all-targets -- -D warnings # lints
cargo fmt --check # formatting
RUSTC_BOOTSTRAP=1 cargo fmt -- --check --config imports_granularity=Module,group_imports=StdExternalCrate,hex_literal_case=Lower,format_macro_matchers=true
# nightly rustfmt options
nix flake check # builds the package (with tests), clippy, rustfmt
nix fmt # formats flake.nix
Continuous integration¶
.github/workflows/ci.yml runs on pushes to main and on pull requests:
| Job | Runs |
|---|---|
| Format | cargo fmt --check, the same with the nightly rustfmt options, and nix fmt -- --check flake.nix |
| Clippy | cargo clippy --all-targets -- -D warnings |
| Build and test | cargo build --release and cargo test on Ubuntu, with fonts installed so the font and emoji tests run |
| Minimum Rust version | cargo build with Rust 1.88, the rust-version in Cargo.toml |
| Third-party licenses | scripts/third-party-licenses.sh --check: THIRD-PARTY-LICENSES matches Cargo.lock |
| Nix flake check | nix flake check: the package with its tests, clippy and rustfmt in the sandbox, and the terminfo size check |
| Move the cachix branch | on main only, after every other job passes: points cachix at the commit |
Warnings fail every job. When raising rust-version, update the
toolchain in the minimum-version job too.
Builds of main upload the Nix build to the justanoobcoder Cachix cache
(token in the repository secret CACHIX_AUTH_TOKEN; pull requests only
pull). Once every job has passed, the publish job moves the cachix
branch to that commit. Users follow cachix, so it only ever points at a
cached build: never push to it by hand. A newer push to main cancels a
running build, so only the latest of a burst gets cached. The free cache
holds 5 GB; when full, Cachix drops the least recently used paths, which
only costs a rebuild to someone pinned to an old commit.
Pushes that touch only Markdown, .gitignore, packaging/, scripts/
or the release workflow skip CI (paths-ignore), so cachix lags behind
them until the next build, which is harmless: the package's src holds
only Cargo.toml, Cargo.lock, LICENSE, THIRD-PARTY-LICENSES,
src/, extra/ and docs/config.example.toml. A file the build reads
elsewhere must join that fileset. The home-manager module is outside it too, but its changes do run
CI, or users on cachix would never get them.
Licenses¶
jotty is MIT (LICENSE). THIRD-PARTY-LICENSES holds the licenses of
the crates compiled into it, generated by cargo-about from Cargo.lock
and installed by every package (Nix, tarball, deb, rpm, Arch). After
changing dependencies, regenerate it in the dev shell and commit it:
nix develop -c scripts/third-party-licenses.sh
scripts/about.toml lists the accepted licenses, in order of preference
for crates that offer a choice. A dependency under any other license fails
the script: check that it is compatible with MIT before adding it there.
Releasing¶
- Set
versioninCargo.toml(and runcargo buildto updateCargo.lock). InCHANGELOG.md, rename## Unreleasedto the version (## 0.2.0) and start a new empty## Unreleasedabove it. Commit and push. - Tag the commit and push the tag:
git tag v0.2.0
git push origin v0.2.0
.github/workflows/release.yml then checks that the tag matches the
version and that CHANGELOG.md has entries under it, builds on Ubuntu
22.04 (for an old enough glibc) for x86_64 and aarch64, and publishes a
GitHub release, described by those entries, with:
| File | For |
|---|---|
jotty_VERSION-1_ARCH.deb |
Debian, Ubuntu and derivatives (cargo-deb; dependencies detected from the binary) |
jotty-VERSION-1.ARCH.rpm |
Fedora, openSUSE, RHEL-likes (cargo-generate-rpm) |
jotty-VERSION-1-x86_64.pkg.tar.zst |
Arch Linux, built with makepkg from packaging/arch/PKGBUILD in an Arch container |
jotty-VERSION-ARCH-linux.tar.gz |
Anything else: bin/jotty with share/terminfo, the desktop entry and docs |
SHA256SUMS |
Checksums of all of the above |
A tag with a - (v0.2.0-rc.1) makes a pre-release, and needs its own
## 0.2.0-rc.1 entry. The package contents are listed in Cargo.toml
([package.metadata.deb] and [package.metadata.generate-rpm]) and in
the PKGBUILD. The PKGBUILD also
works for the AUR: it downloads the tagged source from GitHub.
AUR¶
The AUR has two packages, whose PKGBUILDs live in packaging/aur/:
| Package | What it installs |
|---|---|
jotty-bin |
The release tarballs, repackaged (x86_64 and aarch64) |
jotty-git |
A build of the latest commit on main |
After a release (not a pre-release), the aur job of release.yml pushes
both to the AUR: jotty-bin with the new pkgver and the tarballs'
checksums, jotty-git with the pkgver its pkgver() gives for the
tagged commit. jotty-git is pushed only then, not on every commit: it
always builds the latest commit, and AUR helpers find new commits with
--devel. A change to the PKGBUILDs between releases is pushed by hand,
with pkgrel bumped.
The job needs the AUR_SSH_PRIVATE_KEY secret, the private half of an SSH
key added to the maintainer's AUR account. The first push of each package,
which creates it on the AUR, is done by hand:
git clone ssh://aur@aur.archlinux.org/jotty-bin.git
cp packaging/aur/jotty-bin/PKGBUILD jotty-bin/
cd jotty-bin
makepkg --printsrcinfo > .SRCINFO
git add PKGBUILD .SRCINFO && git commit -m 'Initial import' && git push
CHANGELOG.md lists only what users notice: features, bug fixes and
performance, one short line each. Refactors, dependency bumps, CI and docs
changes stay out of it. Add an entry under ## Unreleased with the change
that makes it.
Tests¶
The tests don't need a compositor, GPU or display:
| Area | What is tested |
|---|---|
terminal/tests.rs |
Escape sequences against expected grid contents: movement, erase, insert/delete, scroll regions, SGR, alternate screen, wide characters, grapheme clusters, charsets, reports (DECRQM, color queries), hyperlinks, resize and reflow, scrollback view, OSC 133, notifications (OSC 9, OSC 777), and a garbage-input fuzz test |
terminal/grid.rs |
Scrolling, history bounds, resize |
pty.rs |
Spawning /bin/sh, environment, window size, resize, input, line editing of UTF-8 characters, controlling terminal, exit status |
input.rs |
Key encoding in all modes, shortcuts, paste encoding |
ime.rs |
Surrounding text from rows (including wide and multibyte characters), byte limits, delete-to-keys, event ordering |
renderer/mod.rs |
Color resolution and program color overrides, cursor styles, decorations, selection and preedit drawing, clusters, splitting rows into words and drawing their shaped glyphs, through a fake glyph cache |
renderer/atlas.rs |
Packing without overlap |
renderer/software.rs |
Pixel output of the CPU renderer: fills, translucency, glyph coverage, color glyphs, clipping, partial repaints and damage bands |
font.rs |
Cell metrics, box drawing, mark overlays, and loading the system monospace font (skipped when no fonts are installed, as in the Nix sandbox); ligatures, Arabic joining and mark positioning with JetBrains Mono and Noto Sans Arabic (each skipped without the font) |
shape.rs |
Placing shaped glyphs in cells: unchanged glyphs, contextual alternates, ligatures over several cells, marks, missing glyphs |
emoji.rs |
Which text is drawn in color, scaling, and flag ligatures in the system emoji font (skipped without one) |
notify.rs |
D-Bus marshalling of Notify, parsing replies and signals in both byte orders, which clicks focus the window, bus addresses |
watch.rs |
Noticing a config file replaced by rename, ignoring other files, parsing inotify events |
links.rs, search.rs |
URL and hyperlink detection, trimming, wrapped lines, configured patterns; finding matches in both directions |
config.rs, cli.rs, selection.rs |
Parsing, validation, selection text, words, lines, following output |
The Wayland and GL glue (app.rs, renderer/gl.rs) is tested by running
jotty, as described next.
Running jotty headless¶
scripts/headless.sh starts a headless sway with software rendering, runs
jotty in it, optionally drives it, and saves a screenshot. Nothing appears on
your screen, and it works over SSH or in CI.
cargo build
nix shell nixpkgs#sway nixpkgs#grim nixpkgs#wtype -c \
scripts/headless.sh shot.png -- ./target/debug/jotty -e sh -c 'ls --color=always; sleep 5'
To type into it, write an actions script and pass it with -a:
cat > /tmp/actions.sh <<'EOF'
wtype -k Shift_L -s 200 'echo hello' -k Return -s 300
swaymsg output HEADLESS-1 scale 2
EOF
nix shell nixpkgs#sway nixpkgs#grim nixpkgs#wtype -c \
scripts/headless.sh -a /tmp/actions.sh shot.png -- ./target/debug/jotty
Put the whole input sequence in a single wtype call (use -s for pauses).
Each wtype process creates and removes a virtual keyboard, and the keys it
sends right after the seat regains a keyboard can be lost.
The input method can be exercised the same way. sway relays
text-input-v3 to an input-method-v2 client, so a small client that sends
set_preedit_string, commit_string and delete_surrounding_text (and
prints the surrounding_text events it receives) tests the whole IME path.
Note that sway only sends text_input.enter while an input method is
connected.
Benchmarks¶
scripts/bench/ compares jotty with foot, kitty, ghostty, alacritty and rio,
or one jotty build with another, on your desktop: cat.sh times cat of a
large file, vtebench.sh runs vtebench's scenarios, and startup.sh
measures start time and memory. Every terminal gets the same font, size and
scrollback, and they run in turn, round after round.
nix build
scripts/bench/cat.sh new=jotty-cpu@./result/bin/jotty old=jotty-cpu foot
nix shell nixpkgs#vtebench -c scripts/bench/vtebench.sh jotty-cpu jotty-gpu
See scripts/bench/README.md for the options and what skews the results.
Debugging¶
- jotty logs to stderr through
env_logger, at levelwarnby default.RUST_LOG=infoadds the fonts loaded, the GL version and scale changes;RUST_LOG=jotty=debugalso every escape sequence jotty doesn't handle. WAYLAND_DEBUG=1traces all Wayland messages. Combine it withgrep text_inputto debug the input method.- To test the CPU renderer, set
renderer = "cpu"in[window]. To test the GL renderer on Mesa's software rasterizer instead (on NixOS with an NVIDIA GPU), setLIBGL_ALWAYS_SOFTWARE=1and__EGL_VENDOR_LIBRARY_FILENAMES=/run/opengl-driver/share/glvnd/egl_vendor.d/50_mesa.json. - To see what jotty receives from a program, record its output with
script -q /tmp/login another terminal, or runcat -vinside jotty.
Website¶
The website at https://justanoobcoder.github.io/jotty/ is built with
MkDocs (Material theme) from site/. It has no copies of the docs:
site/hooks.py adds docs/user/, docs/design/, this page and
CHANGELOG.md as pages, and points links to other files at GitHub.
When an option changes, update the table on its page in docs/user/ as
well as docs/config.example.toml.
Preview it with live reload, at http://127.0.0.1:8000/jotty/:
nix develop -c mkdocs serve -f site/mkdocs.yml
nix build .#site builds it with --strict, so a broken link or anchor
fails the build. The Website workflow builds it for pull requests and
deploys it to GitHub Pages on pushes to main that touch it.
Screenshots and recordings go in site/content/assets/screenshots/; a
<!-- screenshot: name.png --> line in a page shows the file once it
exists there.
Code layout and conventions¶
See the architecture overview for the module map. Some conventions:
- Keep Wayland and GL types out of the logic modules (
terminal,ime,input,selection,renderer::build), so they stay unit-testable. - When adding an escape sequence, add a test in
terminal/tests.rsthat feeds the bytes and checks the resulting grid. unsafestays inpty.rs,font.rs(fontconfig,mmap),watch.rs(inotify, signals) andrenderer/gl.rs, with aSAFETYcomment where the reason isn't obvious.- Imports come in three groups: std, other crates, then the crate's own.
The nightly rustfmt options
imports_granularity = "Module",group_imports = "StdExternalCrate",hex_literal_case = "Lower"andformat_macro_matchers = truekeep them so; stable rustfmt runs them withRUSTC_BOOTSTRAP=1 cargo fmt -- --config imports_granularity=Module,group_imports=StdExternalCrate,hex_literal_case=Lower,format_macro_matchers=true(CI checks it with--check). - Commit one change at a time, and make sure tests, clippy and rustfmt pass first.