Writing

Building a Terminal Tiling Engine in Rust

How I built ratatui-hypertile, a Hyprland-style BSP layout engine for Ratatui, and why the layout and the shell around it live in separate crates.

ratatui-hypertile demo

Ratatui is great at drawing to a terminal, but it isn’t a window manager. You get Layout::split with a horizontal and a vertical direction, and that’s about it. For a dashboard that’s plenty. It stops being enough once you want panes that split, take focus, resize, and move around the way they do in Hyprland.

I wanted exactly that inside a single Ratatui app: panes that tile, focus that moves between them, borders you can drag, and windows you can swap. ratatui-hypertile is what came out of it.

Not another multiplexer

The first thing people usually ask is why I didn’t just use tmux or Zellij. Those tile whole processes, while hypertile tiles regions inside one application. You still draw every pane yourself, and the engine only keeps track of the tree, the focus, and the rectangles. The two don’t compete, either. A hypertile app runs fine inside tmux, and each keeps doing its own job.

The engine is a BSP tree

The layout itself is a binary space partition. Every leaf is a pane, and every internal node is a split with a direction and a ratio. When you split the focused pane, its leaf turns into a split with two children, and when you close a pane, its sibling moves up to take the parent’s place. Most tiling window managers work the same way, and the model maps cleanly onto Ratatui’s Rect.

Layout is computed lazily. You call compute_layout(area) whenever the tree or the terminal size changes, and the rectangles stay cached until something changes again. Focus, hit-testing, and moves all read from that cache:

use ratatui::layout::{Direction, Rect};
use ratatui_hypertile::Hypertile;

let mut layout = Hypertile::new();
layout.split_focused(Direction::Horizontal)?;
layout.compute_layout(Rect::new(0, 0, 80, 24));

for pane in layout.panes_iter() {
    draw_pane(pane.rect, pane.is_focused);
}

The engine itself never draws anything. It hands you a PaneSnapshot for every pane, with its id, rect, and focus state, and you decide what gets rendered inside it.

Actions instead of keycodes

A library that owns your keybindings is one you’ll end up fighting sooner or later, so hypertile doesn’t know about keys at all. It exposes a small set of actions such as FocusNext, SplitFocused, ResizeFocused, and MoveFocused. You map keyboard or mouse input to those yourself and pass them to apply_action, which tells you whether the action was Consumed or Ignored. Your own event loop stays in charge the whole time.

The resize step, the gaps, and the split policy are set through the builder. You can split evenly or use the golden ratio, which is a small touch, but it makes nested splits feel a lot less rigid.

Two crates on purpose

If the engine and a complete TUI shell lived in one crate, everyone who only wanted the layout would also pull in vim keybindings, a command palette, workspace tabs, and animations. So I split it in two:

  • ratatui-hypertile is the layout engine and nothing else. It handles the tree, focus, resizing, moving, and hit-testing, and has no opinions about rendering or input.
  • ratatui-hypertile-extras builds plugins, keymaps, the palette, tabs, and animations on top of it. Implement HypertilePlugin and you have a working shell.

If you want full control, use the core crate. If you just want to see how it feels, run the extras example and build from there.

What I learned

The BSP tree was the easy part. What actually mattered was deciding where the boundary goes: rectangles are computed in one place, and the app owns drawing and keybindings. Once that line was clear, the API started to feel like a normal Ratatui layout tool instead of a framework you have to work around.

The crate now has a few hundred stars on GitHub and a release on crates.io, so I clearly wasn’t the only one who wanted this. If your terminal app has outgrown static splits, that’s exactly what hypertile is for.

GitHub · crates.io · docs.rs