Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
printData(response) {
if (! response.data) {
return print(chalk.gray(''));
}
// Handle pretty-printing common types of content (by header).
if (response.headers && response.headers['content-type']) {
let type = response.headers['content-type'];
if (type.includes('application/json')) {
return printJson(response.data);
} else if (type.includes('text/html') || type.includes('application/xml')) {
return print(emphasize.highlight('xml', response.data).value);
} else if (type.includes('text/plain')) {
return print(response.data);
}
}
// ...or try to guess!
return print(emphasize.highlightAuto(response.data).value);
}
}
const highlightSheet: Sheet = {
keyword: c.magenta,
built_in: c.cyan.italic,
literal: c.cyan,
number: c.yellow,
regexp: c.red,
string: c.green,
symbol: c.cyan,
class: c.yellow.italic,
attr: c.cyan,
comment: c.gray
}
/* eslint-enable @typescript-eslint/camelcase */
return [
emphasize.highlight(
'js',
output,
highlightSheet
).value,
cursor
]
})
}
const stringToAnsi = exports.stringToAnsi = ( str, language ) => {
// accept case-insensitive language
language = _.isEmpty( language ) ? null : language.toLowerCase();
// if `language` is not supported, return `str` back without syntax highlighting
if( ! _.includes( _.values( LANGUAGES ), language ) ) {
return str;
}
// highlight `str` using `emphasize` package in ANSI color format
const { value } = emphasize.highlight( language, str );
// return ANSI formatted string
return value;
};
var log_snippet = function (lines, code, filepath, file_ext, nocolors) {
if (nocolors) {
console.log(_.zip(lines, code.split("\n"))
.map(function (s) { return s.join(" "); }).join("\n"));
}
else {
var colored = void 0;
try {
colored = _.get(emphasize
.highlight(file_ext, code), "value", "");
}
catch (e) {
log.warn("highlighting failed for " + filepath + ":");
colored = code;
}
var colored_lines = lines.map(function (l) { return chalk.gray(l); });
console.log(_.zip(colored_lines, colored.split("\n"))
.map(function (s) { return s.join(""); }).join("\n"));
}
};
var to_console_snippet = function (issue, nocolors) {
const log_snippet = (
lines : any[],
code : string,
filepath : string,
file_ext : string,
nocolors : boolean
) : void => {
if (nocolors) {
console.log(_.zip(lines, code.split("\n"))
.map((s : any[]) => s.join(" ")).join("\n"))
} else {
let colored : string
try {
colored = _.get(emphasize
.highlight(file_ext, code), "value", "")
} catch (e) {
log.warn(`highlighting failed for ${filepath}:`)
colored = code
}
const colored_lines = lines.map((l) => chalk.gray(l))
console.log(_.zip(colored_lines, colored.split("\n"))
.map((s : any[]) => s.join("")).join("\n"))
}
}
export function highlight(language: string, value: string): string {
return mark.reset(emphasize.highlight(language, value, sheet).value);
}
function renderPrompt(): void {
const cols = stdout.columns || Infinity
const completion = scroller && menuItems.length > 0 ?
menuItems[scroller.selected === -1 ? 0 : scroller.selected][0] :
''
const lineHighlightTime = time('lineHighlight')
const highlightedLine =
emphasize.highlight('js', rl.line, highlightSheet).value
debug(lineHighlightTime())
const slice = (start: number, end?: number) =>
sliceAnsi(highlightedLine, start, end)
const beforeCursor = (() => {
const sliced = slice(0, rl.cursor)
if (menuItems.length === 0) {
return sliced
}
if (
((scroller && scroller.selected === -1) || !scroller) &&
!stopping
) {
.map((line, idx) => `${padding}${getLineNumber(code_start_line, code_gutter_len, idx)}${emphasize.highlight('js', line).value}`)
.join('\n')
function highlight (error) {
let source = error.source.replace(/\t/g, ' ');
if (chalk.enabled) {
const extname = path.extname(error.fileName).slice(1);
if (extname) {
try {
return emphasize.highlight(extname.slice(1), source).value;
} catch (ex) {
//
}
}
source = emphasize.highlightAuto(source).value;
}
return source;
}