Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
write(x, y, text, {transformers}) {
if (!text) {
return;
}
const lines = text.split('\n');
let offsetY = 0;
for (let line of lines) {
const length = stringLength(line);
const currentLine = this.output[y + offsetY];
// Line can be missing if `text` is taller than height of pre-initialized `this.output`
if (!currentLine) {
continue;
}
for (const transformer of transformers) {
line = transformer(line);
}
this.output[y + offsetY] = sliceAnsi(currentLine, 0, x) + line + sliceAnsi(currentLine, x + length);
offsetY++;
}
}
}
for (const write of this.writes) {
const {x, y, text, transformers} = write;
const lines = text.split('\n');
let offsetY = 0;
for (let line of lines) {
const currentLine = output[y + offsetY];
// Line can be missing if `text` is taller than height of pre-initialized `this.output`
if (!currentLine) {
continue;
}
const length = stringLength(line);
for (const transformer of transformers) {
line = transformer(line);
}
output[y + offsetY] = sliceAnsi(currentLine, 0, x) + line + sliceAnsi(currentLine, x + length);
offsetY++;
}
}
const generatedOutput = output
.map(line => line.trimRight())
.join('\n');
return {
// Color the prefix depending on the event name / severity level.
switch (logRecord.payload.name) {
case 'error': { text = ck.red.bold(text); break; }
case 'warn': { text = ck.yellow.bold(text); break; }
default: { text = ck.dim.bold(text); break; }
}
// If there's context, color it and append it.
if (logRecord.contextString !== null) {
text += ` ${ck.hex('#44e').bold(logRecord.contextString)}`;
}
// **Note:** `stringLength()` takes into account the fact that ANSI color
// escapes don't add to the visual-length of a string. `+1` to guarantee at
// least one space of padding.
const length = stringLength(text) + 1;
// Update the prefix length instance variables. What we're doing here is
// adjusting the prefix area to be wider when we discover a prefix which
// would be longer than what we've seen before. At the same time, we record
// a recently-observed maximum, and we reset to that from time to time. The
// latter prevents brief "prefix blow-outs" from permanently messing with
// the log output.
const MIN = MIN_PREFIX_LENGTH;
const ADJUST = PREFIX_ADJUST_INCREMENT;
const prefixLength = (length <= MIN)
? MIN
: Math.ceil((length - MIN) / ADJUST) * ADJUST + MIN;
this._prefixLength = Math.max(this._prefixLength, prefixLength);
this._recentMaxPrefix = Math.max(this._recentMaxPrefix, prefixLength);
this._recentLineCount++;
if (this._recentLineCount >= 100) {
_printTypeahead(pattern: string, options: ScrollOptions) {
const matchedTests = this._getMatchedTests(pattern);
const total = matchedTests.length;
const pipe = this._pipe;
const prompt = this._prompt;
printPatternCaret(pattern, pipe);
pipe.write(ansiEscapes.cursorLeft);
if (pattern) {
printPatternMatches(total, 'file', pipe);
const prefix = ` ${chalk.dim('\u203A')} `;
const padding = stringLength(prefix) + 2;
const width = getTerminalWidth(pipe);
const { start, end, index } = scroll(total, options);
prompt.setPromptLength(total);
matchedTests
.slice(start, end)
.map(({ path, context }) => {
const filePath = trimAndFormatPath(
padding,
context.config,
path,
width,
);
return highlight(path, filePath, pattern, context.config.rootDir);
})
function padStep (s: string, step: number) {
const sLength = stringLength(s)
const placeholderLength = Math.ceil(sLength / step) * step
if (sLength < placeholderLength) {
return R.repeat(' ', placeholderLength - sLength).join('') + s
}
return s
}
(prev, l) => { return Math.max(prev, stringLength(l)); },
0);