Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.log(os.EOL) // eslint-disable-line
// Write content
let content = ' '
if (this._.useTimer) {
content += ` ${grey(this._.seconds + 's')}`
content += ` ${grey(figures.pointerSmall)}`
}
content += ` ${stage}`
content += ` ${grey(figures.pointerSmall)} ${this._.parentComponent}`
content += ` ${grey(figures.pointerSmall)} ${message}`
process.stdout.write(content)
// Put cursor to starting position for next view
console.log(os.EOL) // eslint-disable-line
process.stdout.write(ansiEscapes.cursorLeft)
process.stdout.write(ansiEscapes.cursorShow)
if (reason === 'error') {
process.exit(1)
} else {
process.exit(0)
}
}
close(reason, message) {
if (reason === 'error') {
message = red(message)
}
if (reason === 'cancel') {
message = red('Canceled')
}
if (reason === 'done') {
message = green(message || 'Done')
}
// Clear any existing content
process.stdout.write(ansiEscapes.cursorLeft)
process.stdout.write(ansiEscapes.eraseDown)
// Write content
this.log()
let content = ''
if (this._.timer) {
content += `${grey(this._.timerSeconds + 's')}`
content += ` ${grey(figures.pointerSmall)} `
}
content += `${this._.entity} `
content += `${grey(figures.pointerSmall)} ${message}`
process.stdout.write(content)
// Put cursor to starting position for next view
console.log(os.EOL) // eslint-disable-line
process.stdout.write(ansiEscapes.cursorLeft)
render: async (frame = 0) => {
const nextFrame = ++frame
const second = String(Math.floor(nextFrame / 10) + 1) // cause we're running at 10 frames per second
let coloredStage
if (['dev', 'development'].includes(stage)) {
coloredStage = chalk.green(stage)
} else if (['prod', 'production'].includes(stage)) {
coloredStage = chalk.red(stage)
} else {
coloredStage = chalk.yellow(stage)
}
cli.write(
`${ansiEscapes.cursorHide +
ansiEscapes.cursorLeft +
ansiEscapes.eraseDown}\n ${chalk.grey(
`${second}s ${figures.pointerSmall}`
)} ${coloredStage} ${chalk.grey(figures.pointerSmall)} ${componentName} ${chalk.grey(
figures.pointerSmall
)} ${chalk.yellow(cli.msg)}\n${ansiEscapes.cursorLeft + ansiEscapes.cursorUp(2)}`
)
if (!cli.running) {
cli.write(
`${ansiEscapes.cursorShow + ansiEscapes.cursorLeft + ansiEscapes.cursorDown(2)}\n`
)
return
}
await sleep(100)
cli.render(nextFrame)
},
write: process.stdout.write.bind(process.stdout)
if (clearingLine) {
process.stdout.write('\n')
}
}
process.stdout.write(data)
lastOutputClearedLine = clearingLine ? folder : false
lastOutputFolder = folder
}
// Data chunk processing
const regEraseLine = new RegExp(escapeAnsiEscapeSeq(ansiEscapes.eraseLine), 'g')
const regMoveCursor = new RegExp(`(${[
'\r',
escapeAnsiEscapeSeq(ansiEscapes.cursorLeft),
escapeAnsiEscapeSeq(ansiEscapes.cursorTo(0)),
escapeAnsiEscapeSeq(ansiEscapes.cursorTo(1)),
].join('|')})+`, 'g')
const regNewLine = /(\n)/g
const fakePrintBorder = '__print_border__'
const fakePrintBorderReg = new RegExp(fakePrintBorder, 'g')
const printBorder = `${ansiEscapes.cursorTo(0)}${border}${ansiEscapes.cursorTo(2)}`
const printEraseLine = `${ansiEscapes.eraseLine}${fakePrintBorder}`
const printReplaceNewLine = `$&${fakePrintBorder}`
/**
* Process text to print border and move all output 2 charaters to the right
* @param {string} data
*/
const processOutput = (data) => {
data = data.replace(regEraseLine, printEraseLine)
return new Promise(function (resolve, reject) {
let stdin = process.stdin
let stderr = process.stderr
let input = ''
stdin.setEncoding('utf8')
stderr.write(ansi.eraseLine)
stderr.write(ansi.cursorLeft)
cli.console.writeError(options.prompt)
stdin.resume()
stdin.setRawMode(true)
function stop () {
if (!options.hide) {
stderr.write(
ansi.cursorHide +
ansi.cursorLeft +
options.prompt +
input.replace(/./g, '*') +
'\n' +
ansi.cursorShow)
} else {
stderr.write('\n')
}
return new Promise(function (resolve, reject) {
let stdin = process.stdin
let stderr = process.stderr
let input = ''
stdin.setEncoding('utf8')
stderr.write(ansi.eraseLine)
stderr.write(ansi.cursorLeft)
cli.console.writeError(options.prompt)
stdin.resume()
stdin.setRawMode(true)
function stop () {
if (!options.hide) {
stderr.write(
ansi.cursorHide +
ansi.cursorLeft +
options.prompt +
input.replace(/./g, '*') +
'\n' +
ansi.cursorShow)
} else {
stderr.write('\n')
}
_onChange(pattern: string, options: ScrollOptions) {
this._pipe.write(ansiEscapes.eraseLine);
this._pipe.write(ansiEscapes.cursorLeft);
}
}
if (['dev', 'development'].includes(stage)) {
coloredStage = chalk.green(stage)
} else if (['prod', 'production'].includes(stage)) {
coloredStage = chalk.red(stage)
} else {
coloredStage = chalk.yellow(stage)
}
cli.write(
`${ansiEscapes.cursorHide +
ansiEscapes.cursorLeft +
ansiEscapes.eraseDown}\n ${chalk.grey(
`${second}s ${figures.pointerSmall}`
)} ${coloredStage} ${chalk.grey(figures.pointerSmall)} ${componentName} ${chalk.grey(
figures.pointerSmall
)} ${chalk.yellow(cli.msg)}\n${ansiEscapes.cursorLeft + ansiEscapes.cursorUp(2)}`
)
if (!cli.running) {
cli.write(
`${ansiEscapes.cursorShow + ansiEscapes.cursorLeft + ansiEscapes.cursorDown(2)}\n`
)
return
}
await sleep(100)
cli.render(nextFrame)
},
write: process.stdout.write.bind(process.stdout)