Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function redraw (testRuns, watch, count = 15) {
const arranged = limit(sort(testRuns), count)
if (watch) {
process.stdout.write(ansiEscapes.eraseDown)
}
const rows = arranged.map((testRun) => columns(testRun, testRuns))
// this is a massive hack but I basically create a table that does not print so I can calculate its width if it were printed
let width = 0
function printLine (line) {
width = line.length
}
cli.table(rows, {
printLine: printLine,
printHeader: false
})
const printRows = arranged.map((testRun) => columns(testRun, testRuns).concat([progressBar(testRun, testRuns, width)]))
if (debug) {
process.env.DEBUG = "webiny*";
context.debug = require("debug")("webiny");
}
const Template = require("./template/serverless.js");
const component = new Template(`Webiny.${env}`, context);
await component.init();
const output = await component[method]({ env, debug, alias });
if (debug) {
// Add an empty line after debug output for nicer output
console.log();
}
context._.status.running = false;
process.stdout.write(ansiEscapes.cursorLeft);
process.stdout.write(ansiEscapes.eraseDown);
process.stdout.write(ansiEscapes.cursorShow);
process.chdir(cwd);
return { output, duration: context._.seconds };
};
renderStatusStatement(status, entity) {
// If no arguments, skip
if (!status || status == '') {
return
}
if (!entity || entity == '') {
return
}
// Clear any existing content
process.stdout.write(ansiEscapes.eraseDown)
console.log() // eslint-disable-line
// Write log
entity = `${this._.useTimer ? grey(this._.seconds + `s` + figures.pointerSmall) : ''} ${grey(
entity
)} ${grey(figures.pointerSmall)} ${grey(`status:`)}`
console.log(` ${entity}`) // eslint-disable-line
console.log(` `, status) //eslint-disable-line
// Put cursor to starting position for next view
process.stdout.write(ansiEscapes.cursorLeft)
}
if (this._.loadingDotCount === 0) {
this._.loadingDots = `.`
} else if (this._.loadingDotCount === 2) {
this._.loadingDots = `..`
} else if (this._.loadingDotCount === 4) {
this._.loadingDots = `...`
} else if (this._.loadingDotCount === 6) {
this._.loadingDots = ''
}
this._.loadingDotCount++
if (this._.loadingDotCount > 8) {
this._.loadingDotCount = 0
}
// Clear any existing content
process.stdout.write(ansiEscapes.eraseDown)
// Write status content
console.log() // eslint-disable-line
let content = ''
if (this._.timer) {
content += `${grey(this._.timerSeconds + 's')} `
content += `${grey(figures.pointerSmall)} `
}
content += `${this._.entity} `
content += `${grey(figures.pointerSmall)} ${grey(this._.status)}`
content += ` ${grey(this._.loadingDots)}`
process.stdout.write(content)
console.log() // eslint-disable-line
// Put cursor to starting position for next view
const startingPosition = this._getRelativeVerticalCursorPosition(content)
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
// input `)`: `(|)` -> `()|`
function draw(testRuns: Heroku.TestRun[], watchOption = false, jsonOption = false, count = 15) {
const latestTestRuns = sort(testRuns).slice(0, count)
if (jsonOption) {
cli.styledJSON(latestTestRuns)
return
}
if (watchOption) {
process.stdout.write(ansiEscapes.eraseDown)
}
let data: any = []
latestTestRuns.forEach(testRun => {
data.push(
{
iconStatus: `${statusIcon(testRun)}`,
number: testRun.number,
branch: testRun.commit_branch,
sha: testRun.commit_sha!.slice(0, 7),
status: testRun.status
}
)
})
var size_host = 4
var size_meta = 4
var size_tag = 3
sortedmembers.forEach(function(m) {
size_host = Math.max(size_host, m.host.length)
size_meta = Math.max(size_meta, m.meta.length)
size_tag = Math.max(size_tag, m.tag.length)
})
var nm = sortedmembers.length
w(AE.clearScreen)
w(AE.cursorHide)
w(AE.cursorUp(nm + 2))
w(AE.eraseDown)
console.log(
head(
[
Pad('host', size_host),
Pad(2, 'a'),
Pad(2, 'r'),
Pad(2, 's'),
Pad(8, 'time'),
Pad('tag', size_tag),
Pad('meta', size_meta),
'id'
].join(' ')
)
)
clearScreenDown(callback) {
assertCallback(callback);
return this.write(ansiEscapes.eraseDown, callback);
},
process.stdout.write = (message) => {
const newLine = message.endsWith('\n') ? '' : '\n'
return cli.write(`${message + ansiEscapes.eraseDown + newLine}`)
}
jay.on('keypress', (key, stop) => {
if (key.ctrl && key.name === 'l') {
jay.stdout.write(ansiEscapes.cursorTo(0, 0))
jay.stdout.write(ansiEscapes.eraseDown)
return stop(key)
}
return key
})