mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 00:52:01 +00:00
30 lines
847 B
JavaScript
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)
|
||
|
}
|