Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop cjs #129

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .coveralls.yml

This file was deleted.

21 changes: 3 additions & 18 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [12, 16, 18]
node: [16, 18]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
Expand All @@ -21,7 +21,7 @@ jobs:
env:
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
- run: npm test
- run: npm run check
- run: npm run lint
windows:
runs-on: windows-latest
steps:
Expand Down Expand Up @@ -53,19 +53,4 @@ jobs:
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
- run: npm run test
47 changes: 0 additions & 47 deletions .github/workflows/release-please.yml

This file was deleted.

47 changes: 9 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# cliui

![ci](https://github.com/yargs/cliui/workflows/ci/badge.svg)
[![NPM version](https://img.shields.io/npm/v/cliui.svg)](https://www.npmjs.com/package/cliui)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
![nycrc config on GitHub](https://img.shields.io/nycrc/yargs/cliui)

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

## Example

> **Note** This package is ESM only.

```js
const ui = require('cliui')()
import cliui from '@topcli/cli';

const ui = cliui();

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

Expand Down Expand Up @@ -40,33 +39,7 @@ ui.div(
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())
```

<img width="500" src="screenshot.png">
<img width="500" src="public/screenshot.png">

## Layout DSL

Expand All @@ -82,7 +55,9 @@ object:
**as an example...**

```js
var ui = require('./')({
import cliui from '@topcli/cli';

const ui = cliui({
width: 60
})

Expand All @@ -105,10 +80,6 @@ Usage: node ./bin/foo.js

## Methods

```js
cliui = require('cliui')
```

### cliui({width: integer})

Specify the maximum width of the UI being generated.
Expand Down
14 changes: 0 additions & 14 deletions deno.ts

This file was deleted.

13 changes: 9 additions & 4 deletions index.mjs → index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
// Bootstrap cliui with CommonJS dependencies:
import { cliui } from './build/lib/index.js'
import { wrap, stripAnsi } from './build/lib/string-utils.js'
import wrap from 'wrap-ansi'
import stripAnsi from 'strip-ansi'

import wcswidth from '@topcli/wcwidth'

export default function ui (opts) {
return cliui(opts, {
stringWidth: (str) => {
return [...str].length
return wcswidth(stripAnsi(str))
},
stripAnsi,
wrap



wrap,
})
}
12 changes: 0 additions & 12 deletions lib/cjs.ts

This file was deleted.

17 changes: 7 additions & 10 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class UI {
rows.forEach(columns => {
this.div(...columns.map((r, i) => {
return {
text: r.trim(),
text: r,
padding: this.measurePadding(r),
width: (i === 0 && columns.length > 1) ? leftColumnWidth : undefined
} as Column
Expand Down Expand Up @@ -152,11 +152,10 @@ export class UI {
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))
const strWidth = mixin.stringWidth(col.trim())
if (wrapWidth > strWidth) {
ts += ' '.repeat(wrapWidth - strWidth)
}

// align the string within its column.
Expand All @@ -167,7 +166,6 @@ export class UI {
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]) {
Expand Down Expand Up @@ -204,7 +202,7 @@ export class UI {
const match = source.match(/^ */)
const leadingWhitespace = match ? match[0].length : 0
const target = previousLine.text
const targetTextWidth = mixin.stringWidth(target.trimRight())
const targetTextWidth = mixin.stringWidth(target)

if (!previousLine.span) {
return source
Expand All @@ -222,8 +220,7 @@ export class UI {
}

previousLine.hidden = true

return target.trimRight() + ' '.repeat(leadingWhitespace - targetTextWidth) + source.trimLeft()
return target + ' '.repeat(leadingWhitespace - targetTextWidth) + source
}

private rasterize (row: ColumnArray) {
Expand All @@ -237,7 +234,7 @@ export class UI {
// 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')
wrapped = mixin.wrap(col.text, this.negatePadding(col), { hard: true, trim: true }).split('\n')
} else {
wrapped = col.text.split('\n')
}
Expand Down
30 changes: 0 additions & 30 deletions lib/string-utils.ts

This file was deleted.

Loading