Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
render() {
this.clear();
const values = this.selected.map(choice => cyan(choice.message));
const value = this.answered ? values.join(', ') : dim(this.hint);
// ? render the prompt message
let message = this.renderMessage(value);
// - render the list of choices
if (!this.answered) {
message += this.renderChoices();
if (this.choices.length > this.list.length || this.options.footer) {
message += '\n' + gray(this.footer.trim());
}
}
// > write the prompt
this.write(message);
}
prompt.once('run', async() => {
try {
let { state, symbols } = prompt;
let pointer = cyan(symbols.pointer);
let hint = dim('(this is a hint)');
let expected = `${pointer} ${cyan.underline('A')}\n BB ${hint}\n CCC\n DDDD`;
let actual = await prompt.renderChoices();
assert.equal(actual, expected);
await prompt.submit();
} catch (err) {
cb(err);
}
});
'use strict';
const colors = require('ansi-colors');
const { Select } = require('enquirer');
const prompt = new Select({
name: 'separator-example',
message: 'Pick your favorite color',
choices: [
'apple',
'grape',
{ role: 'separator', value: colors.dim('────') },
'watermelon',
'cherry',
'strawberry',
{ role: 'separator', value: colors.dim('────') },
'lemon',
'orange'
]
});
prompt.run()
.then(answer => console.log('Answer:', answer))
.catch(console.error);
function readFiles(dir) {
let files = fs.readdirSync(dir, { withFileTypes: true });
let choices = [];
for (let obj of files) {
if (obj.name === 'support' || obj.name === 'node_modules') continue;
let choice = { name: obj.name, value: path.join(dir, obj.name) };
if (obj.isDirectory()) {
choice.role = 'heading';
choice.name = colors.dim(choice.name + '/');
let res = readFiles(choice.value);
if (res.length) {
choice.choices = res;
choices.push(choice);
}
} else if (choice.name.endsWith('.md')) {
let buf = fs.readFileSync(choice.value);
let file = { ...obj };
file.contents = buf;
file.comment = tokenize(buf.toString(), { stripStars: false });
file.comment.examples = file.comment.examples
.filter(e => hasPrompt(e.value))
.filter(e => /^(\*\*|
constructor(options = {}) {
super(options);
this.hint = options.hint || '';
this.footer = dim('(Scroll up and down to reveal more choice)');
this.queue = [].concat(this.options.choices || []);
this.choices = [];
this.cursor = 0;
this.spin = value => {
return spin(this.output, value, ' ' + value).then(() => value);
};
}
continue;
}
if (token.type === 'template') {
let choice = choices.find(ch => ch.name === key);
let val = [choice.input, state.values[choice.value], choice.value, value].find(v => !!v);
if (state.answered) {
let result = format(state.values[key], choice, state);
state.output += colors.unstyle(result);
continue;
}
if (val !== value) {
state.values[key] = val;
value = colors.dim(val);
} else {
state.values[key] = '';
val = `<${token.inner}>`;
if (state.missing.has(key) || state.invalid.has(key)) {
value = colors.red(val);
} else {
value = colors.cyan(val);
}
}
if (index === state.index) {
value = colors.underline(value);
}
dim(msg: string) {
return color.dim(msg);
}
}
let filePath = diagnostic.relFilePath;
if (typeof filePath !== 'string') {
filePath = diagnostic.absFilePath;
}
if (typeof filePath === 'string') {
if (header.length > 0) {
header += ': ';
}
header += color.cyan(filePath);
if (typeof diagnostic.lineNumber === 'number' && diagnostic.lineNumber > -1) {
header += color.dim(`:`);
header += color.yellow(`${diagnostic.lineNumber}`);
if (typeof diagnostic.columnNumber === 'number' && diagnostic.columnNumber > -1) {
header += color.dim(`:`);
header += color.yellow(`${diagnostic.columnNumber}`);
}
}
}
if (header.length > 0) {
outputLines.unshift(INDENT + header);
}
outputLines.push('');
if (diagnostic.lines && diagnostic.lines.length) {
dim(msg: string) {
return color.dim(msg);
}
function displayOrgItem(org: Org) {
const owner = org.members.find(m => m.role === OrgRole.Owner);
const sub = org.billing && org.billing.subscription;
const planName = sub ? sub.plan.name : "none";
const planType = sub ? sub.plan.type : undefined;
return [
colors.bold(col(org.name, 20)),
col((owner && owner.email) || "N/A", 25),
col(format(org.created, "yyyy-MM-dd"), 12),
col(org.members.length, 7),
col(org.groups.length, 7),
col(org.vaults.length, 7),
colors.bold[planColor(planType)](col(planName, 15)),
colors.bold[subColor(sub)](col(subLabel(sub), 20)),
colors.dim(org.id),
org.frozen ? colors.red.bold("frozen") : ""
].join(" ");
}