Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@isaacs/cliui

yargs91.6mISC8.0.2

easily create complex multi-column command-line-interfaces

cli, command-line, layout, design, console, wrap, table

readme

@isaacs/cliui

Temporary fork of cliui.

ci NPM version Conventional Commits nycrc config on GitHub

easily create complex multi-column command-line-interfaces.

Example

const ui = require('cliui')()

ui.div('Usage: $0 [command] [options]')

ui.div({
  text: 'Options:',
  padding: [2, 0, 1, 0]
})

ui.div(
  {
    text: "-f, --file",
    width: 20,
    padding: [0, 4, 0, 4]
  },
  {
    text: "the file to load." +
      chalk.green("(if this description is long it wraps).")
    ,
    width: 20
  },
  {
    text: chalk.red("[required]"),
    align: 'right'
  }
)

console.log(ui.toString())

Deno/ESM Support

As of v7 cliui supports Deno and ESM:

import cliui from "https://deno.land/x/cliui/deno.ts";

const ui = cliui({})

ui.div('Usage: $0 [command] [options]')

ui.div({
  text: 'Options:',
  padding: [2, 0, 1, 0]
})

ui.div({
  text: "-f, --file",
  width: 20,
  padding: [0, 4, 0, 4]
})

console.log(ui.toString())

Layout DSL

cliui exposes a simple layout DSL:

If you create a single ui.div, passing a string rather than an object:

  • \n: characters will be interpreted as new rows.
  • \t: characters will be interpreted as new columns.
  • \s: characters will be interpreted as padding.

as an example...

var ui = require('./')({
  width: 60
})

ui.div(
  'Usage: node ./bin/foo.js\n' +
  '  <regex>\t  provide a regex\n' +
  '  <glob>\t  provide a glob\t [required]'
)

console.log(ui.toString())

will output:

Usage: node ./bin/foo.js
  <regex>  provide a regex
  <glob>   provide a glob          [required]

Methods

cliui = require('cliui')

cliui({width: integer})

Specify the maximum width of the UI being generated. If no width is provided, cliui will try to get the current window's width and use it, and if that doesn't work, width will be set to 80.

cliui({wrap: boolean})

Enable or disable the wrapping of text in a column.

cliui.div(column, column, column)

Create a row with any number of columns, a column can either be a string, or an object with the following options:

  • text: some text to place in the column.
  • width: the width of a column.
  • align: alignment, right or center.
  • padding: [top, right, bottom, left].
  • border: should a border be placed around the div?

cliui.span(column, column, column)

Similar to div, except the next row will be appended without a new line being created.

cliui.resetOutput()

Resets the UI elements of the current cliui instance, maintaining the values set for width and wrap.

changelog

Change Log

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

8.0.1 (2022-10-01)

Bug Fixes

  • deps: move rollup-plugin-ts to dev deps (#124) (7c8bd6b)

8.0.0 (2022-09-30)

⚠ BREAKING CHANGES

  • deps: drop Node 10 to release CVE-2021-3807 patch (#122)

Bug Fixes

  • deps: drop Node 10 to release CVE-2021-3807 patch (#122) (f156571)

7.0.4 (2020-11-08)

Bug Fixes

  • deno: import UIOptions from definitions (#97) (f04f343)

7.0.3 (2020-10-16)

Bug Fixes

  • exports: node 13.0 and 13.1 require the dotted object form with a string fallback (#93) (eca16fc)

7.0.2 (2020-10-14)

Bug Fixes

  • exports: node 13.0-13.6 require a string fallback (#91) (b529d7e)

7.0.1 (2020-08-16)

Bug Fixes

  • build: main should be build/index.cjs (dc29a3c)

7.0.0 (2020-08-16)

⚠ BREAKING CHANGES

  • tsc/ESM/Deno support (#82)
  • modernize deps and build (#80)

Build System

Code Refactoring

6.0.0 (2019-11-10)

⚠ BREAKING CHANGES

  • update deps, drop Node 6

Code Refactoring

  • update deps, drop Node 6 (62056df)

5.0.0 (2019-04-10)

Bug Fixes

  • Update wrap-ansi to fix compatibility with latest versions of chalk. (#60) (7bf79ae)

BREAKING CHANGES

  • Drop support for node < 6.

4.1.0 (2018-04-23)

Features

4.0.0 (2017-12-18)

Bug Fixes

  • downgrades strip-ansi to version 3.0.1 (#54) (5764c46)
  • set env variable FORCE_COLOR. (#56) (7350e36)

Chores

Features

BREAKING CHANGES

  • officially drop support for Node < 4

3.2.0 (2016-04-11)

Bug Fixes

Features

  • adds standard-version for release management (ff84e32)