TK: Toolkit
TK is a Plan 9-style UI toolkit that provides widget rendering, event handling, layout management, and a complete UI component library. TK implements a synthetic UI filesystem using the 9P2000 protocol — the entire interface is a tree of files.
TK implements a complete synthetic UI filesystem using the 9P2000 protocol. The entire interface is a tree of files — every widget is a directory, every property is a file, every event is a file read. This "Synthetic UI" approach enables universal deployment through a simple, elegant interface.
Three core principles define TK:
TK provides a comprehensive set of UI widgets:
TK operates in two distinct modes:
CPU Server Mode: Run TK on Linux/Android/BSD with a TCP listener. Drawterm clients connect remotely for network-transparent sessions.
Native Mode: Run TK on 9front with kernel pipes. Integrates directly with rio window management and native graphics.
A complete "Hello TK" app demonstrating the synthetic filesystem approach. The same code runs on both modes — CPU Server or Native:
-- controller.lua — Direct 9P filesystem interaction
local tk = require("tk")
# Mount the synthetic UI filesystem
tk.mount("/mnt/tk")
local count = 0
# Create a simple window with label and button
tk.write("/mnt/tk/windows/main/title", "Greeting App")
# Add widgets as directory/file operations
tk.mkdir("/mnt/tk/widgets/greeting")
tk.write("/mnt/tk/widgets/greeting/type", "label")
tk.write("/mnt/tk/widgets/greeting/text", "Awaiting input...")
# Watch for events via file reads
while true do
local event = tk.read("/mnt/tk/events")
if event.widget == "submit_btn" then
count = count + 1
tk.write("/mnt/tk/widgets/greeting/text",
"Hello, " .. event.value .. "!")
end
end
TK includes a CLI tool called tjk for managing UI components and resources:
# Build and use tjk
$ cd tk
$ mk
$ ./bin/tjk --help
WM (Window Manager) → | Mu (Kernel) → | GitHub Repository | Back to Projects