Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The nf command

nf is the one tool you need for Nifty. Run nf help to see a summary.

A project is a folder with a main.nf file in it. Every .nf file in the folder and its subfolders is part of the app, so you can split a bigger app across files; see Projects. Anywhere a command takes a [project], you can give a project folder, a single .nf file, or nothing at all to use the current folder. A single file runs on its own, without the other files around it.

nf create <name>

Makes a new folder called <name> with a starter app in main.nf.

nf create my-app

The name becomes the folder name and the window title. It must start with a letter and use only letters, digits, - and _. nf create won’t overwrite a folder that already exists.

nf run [project]

Checks the app, and if there are no errors, runs it with native windows.

nf run            # the project in this folder
nf run my-app     # a project folder
nf run demo.nf    # a single file

The app runs until you quit it (⌘Q on macOS) or close its last window (Alt+F4 on Windows). If it hits an error while running, it stops and shows where.

nf dev [project]

Like nf run, but it reloads the app every time you save. Keep it running while you work, and each change shows up in the open window within a moment.

nf dev my-app
my-app: started
watching my-app for changes; quit the app or press Ctrl-C to stop
my-app: reloaded

It watches every .nf file in the project folder and its subfolders, so saving any of them reloads the app, and so does adding or deleting one. For a single .nf file, it watches just that file.

  • Your state is kept. If you’ve typed three todos and then change a label’s text, the todos are still there after the reload. A state keeps its value as long as the new version still declares it with the same name and the same type. Rename it or change its type, and it starts again from its starting value.
  • Mistakes don’t close the app. If you save code with errors, nf dev prints them and keeps showing the last version that worked. Fix the code, save, and it reloads. If the very first version has errors, it waits for you to save a fix.
  • Errors while running don’t stop it either. If a button’s action hits an error, nf dev prints it and the app keeps running, so your next save can fix it. (nf run stops instead.)
  • Saving without changing anything doesn’t reload.

Stop it by quitting the app or pressing Ctrl+C in the terminal.

nf check [project]

Looks for mistakes without running anything, and lists every one it finds.

nf check
my-app: no problems found

Handy in scripts and CI, since nothing opens on screen.

nf lsp

Runs the language server, which gives editors errors-as-you-type, autocomplete, go to definition and more. Your editor starts this for you; you don’t run it by hand. See Set up your editor.

nf build [project] [--macos | --windows | --linux]

Checks the app, compiles it to machine code, and packages it as a native app you can give to other people.

nf build todos
built todos/build/todos.app
  • The app goes in a build folder next to main.nf, named after the project folder (or after the file, for a single .nf file). Building again replaces it.
  • It builds for the system you’re on, which is also the default with no flag: on macOS, a .app bundle; on Windows, a todos folder holding todos.exe. There’s no Linux backend yet, so --linux doesn’t work.
  • The app is one compiled program, linked with Nifty’s runtime library; the project’s .nf files aren’t inside it. Linking needs the system’s linker: Xcode’s command line tools on macOS, and Microsoft’s C++ Build Tools on Windows.
  • If the app has errors, they’re shown and nothing is built.
  • An error while the app runs stops it, and is written to the terminal it was started from as file:line:column: message.

See Share your app for a walkthrough.

nf version

Prints the version of nf, such as nf 0.1.0-alpha.3. nf --version works too.

Exit codes

For scripts:

CodeMeaning
0everything worked
1your program has errors (found by checking, or while running)
2the command itself was wrong, e.g. a typo in the command or a missing folder