I continue to implement my most daring ideas, for which there were previously no resources and which can now be realized thanks to the advent of LLM. I believe that now the value of the idea itself has become higher and it is it that decides everything.

Today I want to introduce a lightweight UI framework. It is written in Rust, runs on Windows (x64, ARM), macOS, Linux, Android, iOS/iPadOS, and even in the browser via WASM (online demo on GitHub Pages). Provided with examples of use in Rust, C, C++ and even ASM.

Distinctive feature: the framework has two formats - it either displays a graphical UI for people, or renders the UI in JSON so that AI agents can interact with it without taking screenshots. The same feature made it possible to add the ability to transfer the UI via SSH (more details below).

Пример приложений
Пример приложений

The key idea is JSON in everything

Although shifting JSONs is the talk of the town, in this case I considered it justified. The simplicity of the protocol, starting from the lower level, allows you not to spend a lot of time learning it, and in this case this is more important than rendering speed (the framework is intended for utilities, not for complex graphics).

The lower level of the framework can only render a JSON frame of 9 primitives. Here they are:

Primitive

Geometry

Properties

Description

rect

[x, y, w, h]

fill, stroke, width, radius

rectangle, including with rounded corners

line

[x1, y1, x2, y2]

color, width, cap (butt / round)

segment

circle

[cx, cy, r]

fill, stroke, width

circle

tri

[x1, y1, x2, y2, x3, y3]

fill, stroke, width

triangle (arrows, checkmarks)

poly

[[x, y], [x, y], …]

fill, stroke, width

closed polygon (graph sectors, own figures)

text

"одна строка"

at: [x, y], size, color, font, bold, italic

textline; transfer does a layer of screens

image

[x, y, w, h]

src, fit (cover / contain / fill), radius

picture

clip

[x, y, w, h]

items: […]

group cropped to rectangle (scrolling)

hit

[x, y, w, h]

id, cursor

invisible area for mouse and touch (not drawn)

At a higher level, familiar controls are added to JSON, such as Row, Text, IconButton and others. JSON with complex elements when going down to the lower level will be transformed so that only these 9 primitives remain.

All this made it possible to quickly adapt the framework to all 6 platforms of humanity:

platform

backend

macOS

AppKit, CoreGraphics, CoreText, ImageIO via Objective-C runtime

iOS

UIKit, CADisplayLink, same CoreGraphics/CoreText code as on macOS

Android

JNI manually, android.graphics.Canvas, Java layer ~300 lines; APK is built without Gradle

Windows

Win32, Direct2D, DirectWrite and WIC, COM manually; DPI per monitor, dark header

Linux

own Wayland and X11 protocol code (xcb), Cairo + Pango, xkbcommon - all through dlopen, so the binary depends only on libc

Browser

wasm32-unknown-unknown without wasm-bindgen, canvas 2D; C/C++ via Emscripten

To add a platform, you need to implement 9 methods (one for each of the primitives) using the platform, and also add event processing.

Custom controls

At the highest level, users can add their own controls to JSON like this:

#include <uison_widgets.hpp>

using namespace uison::widgets;

template <class F>
uison::Node Pill(std::string text, F on_click) {
    return Box({
        .padding = {8, 22},
        .fill = uison::json(R"({ state: {
            normal: "$theme.primary", hover: "$theme.primaryHover", pressed: "$theme.primaryPressed" } })"),
        .radius = 999,  // more than half the height: the ends become semicircles
        .align = "center",
        .interactive = true,
        .on_click = on_click,
        .child = Text(text, {.bold = true, .color = "$theme.onPrimary"}),
    });
}

int main() {
    auto screen = Column({.padding = 24, .gap = 16, .cross = "start", .children = {
        Text("Pressed {@n} times", {.size = 20}),
        Pill("Press me", [](uison::Cx& cx) {
            cx.data().set("n", cx.data().get<int>("n") + 1);
        }),
    }});
    uison::Ui ui(screen, {.size = {360, 140}, .data = uison::obj{{"n", 0}}});
    return ui.run("Pill");
}

Or directly in JSON:

{
  Pill: {
    params: { text: "" },
    interactive: true,  // the node gets hover / pressed states and a click
    body: {
      Box: {
        padding: [8, 22],
        radius: 999,  // more than half the height: the ends become semicircles
        align: "center",
        fill: { state: {
          normal: "$theme.primary",
          hover: "$theme.primaryHover",
          pressed: "$theme.primaryPressed",
        } },
        child: { Text: { text: "$text", bold: true, color: "$theme.onPrimary" } },
      },
    },
  },
}

All these new elements, having reached the bottom layer, will be converted to JSON from the same 9 primitives that are shown in the table above.

We render only what has changed

The new frame is compared with the old one element by element (LCS alignment, groups of clips with the same rectangle are compared internally). Changed, added and removed elements produce areas of “damage”, and the backend redraws only these.

For example, thanks to list virtualization, a mail frame of 2000 letters contains a couple of dozen lines.

How viable is the idea?

Based on the same idea, it was possible to implement even a simple browser. HTML and CSS are converted to JSON, after which the result is simply fed to our framework.

Uison itself does not know anything about HTML and CSS. It receives the familiar JSON and displays it just like the interface of a regular application.

Thus, the same mechanism allows you to draw both regular applications with buttons and tables, and web pages.

Wiki в JSON
Wiki в JSON

stdin and stdout instead of window: UI over SSH

Since we have JSON at the very bottom, we don’t have to render it at all, but send it as is – to the console in its bare form. This allows you to easily run the program on the server and work with it over SSH as if it were running on your computer.

The program on the server does not know about SSH. It writes frames to stdout and reads events from stdin. The server only needs sshd, no X11, no VNC, no browser.

The player can download the program to the server itself and run it with --console.

Плеер uison
Плеер uison

The player is designed as a separate project. You can even build it for Android and control the program via your phone. In a separate tab you can view JSON events and render frames that are transferred between the client and server:

JSON рендер и события плеера
JSON рендер и события плеера

Development of the idea: mode for AI agents

The same application can run in multiple modes without changing the source code. It can open a regular graphics window for a human, pass JSON frames to an external renderer, or provide a semantic description of the interface to an AI agent.

Launch

Who's on the other end

What goes into stdout

todo

Man

Nothing: window opens

todo --console

Player that draws

JSON frames: rectangles, text, coordinates

todo --agent

Script or AI agent

JSON with meaning: roles, names, states

todo --mcp

Claude Code and other MCP clients

The same meaning, but in the MCP protocol

With the --mcp flag, the program becomes an MCP server, that is, a set of tools for Claude Code, Cursor and other AI clients. It can be connected with one command: claude mcp add todo – ./todo --mcp, no need to write any code. The agent calls snapshot and receives the screen as text, and then acts with the click, type, choose tools. The answer is only what has changed. For example, an agent enters “Milk” in the field and presses Enter:

→ {"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"type","arguments":{"key":"draft/1/0","text":"Milk","submit":true}}}
← {"jsonrpc":"2.0","id":4,"result":{"content":[{"type":"text","text":"ok\nchanges (+ added, - removed, ~ changed):\n+ checkbox \"Milk\" #4/0 unchecked\n+ button \"trash\" #del-4\n+ text \"3\"\n+ text \"1 of 4 done\"\n+ text \"Remaining: 3\"\n- text \"2\"\n- text \"1 of 3 done\"\n- text \"Remaining: 2\"\n~ #draft/1/0 focused\n"}],"isError":false}}

The “Milk” item and its delete button appeared in the list, and the counter changed from “1 of 3” to “1 of 4”. The agent will not be able to press an inactive button, just as a person could not: the program will respond that the button is inactive.

Size and speed

I’ll show you using an example of a real open source program – Disk Usage on macOS. It was created in two versions: egui and uison, both in Rust. Here is the test result:

Indicator

egui (original)

uison

Program size, macOS arm64

5.1 MB (5,126,464 B)

0.9 MB (923,216 B), −82%

Size with opt-level = "s"

4.5 MB (4,450,560 B)

0.9 MB, about 5 times less than

Dependencies in Cargo.lock

362

0 external (uison racks only)

Empty window memory, no scanning

122 MB

55 MB

Memory after scan

152 MB

97 MB, −36%

Memory peak during scan

167–176 MB

183–184 MB

Strings Rust

3 198

3,547 + 479 lines of JSON screen

Quick start

Everything is in the lessons in Russian. Lessons for Rust, C, C++, as well as a short introduction to ASM.

Here I will show you how to start using Rust.

Step 1. Create a project and add uison

cargo new hello && cd hello
cargo add uison

Step 2: Replace src/main.rs

use uison::prelude::*;

fn main() {
    let screen = center(column().gap(12).cross("center").children([
        text("Pressed {@n} times").size(20),
        button("+1").key("inc").on_click(|cx| cx.data.edit("n", |n: &mut i32| *n += 1)),
    ]));
    let mut ui = Ui::from_node(screen).with_size(320.0, 200.0);
    ui.data.set("n", 0);
    run(ui, "Hello");
}

Step 3: launch

cargo run --release

A window with a counter will open. {@n} – data binding: the handler changes n, and the text is updated itself, without manual redrawing.

To keep the program small, add an assembly profile to the end of Cargo.toml:

[profile.release]
opt-level = "s"
lto = true
codegen-units = 1
panic = "abort"
strip = true

The framework does not aim to replace Qt or other full-fledged GUI frameworks. uison is primarily designed for utilities, developer tools, and general applications with buttons, lists, tables, and forms. For games and complex graphics, it is better to use other solutions.

For those interested, everything you need can be found at the following links: