pax_global_header 0000666 0000000 0000000 00000000064 13752103035 0014511 g ustar 00root root 0000000 0000000 52 comment=57efcd2d1acdb0c8a6c9ee08f83719c0b60bf69b
cliui-7.0.4/ 0000775 0000000 0000000 00000000000 13752103035 0012626 5 ustar 00root root 0000000 0000000 cliui-7.0.4/.coveralls.yml 0000664 0000000 0000000 00000000056 13752103035 0015422 0 ustar 00root root 0000000 0000000 repo_token: NiRhyj91Z2vtgob6XdEAqs83rzNnbMZUu
cliui-7.0.4/.eslintrc 0000664 0000000 0000000 00000000710 13752103035 0014450 0 ustar 00root root 0000000 0000000 {
"overrides": [
{
"files": "*.ts",
"parser": "@typescript-eslint/parser",
"rules": {
"no-unused-vars": "off",
"no-useless-constructor": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-useless-constructor": "error"
}
}
],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint/eslint-plugin"
]
}
cliui-7.0.4/.github/ 0000775 0000000 0000000 00000000000 13752103035 0014166 5 ustar 00root root 0000000 0000000 cliui-7.0.4/.github/workflows/ 0000775 0000000 0000000 00000000000 13752103035 0016223 5 ustar 00root root 0000000 0000000 cliui-7.0.4/.github/workflows/ci.yaml 0000664 0000000 0000000 00000003223 13752103035 0017502 0 ustar 00root root 0000000 0000000 on:
push:
branches:
- master
pull_request:
types: [ assigned, opened, synchronize, reopened, labeled ]
name: ci
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node: [10, 12, 14]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: node --version
- run: npm install
env:
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
- run: npm test
- run: npm run check
windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
- run: npm install
env:
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
- run: npm test
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: npm install
env:
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
- run: npm test
- run: npm run coverage
esm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: npm install
- run: npm run test:esm
deno:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: npm install
- run: npm run compile
- uses: denolib/setup-deno@v2
with:
deno-version: v1.x
- run: |
deno --version
deno test test/deno/cliui-test.ts
cliui-7.0.4/.github/workflows/release-please.yml 0000664 0000000 0000000 00000003217 13752103035 0021640 0 ustar 00root root 0000000 0000000 on:
push:
branches:
- master
name: release-please
jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: bcoe/release-please-action@v2.6.0
id: release
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: node
package-name: cliui
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: npm install
env:
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
- run: npm run compile
- name: push Deno release
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git remote add gh-token "https://${{ secrets.GITHUB_TOKEN}}@github.com/yargs/cliui.git"
git checkout -b deno
git add -f build
git commit -a -m 'chore: ${{ steps.release.outputs.tag_name }} release'
git push origin +deno
git tag -a ${{ steps.release.outputs.tag_name }}-deno -m 'chore: ${{ steps.release.outputs.tag_name }} release'
git push origin ${{ steps.release.outputs.tag_name }}-deno
if: ${{ steps.release.outputs.release_created }}
- uses: actions/setup-node@v1
with:
node-version: 14
registry-url: 'https://external-dot-oss-automation.appspot.com/'
if: ${{ steps.release.outputs.release_created }}
- run: npm install
if: ${{ steps.release.outputs.release_created }}
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
if: ${{ steps.release.outputs.release_created }}
cliui-7.0.4/.gitignore 0000664 0000000 0000000 00000000104 13752103035 0014611 0 ustar 00root root 0000000 0000000 .DS_Store
node_modules
.nyc_output
package-lock.json
coverage
build
cliui-7.0.4/.nycrc 0000664 0000000 0000000 00000000243 13752103035 0013744 0 ustar 00root root 0000000 0000000 {
"exclude": [
"build/test/**",
"test/**"
],
"reporter": [
"html",
"text"
],
"lines": 99.0,
"branches": "95",
"statements": "99.0"
}
cliui-7.0.4/CHANGELOG.md 0000664 0000000 0000000 00000007470 13752103035 0014447 0 ustar 00root root 0000000 0000000 # Change Log
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [7.0.4](https://www.github.com/yargs/cliui/compare/v7.0.3...v7.0.4) (2020-11-08)
### Bug Fixes
* **deno:** import UIOptions from definitions ([#97](https://www.github.com/yargs/cliui/issues/97)) ([f04f343](https://www.github.com/yargs/cliui/commit/f04f3439bc78114c7e90f82ff56f5acf16268ea8))
### [7.0.3](https://www.github.com/yargs/cliui/compare/v7.0.2...v7.0.3) (2020-10-16)
### Bug Fixes
* **exports:** node 13.0 and 13.1 require the dotted object form _with_ a string fallback ([#93](https://www.github.com/yargs/cliui/issues/93)) ([eca16fc](https://www.github.com/yargs/cliui/commit/eca16fc05d26255df3280906c36d7f0e5b05c6e9))
### [7.0.2](https://www.github.com/yargs/cliui/compare/v7.0.1...v7.0.2) (2020-10-14)
### Bug Fixes
* **exports:** node 13.0-13.6 require a string fallback ([#91](https://www.github.com/yargs/cliui/issues/91)) ([b529d7e](https://www.github.com/yargs/cliui/commit/b529d7e432901af1af7848b23ed6cf634497d961))
### [7.0.1](https://www.github.com/yargs/cliui/compare/v7.0.0...v7.0.1) (2020-08-16)
### Bug Fixes
* **build:** main should be build/index.cjs ([dc29a3c](https://www.github.com/yargs/cliui/commit/dc29a3cc617a410aa850e06337b5954b04f2cb4d))
## [7.0.0](https://www.github.com/yargs/cliui/compare/v6.0.0...v7.0.0) (2020-08-16)
### ⚠ BREAKING CHANGES
* tsc/ESM/Deno support (#82)
* modernize deps and build (#80)
### Build System
* modernize deps and build ([#80](https://www.github.com/yargs/cliui/issues/80)) ([339d08d](https://www.github.com/yargs/cliui/commit/339d08dc71b15a3928aeab09042af94db2f43743))
### Code Refactoring
* tsc/ESM/Deno support ([#82](https://www.github.com/yargs/cliui/issues/82)) ([4b777a5](https://www.github.com/yargs/cliui/commit/4b777a5fe01c5d8958c6708695d6aab7dbe5706c))
## [6.0.0](https://www.github.com/yargs/cliui/compare/v5.0.0...v6.0.0) (2019-11-10)
### ⚠ BREAKING CHANGES
* update deps, drop Node 6
### Code Refactoring
* update deps, drop Node 6 ([62056df](https://www.github.com/yargs/cliui/commit/62056df))
## [5.0.0](https://github.com/yargs/cliui/compare/v4.1.0...v5.0.0) (2019-04-10)
### Bug Fixes
* Update wrap-ansi to fix compatibility with latest versions of chalk. ([#60](https://github.com/yargs/cliui/issues/60)) ([7bf79ae](https://github.com/yargs/cliui/commit/7bf79ae))
### BREAKING CHANGES
* Drop support for node < 6.
## [4.1.0](https://github.com/yargs/cliui/compare/v4.0.0...v4.1.0) (2018-04-23)
### Features
* add resetOutput method ([#57](https://github.com/yargs/cliui/issues/57)) ([7246902](https://github.com/yargs/cliui/commit/7246902))
## [4.0.0](https://github.com/yargs/cliui/compare/v3.2.0...v4.0.0) (2017-12-18)
### Bug Fixes
* downgrades strip-ansi to version 3.0.1 ([#54](https://github.com/yargs/cliui/issues/54)) ([5764c46](https://github.com/yargs/cliui/commit/5764c46))
* set env variable FORCE_COLOR. ([#56](https://github.com/yargs/cliui/issues/56)) ([7350e36](https://github.com/yargs/cliui/commit/7350e36))
### Chores
* drop support for node < 4 ([#53](https://github.com/yargs/cliui/issues/53)) ([b105376](https://github.com/yargs/cliui/commit/b105376))
### Features
* add fallback for window width ([#45](https://github.com/yargs/cliui/issues/45)) ([d064922](https://github.com/yargs/cliui/commit/d064922))
### BREAKING CHANGES
* officially drop support for Node < 4
## [3.2.0](https://github.com/yargs/cliui/compare/v3.1.2...v3.2.0) (2016-04-11)
### Bug Fixes
* reduces tarball size ([acc6c33](https://github.com/yargs/cliui/commit/acc6c33))
### Features
* adds standard-version for release management ([ff84e32](https://github.com/yargs/cliui/commit/ff84e32))
cliui-7.0.4/LICENSE.txt 0000664 0000000 0000000 00000001333 13752103035 0014451 0 ustar 00root root 0000000 0000000 Copyright (c) 2015, Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice
appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
cliui-7.0.4/README.md 0000664 0000000 0000000 00000005666 13752103035 0014122 0 ustar 00root root 0000000 0000000 # cliui

[](https://www.npmjs.com/package/cliui)
[](https://conventionalcommits.org)

easily create complex multi-column command-line-interfaces.
## Example
```js
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](https://github.com/denoland/deno) and
[ESM](https://nodejs.org/api/esm.html#esm_ecmascript_modules):
```typescript
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...**
```js
var ui = require('./')({
width: 60
})
ui.div(
'Usage: node ./bin/foo.js\n' +
' \t provide a regex\n' +
' \t provide a glob\t [required]'
)
console.log(ui.toString())
```
**will output:**
```shell
Usage: node ./bin/foo.js
provide a regex
provide a glob [required]
```
## Methods
```js
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`.
cliui-7.0.4/deno.ts 0000664 0000000 0000000 00000000610 13752103035 0014120 0 ustar 00root root 0000000 0000000 // Bootstrap cliui with CommonJS dependencies:
import { cliui, UI } from './build/lib/index.js'
import type { UIOptions } from './build/lib/index.d.ts'
import { wrap, stripAnsi } from './build/lib/string-utils.js'
export default function ui (opts: UIOptions): UI {
return cliui(opts, {
stringWidth: (str: string) => {
return [...str].length
},
stripAnsi,
wrap
})
}
cliui-7.0.4/index.mjs 0000664 0000000 0000000 00000000465 13752103035 0014455 0 ustar 00root root 0000000 0000000 // Bootstrap cliui with CommonJS dependencies:
import { cliui } from './build/lib/index.js'
import { wrap, stripAnsi } from './build/lib/string-utils.js'
export default function ui (opts) {
return cliui(opts, {
stringWidth: (str) => {
return [...str].length
},
stripAnsi,
wrap
})
}
cliui-7.0.4/lib/ 0000775 0000000 0000000 00000000000 13752103035 0013374 5 ustar 00root root 0000000 0000000 cliui-7.0.4/lib/cjs.ts 0000664 0000000 0000000 00000000511 13752103035 0014520 0 ustar 00root root 0000000 0000000 // Bootstrap cliui with CommonJS dependencies:
import { cliui, UIOptions } from './index.js'
const stringWidth = require('string-width')
const stripAnsi = require('strip-ansi')
const wrap = require('wrap-ansi')
export default function ui (opts: UIOptions) {
return cliui(opts, {
stringWidth,
stripAnsi,
wrap
})
}
cliui-7.0.4/lib/index.ts 0000664 0000000 0000000 00000021774 13752103035 0015066 0 ustar 00root root 0000000 0000000 'use strict'
const align = {
right: alignRight,
center: alignCenter
}
const top = 0
const right = 1
const bottom = 2
const left = 3
export interface UIOptions {
width: number;
wrap?: boolean;
rows?: string[];
}
interface Column {
text: string;
width?: number;
align?: 'right'|'left'|'center',
padding: number[],
border?: boolean;
}
interface ColumnArray extends Array {
span: boolean;
}
interface Line {
hidden?: boolean;
text: string;
span?: boolean;
}
interface Mixin {
stringWidth: Function;
stripAnsi: Function;
wrap: Function;
}
export class UI {
width: number;
wrap: boolean;
rows: ColumnArray[];
constructor (opts: UIOptions) {
this.width = opts.width
this.wrap = opts.wrap ?? true
this.rows = []
}
span (...args: ColumnArray) {
const cols = this.div(...args)
cols.span = true
}
resetOutput () {
this.rows = []
}
div (...args: (Column|string)[]): ColumnArray {
if (args.length === 0) {
this.div('')
}
if (this.wrap && this.shouldApplyLayoutDSL(...args) && typeof args[0] === 'string') {
return this.applyLayoutDSL(args[0])
}
const cols = args.map(arg => {
if (typeof arg === 'string') {
return this.colFromString(arg)
}
return arg
}) as ColumnArray
this.rows.push(cols)
return cols
}
private shouldApplyLayoutDSL (...args: (Column|string)[]): boolean {
return args.length === 1 && typeof args[0] === 'string' &&
/[\t\n]/.test(args[0])
}
private applyLayoutDSL (str: string): ColumnArray {
const rows = str.split('\n').map(row => row.split('\t'))
let leftColumnWidth = 0
// simple heuristic for layout, make sure the
// second column lines up along the left-hand.
// don't allow the first column to take up more
// than 50% of the screen.
rows.forEach(columns => {
if (columns.length > 1 && mixin.stringWidth(columns[0]) > leftColumnWidth) {
leftColumnWidth = Math.min(
Math.floor(this.width * 0.5),
mixin.stringWidth(columns[0])
)
}
})
// generate a table:
// replacing ' ' with padding calculations.
// using the algorithmically generated width.
rows.forEach(columns => {
this.div(...columns.map((r, i) => {
return {
text: r.trim(),
padding: this.measurePadding(r),
width: (i === 0 && columns.length > 1) ? leftColumnWidth : undefined
} as Column
}))
})
return this.rows[this.rows.length - 1]
}
private colFromString (text: string): Column {
return {
text,
padding: this.measurePadding(text)
}
}
private measurePadding (str: string): number[] {
// measure padding without ansi escape codes
const noAnsi = mixin.stripAnsi(str)
return [0, noAnsi.match(/\s*$/)[0].length, 0, noAnsi.match(/^\s*/)[0].length]
}
toString (): string {
const lines: Line[] = []
this.rows.forEach(row => {
this.rowToString(row, lines)
})
// don't display any lines with the
// hidden flag set.
return lines
.filter(line => !line.hidden)
.map(line => line.text)
.join('\n')
}
rowToString (row: ColumnArray, lines: Line[]) {
this.rasterize(row).forEach((rrow, r) => {
let str = ''
rrow.forEach((col: string, c: number) => {
const { width } = row[c] // the width with padding.
const wrapWidth = this.negatePadding(row[c]) // the width without padding.
let ts = col // temporary string used during alignment/padding.
if (wrapWidth > mixin.stringWidth(col)) {
ts += ' '.repeat(wrapWidth - mixin.stringWidth(col))
}
// align the string within its column.
if (row[c].align && row[c].align !== 'left' && this.wrap) {
const fn = align[(row[c].align as 'right'|'center')]
ts = fn(ts, wrapWidth)
if (mixin.stringWidth(ts) < wrapWidth) {
ts += ' '.repeat((width || 0) - mixin.stringWidth(ts) - 1)
}
}
// apply border and padding to string.
const padding = row[c].padding || [0, 0, 0, 0]
if (padding[left]) {
str += ' '.repeat(padding[left])
}
str += addBorder(row[c], ts, '| ')
str += ts
str += addBorder(row[c], ts, ' |')
if (padding[right]) {
str += ' '.repeat(padding[right])
}
// if prior row is span, try to render the
// current row on the prior line.
if (r === 0 && lines.length > 0) {
str = this.renderInline(str, lines[lines.length - 1])
}
})
// remove trailing whitespace.
lines.push({
text: str.replace(/ +$/, ''),
span: row.span
})
})
return lines
}
// if the full 'source' can render in
// the target line, do so.
private renderInline (source: string, previousLine: Line) {
const match = source.match(/^ */)
const leadingWhitespace = match ? match[0].length : 0
const target = previousLine.text
const targetTextWidth = mixin.stringWidth(target.trimRight())
if (!previousLine.span) {
return source
}
// if we're not applying wrapping logic,
// just always append to the span.
if (!this.wrap) {
previousLine.hidden = true
return target + source
}
if (leadingWhitespace < targetTextWidth) {
return source
}
previousLine.hidden = true
return target.trimRight() + ' '.repeat(leadingWhitespace - targetTextWidth) + source.trimLeft()
}
private rasterize (row: ColumnArray) {
const rrows: string[][] = []
const widths = this.columnWidths(row)
let wrapped
// word wrap all columns, and create
// a data-structure that is easy to rasterize.
row.forEach((col, c) => {
// leave room for left and right padding.
col.width = widths[c]
if (this.wrap) {
wrapped = mixin.wrap(col.text, this.negatePadding(col), { hard: true }).split('\n')
} else {
wrapped = col.text.split('\n')
}
if (col.border) {
wrapped.unshift('.' + '-'.repeat(this.negatePadding(col) + 2) + '.')
wrapped.push("'" + '-'.repeat(this.negatePadding(col) + 2) + "'")
}
// add top and bottom padding.
if (col.padding) {
wrapped.unshift(...new Array(col.padding[top] || 0).fill(''))
wrapped.push(...new Array(col.padding[bottom] || 0).fill(''))
}
wrapped.forEach((str: string, r: number) => {
if (!rrows[r]) {
rrows.push([])
}
const rrow = rrows[r]
for (let i = 0; i < c; i++) {
if (rrow[i] === undefined) {
rrow.push('')
}
}
rrow.push(str)
})
})
return rrows
}
private negatePadding (col: Column) {
let wrapWidth = col.width || 0
if (col.padding) {
wrapWidth -= (col.padding[left] || 0) + (col.padding[right] || 0)
}
if (col.border) {
wrapWidth -= 4
}
return wrapWidth
}
private columnWidths (row: ColumnArray) {
if (!this.wrap) {
return row.map(col => {
return col.width || mixin.stringWidth(col.text)
})
}
let unset = row.length
let remainingWidth = this.width
// column widths can be set in config.
const widths = row.map(col => {
if (col.width) {
unset--
remainingWidth -= col.width
return col.width
}
return undefined
})
// any unset widths should be calculated.
const unsetWidth = unset ? Math.floor(remainingWidth / unset) : 0
return widths.map((w, i) => {
if (w === undefined) {
return Math.max(unsetWidth, _minWidth(row[i]))
}
return w
})
}
}
function addBorder (col: Column, ts: string, style: string) {
if (col.border) {
if (/[.']-+[.']/.test(ts)) {
return ''
}
if (ts.trim().length !== 0) {
return style
}
return ' '
}
return ''
}
// calculates the minimum width of
// a column, based on padding preferences.
function _minWidth (col: Column) {
const padding = col.padding || []
const minWidth = 1 + (padding[left] || 0) + (padding[right] || 0)
if (col.border) {
return minWidth + 4
}
return minWidth
}
function getWindowWidth (): number {
/* istanbul ignore next: depends on terminal */
if (typeof process === 'object' && process.stdout && process.stdout.columns) {
return process.stdout.columns
}
return 80
}
function alignRight (str: string, width: number): string {
str = str.trim()
const strWidth = mixin.stringWidth(str)
if (strWidth < width) {
return ' '.repeat(width - strWidth) + str
}
return str
}
function alignCenter (str: string, width: number): string {
str = str.trim()
const strWidth = mixin.stringWidth(str)
/* istanbul ignore next */
if (strWidth >= width) {
return str
}
return ' '.repeat((width - strWidth) >> 1) + str
}
let mixin: Mixin
export function cliui (opts: Partial, _mixin: Mixin) {
mixin = _mixin
return new UI({
width: opts?.width || getWindowWidth(),
wrap: opts?.wrap
})
}
cliui-7.0.4/lib/string-utils.ts 0000664 0000000 0000000 00000001733 13752103035 0016414 0 ustar 00root root 0000000 0000000 // Minimal replacement for ansi string helpers "wrap-ansi" and "strip-ansi".
// to facilitate ESM and Deno modules.
// TODO: look at porting https://www.npmjs.com/package/wrap-ansi to ESM.
// The npm application
// Copyright (c) npm, Inc. and Contributors
// Licensed on the terms of The Artistic License 2.0
// See: https://github.com/npm/cli/blob/4c65cd952bc8627811735bea76b9b110cc4fc80e/lib/utils/ansi-trim.js
const ansi = new RegExp('\x1b(?:\\[(?:\\d+[ABCDEFGJKSTm]|\\d+;\\d+[Hfm]|' +
'\\d+;\\d+;\\d+m|6n|s|u|\\?25[lh])|\\w)', 'g')
export function stripAnsi (str: string) {
return str.replace(ansi, '')
}
export function wrap (str: string, width: number) {
const [start, end] = str.match(ansi) || ['', '']
str = stripAnsi(str)
let wrapped = ''
for (let i = 0; i < str.length; i++) {
if (i !== 0 && (i % width) === 0) {
wrapped += '\n'
}
wrapped += str.charAt(i)
}
if (start && end) {
wrapped = `${start}${wrapped}${end}`
}
return wrapped
}
cliui-7.0.4/package.json 0000664 0000000 0000000 00000003757 13752103035 0015130 0 ustar 00root root 0000000 0000000 {
"name": "cliui",
"version": "7.0.4",
"description": "easily create complex multi-column command-line-interfaces",
"main": "build/index.cjs",
"exports": {
".": [
{
"import": "./index.mjs",
"require": "./build/index.cjs"
},
"./build/index.cjs"
]
},
"type": "module",
"module": "./index.mjs",
"scripts": {
"check": "standardx '**/*.ts' && standardx '**/*.js' && standardx '**/*.cjs'",
"fix": "standardx --fix '**/*.ts' && standardx --fix '**/*.js' && standardx --fix '**/*.cjs'",
"pretest": "rimraf build && tsc -p tsconfig.test.json && cross-env NODE_ENV=test npm run build:cjs",
"test": "c8 mocha ./test/*.cjs",
"test:esm": "c8 mocha ./test/esm/cliui-test.mjs",
"postest": "check",
"coverage": "c8 report --check-coverage",
"precompile": "rimraf build",
"compile": "tsc",
"postcompile": "npm run build:cjs",
"build:cjs": "rollup -c",
"prepare": "npm run compile"
},
"repository": "yargs/cliui",
"standard": {
"ignore": [
"**/example/**"
],
"globals": [
"it"
]
},
"keywords": [
"cli",
"command-line",
"layout",
"design",
"console",
"wrap",
"table"
],
"author": "Ben Coe ",
"license": "ISC",
"dependencies": {
"string-width": "^4.2.0",
"strip-ansi": "^6.0.0",
"wrap-ansi": "^7.0.0"
},
"devDependencies": {
"@types/node": "^14.0.27",
"@typescript-eslint/eslint-plugin": "^4.0.0",
"@typescript-eslint/parser": "^4.0.0",
"@wessberg/rollup-plugin-ts": "^1.3.2",
"c8": "^7.3.0",
"chai": "^4.2.0",
"chalk": "^4.1.0",
"cross-env": "^7.0.2",
"eslint": "^7.6.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-node": "^11.1.0",
"gts": "^3.0.0",
"mocha": "^8.1.1",
"rimraf": "^3.0.2",
"rollup": "^2.23.1",
"standardx": "^7.0.0",
"typescript": "^4.0.0"
},
"files": [
"build",
"index.mjs",
"!*.d.ts"
],
"engine": {
"node": ">=10"
}
}
cliui-7.0.4/renovate.json 0000664 0000000 0000000 00000000160 13752103035 0015341 0 ustar 00root root 0000000 0000000 {
"extends": [
"config:base"
],
"pinVersions": false,
"rebaseStalePrs": true,
"gitAuthor": null
}
cliui-7.0.4/rollup.config.js 0000664 0000000 0000000 00000000443 13752103035 0015746 0 ustar 00root root 0000000 0000000 import ts from '@wessberg/rollup-plugin-ts'
const output = {
format: 'cjs',
file: './build/index.cjs',
exports: 'default'
}
if (process.env.NODE_ENV === 'test') output.sourcemap = true
export default {
input: './lib/cjs.ts',
output,
plugins: [
ts({ /* options */ })
]
}
cliui-7.0.4/screenshot.png 0000664 0000000 0000000 00000043515 13752103035 0015521 0 ustar 00root root 0000000 0000000 PNG
IHDR 8 6Y PiCCPICC Profile X YgTsQrs.IP"D
FDD@"
(*@{}s<[]]TuOT- djll$
@Tt