Resin CLI Visuals

4.0.4 · active · verified Wed Apr 22

resin-cli-visuals is a JavaScript/TypeScript library providing a collection of command-line interface (CLI) widgets designed primarily for the Balena ecosystem's CLI tools. It offers components such as spinners, progress bars, interactive tables (horizontal and vertical), and a drive scanner to dynamically detect storage device changes. The current stable version is 4.0.4, released in March 2026, indicating an active development cadence with several minor and major releases in the last year. Key differentiators include its focus on CLI UX within the Balena context, offering ready-to-use visual components for common CLI interactions, and its recent migration to TypeScript and ESM, ensuring modern JavaScript practices. The library is built to enhance user interaction in console applications, making operations like long-running tasks or data display more visually intuitive.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates creating a spinner, displaying data in a horizontal table, and using the DriveScanner to detect drive changes.

import { visuals, DriveScanner } from 'resin-cli-visuals';

async function runCliDemo() {
  // Simulate a long-running operation with a spinner
  const spinner = new visuals.Spinner('Processing task...');
  spinner.start();
  await new Promise(resolve => setTimeout(resolve, 3000));
  spinner.stop();
  console.log('Task completed.');

  // Display data in a horizontal table
  const tableData = [
    { label: 'Name', value: 'John Doe' },
    { label: 'Email', value: 'john.doe@example.com' },
    { label: 'Role', value: 'Developer' }
  ];
  const tableOrdering = ['label', 'value'];
  console.log('\nUser Details:');
  console.log(visuals.table.horizontal(tableData, tableOrdering));

  // Example of a DriveScanner (requires a driveFinder function)
  // In a real scenario, driveFinder would be an async function
  // that returns an array of drive objects.
  const mockDriveFinder = async () => [
    { device: '/dev/sda', size: '10GB', description: 'USB Drive' },
    { device: '/dev/sdb', size: '500GB', description: 'Internal HDD' }
  ];
  const scanner = new DriveScanner(mockDriveFinder, { interval: 2000 });
  scanner.on('change', (drives) => {
    console.log('\nDrive change detected:', drives);
  });
  console.log('\nDrive scanner started. Waiting for changes (runs for 5s)...');
  await new Promise(resolve => setTimeout(resolve, 5000));
  scanner.stop();
  console.log('Drive scanner stopped.');
}

runCliDemo().catch(console.error);

view raw JSON →