docs/GETTING_STARTED

Getting Started with Nebble

Nebble is a Nim wrapper library for Pebble smartwatch development. This guide will walk you through installation, creating your first app, and understanding the API structure.

Prerequisites

1. Nim Compiler (>= 2.2.0)

We strongly recommend installing Nim using choosenim to ensure you have the latest version and consistent environment for documentation generation.

After installation, verify with:

nim --version

2. Pebble SDK

To develop for Pebble, you need the Pebble SDK. Follow the instructions at the RePebble SDK Installation Guide for your platform (Windows, macOS, or Linux).

Verify that the pebble command is in your PATH:

pebble --version

Installation

nimble install nebble

Option 2: From Source

git clone https://github.com/Brokezawa/nebble.git
cd nebble
nimble install

Verify CLI Installation

The Nebble CLI is automatically installed when you run nimble install nebble. Verify the installation:

nebble version

If the command is not found, ensure your Nimble bin directory is in your PATH:

# Add to your shell profile (~/.bashrc, ~/.zshrc, etc.)
export PATH="$HOME/.nimble/bin:$PATH"

Your First App: Hello World

Step 1: Create a New Project

# Create a new project called "my_first_app"
nebble new my_first_app
cd my_first_app

This generates the project structure:

my_first_app/
├── package.json        # Pebble SDK project metadata
├── nim.cfg             # Cross-compilation flags
├── wscript             # Waf build configuration
└── src/
    ├── my_first_app.nim  # Your Nim watchapp source
    └── pkjs.nim          # Your Nim phone-side logic

Step 2: Write Your App Code

Open src/my_first_app.nim. Nebble provides a Declarative DSL to minimize boilerplate:

import nebble

# Handlers
proc selectClickHandler(recognizer: ClickRecognizerRef; context: pointer) {.cdecl.} =
  vibes.shortPulse()

# Declarative UI and interaction
nebbleApp:
  textLayer:
    id = myLabel
    fullWidth = true
    y = center
    h = 40
    text = "Hello Nim!"
    alignment = GTextAlignmentCenter
  
  clicks:
    BUTTON_ID_SELECT = selectClickHandler

Step 3: Build the App

nebble build

This command triggers the entire pipeline:

  1. Nim compilation to C (for the watch).
  2. Nim compilation to JS (for the phone component).
  3. Generating the unified package.json metadata on the fly.
  4. Invoking the Pebble build system to generate a single .pbw bundle for all platforms.

Step 4: Run in Emulator

Nebble provides aliases for common Pebble commands for consistency:

# Start emulator and install the unified bundle
nebble install --emulator basalt

# Or install to all platforms at once
nebble install --emulator all

Note: `nebble install` is a wrapper around `pebble install` that defaults to using the unified `.pbw` from the `build/` directory.

Cross-Platform Usage

Nebble works on Windows, macOS, and Linux. The CLI tool abstracts platform differences:

API Structure

Nebble has a two-layer architecture:

  1. Low-Level FFI (`nebble/ffi`): Direct 1:1 mapping of the C SDK.
  2. High-Level API (`nebble`): Idiomatic Nim wrappers with ARC memory management (Handles).

Always prefer the High-Level API for application logic to benefit from automatic memory management and type safety.

Full-Stack Development

Nebble is a Full-Stack framework. When you create a project, you get a src/pkjs.nim file. This is where you write your phone-side logic (Net requests, GPS, etc.) in Nim. It shares the same types and keys as your watch code. See the Full-Stack Guide for details.