pax_global_header 0000666 0000000 0000000 00000000064 14765705156 0014532 g ustar 00root root 0000000 0000000 52 comment=2737977df41e728bd8c7d3ca0658498273cecce5
yargs-cliui-2737977/ 0000775 0000000 0000000 00000000000 14765705156 0014175 5 ustar 00root root 0000000 0000000 yargs-cliui-2737977/.coveralls.yml 0000664 0000000 0000000 00000000056 14765705156 0016771 0 ustar 00root root 0000000 0000000 repo_token: NiRhyj91Z2vtgob6XdEAqs83rzNnbMZUu
yargs-cliui-2737977/.eslintrc 0000664 0000000 0000000 00000000710 14765705156 0016017 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"
]
}
yargs-cliui-2737977/.github/ 0000775 0000000 0000000 00000000000 14765705156 0015535 5 ustar 00root root 0000000 0000000 yargs-cliui-2737977/.github/workflows/ 0000775 0000000 0000000 00000000000 14765705156 0017572 5 ustar 00root root 0000000 0000000 yargs-cliui-2737977/.github/workflows/ci.yaml 0000664 0000000 0000000 00000002674 14765705156 0021062 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: [20, 22]
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: 22
- 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: 22
- run: npm install
env:
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
- run: npm test
- run: npm run coverage
deno:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 22
- 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
yargs-cliui-2737977/.github/workflows/release-please.yml 0000664 0000000 0000000 00000003213 14765705156 0023203 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@v3
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 }}
yargs-cliui-2737977/.gitignore 0000664 0000000 0000000 00000000104 14765705156 0016160 0 ustar 00root root 0000000 0000000 .DS_Store
node_modules
.nyc_output
package-lock.json
coverage
build
yargs-cliui-2737977/.nycrc 0000664 0000000 0000000 00000000243 14765705156 0015313 0 ustar 00root root 0000000 0000000 {
"exclude": [
"build/test/**",
"test/**"
],
"reporter": [
"html",
"text"
],
"lines": 99.0,
"branches": "95",
"statements": "99.0"
}
yargs-cliui-2737977/CHANGELOG.md 0000664 0000000 0000000 00000012073 14765705156 0016011 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.
## [9.0.1](https://github.com/yargs/cliui/compare/v9.0.0...v9.0.1) (2025-03-17)
### Bug Fixes
* make require("cliui") work as expected for CJS ([04ccc25](https://github.com/yargs/cliui/commit/04ccc250e30a059292c03fa1ef0a8661f8d93dfe))
## [9.0.0](https://github.com/yargs/cliui/compare/v8.0.1...v9.0.0) (2025-03-16)
### ⚠ BREAKING CHANGES
* cliui is now ESM only ([#165](https://github.com/yargs/cliui/issues/165))
### Features
* cliui is now ESM only ([#165](https://github.com/yargs/cliui/issues/165)) ([5a521de](https://github.com/yargs/cliui/commit/5a521de7ea88f262236394c8d96775bcf50ff0a4))
## [8.0.1](https://github.com/yargs/cliui/compare/v8.0.0...v8.0.1) (2022-10-01)
### Bug Fixes
* **deps:** move rollup-plugin-ts to dev deps ([#124](https://github.com/yargs/cliui/issues/124)) ([7c8bd6b](https://github.com/yargs/cliui/commit/7c8bd6ba024d61e4eeae310c7959ab8ab6829081))
## [8.0.0](https://github.com/yargs/cliui/compare/v7.0.4...v8.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](https://github.com/yargs/cliui/issues/122)) ([f156571](https://github.com/yargs/cliui/commit/f156571ce4f2ebf313335e3a53ad905589da5a30))
### [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))
yargs-cliui-2737977/LICENSE.txt 0000664 0000000 0000000 00000001333 14765705156 0016020 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.
yargs-cliui-2737977/README.md 0000664 0000000 0000000 00000006444 14765705156 0015464 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
```bash
npm i cliui@latest chalk@latest
```
```js
const ui = require('cliui')()
const {Chalk} = require('chalk');
const chalk = new Chalk();
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 "cliui";
import chalk from "chalk";
// Deno: 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]
},
{
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())
```
## 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`.
yargs-cliui-2737977/deno.ts 0000664 0000000 0000000 00000000610 14765705156 0015467 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 stringWidth from 'string-width'
import stripAnsi from 'strip-ansi'
import wrapAnsi from 'wrap-ansi'
export default function ui (opts: UIOptions): UI {
return cliui(opts, {
stringWidth,
stripAnsi,
wrap: wrapAnsi
})
}
yargs-cliui-2737977/index.mjs 0000664 0000000 0000000 00000000537 14765705156 0016024 0 ustar 00root root 0000000 0000000 // Bootstrap cliui with CommonJS dependencies:
import { cliui } from './build/lib/index.js'
import stringWidth from 'string-width'
import stripAnsi from 'strip-ansi'
import wrapAnsi from 'wrap-ansi'
export default function ui (opts) {
return cliui(opts, {
stringWidth,
stripAnsi,
wrap: wrapAnsi
})
}
export {ui as 'module.exports'};
yargs-cliui-2737977/lib/ 0000775 0000000 0000000 00000000000 14765705156 0014743 5 ustar 00root root 0000000 0000000 yargs-cliui-2737977/lib/index.ts 0000664 0000000 0000000 00000021764 14765705156 0016434 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 {
/* c8 ignore next 5: 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)
/* c8 ignore next 3 */
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
})
}
yargs-cliui-2737977/package.json 0000664 0000000 0000000 00000003137 14765705156 0016467 0 ustar 00root root 0000000 0000000 {
"name": "cliui",
"version": "9.0.1",
"description": "easily create complex multi-column command-line-interfaces",
"main": "build/index.mjs",
"exports": {
".": "./index.mjs"
},
"type": "module",
"module": "./index.mjs",
"scripts": {
"check": "standardx '**/*.ts' && standardx '**/*.js'",
"fix": "standardx --fix '**/*.ts' && standardx --fix '**/*.js'",
"pretest": "rimraf build && tsc -p tsconfig.test.json",
"test": "c8 mocha ./test/*.mjs",
"postest": "check",
"coverage": "c8 report --check-coverage",
"precompile": "rimraf build",
"compile": "tsc",
"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": "^7.2.0",
"strip-ansi": "^7.1.0",
"wrap-ansi": "^9.0.0"
},
"devDependencies": {
"@types/node": "^22.13.10",
"@typescript-eslint/eslint-plugin": "^4.0.0",
"@typescript-eslint/parser": "^4.0.0",
"c8": "^10.1.3",
"chai": "^5.2.0",
"chalk": "^5.4.1",
"cross-env": "^7.0.2",
"eslint": "^7.6.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-n": "^14.0.0",
"gts": "^6.0.2",
"mocha": "^11.1.0",
"rimraf": "^6.0.1",
"standardx": "^7.0.0",
"typescript": "^5.8.2"
},
"files": [
"build",
"index.mjs",
"!*.d.ts"
],
"engines": {
"node": ">=20"
}
}
yargs-cliui-2737977/renovate.json 0000664 0000000 0000000 00000000160 14765705156 0016710 0 ustar 00root root 0000000 0000000 {
"extends": [
"config:base"
],
"pinVersions": false,
"rebaseStalePrs": true,
"gitAuthor": null
}
yargs-cliui-2737977/rollup.config.js 0000664 0000000 0000000 00000000431 14765705156 0017312 0 ustar 00root root 0000000 0000000 import ts from '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 */ })
]
}
yargs-cliui-2737977/screenshot.png 0000664 0000000 0000000 00000043515 14765705156 0017070 0 ustar 00root root 0000000 0000000 PNG
IHDR 8 6Y PiCCPICC Profile X YgTsQrs.IP"D
FDD@"
(*@{}s<[]]TuOT- djll$
@Tt