Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cols: process.stdout.columns - 2,
rows: process.stdout.rows,
cwd: folder,
env: process.env,
})
children.add(child)
folderMap.set(folder, child)
const printTag = `\n\n${tag}\n${border}${ansiEscapes.cursorTo(2)}`
const hasClearLineRef = new RegExp([
`\r`,
escapeAnsiEscapeSeq(ansiEscapes.eraseLine),
escapeAnsiEscapeSeq(ansiEscapes.cursorLeft),
escapeAnsiEscapeSeq(ansiEscapes.cursorTo(0)),
escapeAnsiEscapeSeq(ansiEscapes.cursorTo(1)),
].join('|'))
/**
* Print a data chunk to stdout
* @param {string} data
*/
const print = (data) => {
if (quiet || !data.trim()) return
const clearingLine = hasClearLineRef.test(data)
data = processOutput(data)
if (lastOutputFolder !== folder) {
if (lastOutputClearedLine) {
process.stdout.write(ansiEscapes.eraseLine)
process.stdout.write(ansiEscapes.cursorTo(0))
}
// Different folder => print folder tag
const print = (data) => {
if (quiet || !data.trim()) return
const clearingLine = hasClearLineRef.test(data)
data = processOutput(data)
if (lastOutputFolder !== folder) {
if (lastOutputClearedLine) {
process.stdout.write(ansiEscapes.eraseLine)
process.stdout.write(ansiEscapes.cursorTo(0))
}
// Different folder => print folder tag
process.stdout.write(printTag)
if (clearingLine) {
process.stdout.write('\n')
}
}
process.stdout.write(data)
lastOutputClearedLine = clearingLine ? folder : false
lastOutputFolder = folder
}
scroller = undefined
menuItems = []
} else if (ctrl && name === 'd') {
stop()
return resolve([Commands.Exit, {}])
} else if (ctrl && name === 'c') {
stop()
if (rl.line === '') {
stdout.write(c.gray(`Press \`${c.bold('ctrl+d')}\` to exit.\n`))
}
return resolve([Commands.Abort, {}])
} else if (ctrl && name === 'l') {
stdout.write(ansiEscapes.cursorTo(0, 0))
stdout.write(ansiEscapes.eraseDown)
} else if (ctrl && name === 'z' && process.platform !== 'win32') {
setRawMode(false)
process.once('SIGCONT', () => {
setRawMode(true)
rerender()
})
stdout.write('\n')
process.kill(process.pid, 'SIGTSTP')
} else if (name === 'return') {
stop()
return resolve([Commands.Line, {line: rl.line}])
} else if (hasPrePair(sequence) && sequence === relativeCharacter(0)) {
// Next character is a pair and is the same as the one entered, ghost it
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)
data = data.replace(regMoveCursor, fakePrintBorder)
data = data.replace(regNewLine, printReplaceNewLine)
data = data.replace(fakePrintBorderReg, printBorder)
return data
}
/**
resetCursor(): this {
this.console.out(ansiEscapes.cursorTo(0, this.size().rows));
return this;
}
private setCursorAt({ x, y }: IPosition): void {
this.print(ansiEscapes.cursorTo(x, y));
}
private setCursorAt({ x, y }: IPosition) {
this.print(ansiEscapes.cursorTo(x, y));
}
reset(heading) {
stderr(`${ansiEscape.eraseScreen}${ansiEscape.cursorTo(0, 0)}${heading}`);
},
};
const rate = this.getAvgRate()
const [unit, eta] = getRateInfo(rate, this.total, this.current)
const percent = Math.min(Math.max(this.current / this.total), 1)
const progress = ` ${this.current}/${this.total} | ETA: ${eta} ${unit}`
const width = Math.max(0, process.stdout.columns - progress.length - 3)
const filledLength = Math.round(width * percent)
const filled = bar[0].repeat(filledLength)
const empty = bar[1].repeat(width - filledLength)
process.stdout.write(eraseLine)
process.stdout.write(cursorTo(0))
process.stdout.write(`[${filled}${empty}]${progress}`)
}
}