Browse the source code
All of Nifty is open source on GitHub: github.com/istorry/nifty.
Each part below links to two places:
- Source opens the code on GitHub.
- API docs opens the generated Rust documentation for that crate: every type and
function, with its doc comments, cross-linked, and a
sourcelink on each item.
Not sure where to start? Read How Nifty works first; it explains how these pieces fit together.
The repository at a glance
nifty/
├── crates/ the Rust code that makes up Nifty
│ ├── nifty-syntax/ text → syntax tree
│ ├── nifty-check/ syntax tree → checked program
│ ├── nifty-interp/ runs a checked program
│ ├── nifty-codegen/ compiles a program to machine code and links it
│ ├── nifty-rt/ the runtime library compiled apps link against
│ ├── nifty-runtime/ widgets, layout and the engine apps run on, on any OS
│ ├── nifty-download/ `download`, for interpreted and compiled apps
│ ├── nifty-platform/ picks the backend for this OS
│ ├── nifty-macos/ the macOS (AppKit) backend
│ ├── nifty-windows/ the Windows (Win32) backend
│ ├── nifty-lsp/ the language server for editors
│ └── nifty-cli/ the `nf` command
├── editors/ editor extensions and grammars
│ ├── vscode/
│ ├── zed/
│ └── tree-sitter-nifty/
├── fixtures/ .nf programs the tests read
└── docs/ this book
Crates
nifty-syntax: reading source code
Turns text into a syntax tree, with error recovery. Source · API docs
| File | What’s in it |
|---|---|
lexer.rs | splits text into tokens; decides which line breaks matter |
token.rs | the token kinds and the keyword list |
parser/ | the parser, split into items, statements and expressions |
ast.rs | the syntax tree types |
diagnostic.rs, span.rs | error messages and source positions, each in one file of the project |
project.rs | which .nf files make up a project |
nifty-check: understanding the program
Resolves names, checks types, and records what state each part of the UI reads. Source · API docs
| File | What’s in it |
|---|---|
elements.rs | the one table of built-in UI elements and their arguments |
functions.rs | the one table of built-in functions, such as download |
methods.rs | the one table of built-in list and string methods |
hir.rs | the checked program that the interpreter runs |
checker/ | the checker: declarations, statements, expressions, UI, arguments, constants |
tests/grammars.rs | checks the editor grammars, docs highlighter and reference lists against those tables |
nifty-interp: running the program
Runs a checked program on the runtime’s engine, evaluating every dynamic part of the UI by walking the checked code. Source · API docs
| File | What’s in it |
|---|---|
app.rs | starts and reloads a program on the engine |
lower.rs | turns checked windows and views into the engine’s templates |
logic.rs | the interpreter as the engine’s Logic: text, bindings, actions and regions |
live.rs | an app whose program can be swapped while it runs, for nf dev |
machine/carry.rs | which state values survive a reload |
machine/ | evaluates statements and expressions; reads and writes places |
value.rs | runtime values |
nifty-codegen: compiling to machine code
Compiles programs to object files with Cranelift, and links them against nifty-rt with
the system’s linker: cc from Xcode’s command line tools on macOS, and the MSVC linker
on Windows.
Source ·
API docs
| File | What’s in it |
|---|---|
compile/ | compiles a checked program and emits the descriptor the runtime reads |
compile/body.rs | statements, expressions and places, with the reference counting that keeps copies independent |
compile/ui.rs | windows, views, templates, and the functions behind their dynamic parts |
emit.rs | writes functions and data into an object file, or into memory for tests |
object.rs | an app’s object file, with the main that runs it |
link.rs | links an object and the runtime library into an executable |
tests/compiled.rs | runs programs compiled and interpreted side by side, and checks they match |
tests/link.rs | compiles, links and runs a program for real; build the workspace first |
nifty-rt: the runtime library compiled apps link against
A static library holding everything a compiled app needs at run time. Compiled code
calls its nf_* functions and hands nifty_rt_main a descriptor of its states, windows
and views, which it shows through the same engine the interpreter uses.
Source ·
API docs
| File | What’s in it |
|---|---|
program.rs | the descriptor compiled programs emit, whose layout is the contract with nifty-codegen |
value.rs | values in 64-bit slots; reference-counted strings, lists and structs |
abi/ | the nf_* calls, and who owns the values passed to them |
context.rs | state, call depth, and why code failed |
logic.rs, lower.rs, show.rs | compiled code as the engine’s Logic |
place.rs | places in state that later writes go to, as compiled code names them |
download.rs, dialog.rs | download and the file dialogs in compiled apps |
symbols.rs | the names compiled code links to |
nifty-download: downloads
Runs each download on its own thread and hands its reports back to the UI thread, for
both the interpreter and compiled apps.
Source ·
API docs
nifty-runtime: widgets, layout and the engine
The OS-independent widget tree and flexbox layout, the Backend trait each OS
implements, and the engine that keeps an app’s windows in step with its state.
Source ·
API docs
| File | What’s in it |
|---|---|
reactive/ | the engine: mounts templates, handles events, updates only what changed, and the Logic trait that gives templates their values |
state.rs, failure.rs | which state UI reads; why running code fails, the same however it runs |
ui.rs | the retained UI: create, arrange and update widgets |
backend.rs | the Backend trait a platform implements, and the Waker other threads use to reach the UI thread |
dialog.rs, paths.rs | file dialogs: what an app asks for, and the queue that shows them between events and hands back the answers; ~ in paths |
layout.rs | flexbox layout with Taffy |
style.rs, geometry.rs | text/button/stack styles; points, sizes, frames |
testing.rs | an in-memory fake backend for tests |
nifty-macos, nifty-windows and nifty-platform: real native widgets
nifty-macos implements Backend with AppKit, and nifty-windows implements it with
Win32 common controls. Each backend crate compiles to nothing on other systems, so the
workspace builds on both macOS and Windows; CI runs every test on each. nifty-platform picks the backend for the
OS you build on. Windows executables need the application manifest that nifty-cli’s
build.rs embeds, which turns on Common Controls 6 and per-monitor DPI awareness.
macOS source ·
macOS API docs ·
Windows source ·
platform source ·
platform API docs
nifty-lsp: editor support
The language server behind nf lsp.
Source ·
API docs
| File | What’s in it |
|---|---|
server.rs | the request loop |
workspace.rs | open files and the projects they belong to |
project.rs | a project’s files, analysed together |
document.rs | one file’s text, syntax tree and position conversion |
index/ | an index of every declaration and use, for navigation |
features/ | diagnostics, completion, semantic tokens, outline, navigation |
nifty-cli: the nf command
nf, the tool you use.
Source ·
API docs
| File | What’s in it |
|---|---|
lib.rs | the usage text; parses the command line and dispatches |
main.rs | the entry point |
create.rs, run.rs, dev.rs, check.rs, build.rs, lsp.rs | one file per command |
build/macos.rs | writes the .app bundle around the compiled executable |
build/windows.rs | writes the Windows app folder around the compiled executable |
frontend.rs | reads a project, checks it, and says where spans are; shared by every command |
report.rs | prints errors with the source line underneath |
templates/main.nf | the starter app nf create writes |
Editors
| Folder | What’s in it |
|---|---|
editors/vscode | VS Code extension: TextMate grammar + language client |
editors/zed | Zed extension: Tree-sitter queries + language server setup |
editors/tree-sitter-nifty | the Tree-sitter grammar |
This book
The docs you’re reading are in
docs/, written in Markdown and built
with mdBook. Every page has an edit button at
the top right.