Skip to main content

Module: CLI

The CLI provides a terminal user interface (TUI) for managing and monitoring the Almena daemon.

Overview

PropertyValue
Crate namealmena-cli
LanguageRust 2021
Version2026.3.5
LicenseApache-2.0 OR MIT
Repositoryalmena-network/cli

Source Structure

cli/
├── src/
│ ├── main.rs # Entry point, CLI args
│ ├── tui.rs # Ratatui TUI main loop
│ ├── daemon.rs # gRPC client to daemon
│ ├── daemon_process.rs # Process spawning/management
│ ├── theme.rs # Design system colors
│ └── path.rs # Platform-specific data directories
├── proto/
│ └── almena/daemon/v1/
│ └── service.proto # gRPC service definition (copied from daemon)
├── build.rs # tonic-build proto compilation
├── Cargo.toml # Dependencies
└── Taskfile.yml # Task orchestration

Key Dependencies

DependencyVersionPurpose
ratatui0.29Terminal UI framework
crossterm0.28Terminal input/output
tonic0.12gRPC client
prost0.13Protocol Buffer serialization
tokio1Async runtime
clap4CLI argument parsing
anyhow1Error handling

Implemented Features

TUI Interface

The TUI runs an async event loop with 100ms polling:

Keyboard Commands:

KeyAction
sStart the daemon
xStop the daemon
pPing the daemon
q / EscQuit the CLI

UI Layout:

  1. Header — Tagline and daemon status indicator
  2. Status Card — Colored dot showing daemon state:
    • Red = Stopped
    • Green = Running
    • Yellow = Checking
  3. Main Area — Available commands, daemon address, last command output
  4. Footer — Key hints

Daemon Status Monitoring

A background task checks daemon status every 2 seconds by attempting a gRPC ping. The status indicator updates automatically.

gRPC Client

The daemon.rs module provides:

pub async fn is_running(addr: &str) -> bool  // Ping check
pub async fn ping(addr: &str) -> String // Ping with response message

Daemon Process Management

Same dual-mode management as the desktop app:

ModeStartStop
DevelopmentSpawns binary from ALMENAD_DIRKills child process
macOSlaunchctl load ...plistlaunchctl unload ...plist
Linuxsystemctl --user start almenadsystemctl --user stop almenad
Windowssc start AlmenaDsc stop AlmenaD

Theme

The CLI uses a color theme consistent with the platform design system:

ColorHexUsage
Primary#FB923CActive elements, highlights
Secondary#8B5CF6Accents
Text#fafafaMain text
Muted#a3a3a3Labels, hints
SuccessGreenRunning status
ErrorRedStopped status
WarningYellowChecking status

Development

# Install dependencies
task install

# Run in dev mode
task dev

# Build for release
task build

# Check compilation
task check

CLI Arguments

FlagDefaultDescription
--daemon-addrhttp://127.0.0.1:50051Daemon gRPC address
--versionPrint version and exit

Proto Workflow

After daemon proto changes:

task proto:copy     # Copy proto from daemon
task proto:client # Rebuild gRPC client (includes proto:copy)