Nuxt/packages/cli/src/formatting.js
Jonas Galvez 6dadadfa25 feat(cli): list commands (#4245)
* add listCommands to cli/run

* add listCommands to cli/run (2)

* lint

* lint

* lint

* fix

* fixes

* fix

* lint

* maxCharsPerLine = process.stdout.columns * 80 / 100

* fix test

* fix imports

* refactor foldLines()

* default process.stdout.columns to 80

* default to 80

* fix

* fix test

* lint

* fix test

* add help flags to main usage

* fix

* fix

* fix
2018-11-01 04:53:06 +01:00

30 lines
847 B
JavaScript

import wrapAnsi from 'wrap-ansi'
export const startSpaces = 2
export const optionSpaces = 2
// 80% of terminal column width
export const maxCharsPerLine = (process.stdout.columns || 100) * 80 / 100
export function indent(count, chr = ' ') {
return chr.repeat(count)
}
export function indentLines(string, spaces, firstLineSpaces) {
const lines = Array.isArray(string) ? string : string.split('\n')
let s = ''
if (lines.length) {
const i0 = indent(firstLineSpaces === undefined ? spaces : firstLineSpaces)
s = i0 + lines.shift()
}
if (lines.length) {
const i = indent(spaces)
s += '\n' + lines.map(l => i + l).join('\n')
}
return s
}
export function foldLines(string, spaces, firstLineSpaces, maxCharsPerLine) {
return indentLines(wrapAnsi(string, maxCharsPerLine, { trim: false }), spaces, firstLineSpaces)
}