@isaacs/cliui

中文文档
9.0.0发布于 2026/02/06BlueOak-1.0.0TypeScriptESM + CJS零依赖近 30 天下载 4.6亿

easily create complex multi-column command-line-interfaces

原始使用文档
文档目录10 节
  1. Changes in v9
  2. Example
  3. Deno/ESM Support
  4. Layout DSL
  5. Methods
  6. cliui({width: integer})
  7. cliui({wrap: boolean})
  8. cliui.div(column, column, column)
  9. cliui.span(column, column, column)
  10. cliui.resetOutput()

@isaacs/cliui

Fork of cliui. Fully CommonJS/ESM hybridized, with all dependencies vendored and optimized for minimal bundle size without sacrificing functionality.

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

Changes in v9

The default export is no longer exported. So, intead of import cliui from '@isaacs/cliui', you'll do import { cliui } from '@isaacs/cliui'. This is done in order to minimize typescript oddness between the CommonJS and ESM versions.

A minified export is provided at @isaacs/cliui/min. If you are concerned about bundle size, that's the thing to use.

Example

import { cliui } from '@isaacs/cliui'
// or: const { cliui } = require('cliui')
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],
  },
  {
    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

Load the minified version from unpkg.

import { cliui } from 'https://unpkg.com/@isaacs/cliui/dist/esm/index.min.js'

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('@isaacs/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.

版本与发布记录

@isaacs/cliui 共发布 2 个版本,首次发布于 2023/05/02;过去 12 个月发布了 1 个版本。

版本发布日期距今
9.0.0latest2026/02/069 个月前
8.0.22023/05/023 年前

关于 @isaacs/cliui 的常见问题

@isaacs/cliui 是什么?

easily create complex multi-column command-line-interfaces

如何安装 @isaacs/cliui?

在项目目录运行 npm install @isaacs/cliui,或使用 pnpm add / yarn add / bun add。

@isaacs/cliui 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@isaacs/cliui 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@isaacs/cliui 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@isaacs/cliui 可以商用吗?

@isaacs/cliui 使用 BlueOak-1.0.0 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@isaacs/cliui 的下载量有多少?

根据 npm 官方下载统计,@isaacs/cliui 在 2026/10/07 – 2026/11/05 这 30 天内被下载 456,239,538 次,日均约 15,207,985 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@isaacs/cliui 还在维护吗?

最新版本 9.0.0 发布于 2026/02/06(9 个月前);至今共发布 2 个版本,其中过去 12 个月发布了 1 个;首次发布于 2023/05/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。