mirror of
https://github.com/actions/labeler
synced 2026-05-10 10:31:02 +02:00
build
This commit is contained in:
59
node_modules/prompts/dist/elements/select.js
generated
vendored
59
node_modules/prompts/dist/elements/select.js
generated
vendored
@@ -7,10 +7,11 @@ const Prompt = require('./prompt');
|
||||
const _require = require('../util'),
|
||||
style = _require.style,
|
||||
clear = _require.clear,
|
||||
figures = _require.figures;
|
||||
figures = _require.figures,
|
||||
wrap = _require.wrap,
|
||||
entriesToDisplay = _require.entriesToDisplay;
|
||||
|
||||
const _require2 = require('sisteransi'),
|
||||
erase = _require2.erase,
|
||||
cursor = _require2.cursor;
|
||||
/**
|
||||
* SelectPrompt Base Element
|
||||
@@ -21,6 +22,7 @@ const _require2 = require('sisteransi'),
|
||||
* @param {Number} [opts.initial] Index of default value
|
||||
* @param {Stream} [opts.stdin] The Readable stream to listen to
|
||||
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
|
||||
* @param {Number} [opts.optionsPerPage=10] Max options to display at once
|
||||
*/
|
||||
|
||||
|
||||
@@ -38,11 +40,13 @@ class SelectPrompt extends Prompt {
|
||||
};
|
||||
return {
|
||||
title: ch && (ch.title || ch.value || ch),
|
||||
value: ch && (ch.value || idx),
|
||||
value: ch && (ch.value === undefined ? idx : ch.value),
|
||||
description: ch && ch.description,
|
||||
selected: ch && ch.selected,
|
||||
disabled: ch && ch.disabled
|
||||
};
|
||||
});
|
||||
this.optionsPerPage = opts.optionsPerPage || 10;
|
||||
this.value = (this.choices[this.cursor] || {}).value;
|
||||
this.clear = clear('');
|
||||
this.render();
|
||||
@@ -116,26 +120,57 @@ class SelectPrompt extends Prompt {
|
||||
|
||||
render() {
|
||||
if (this.closed) return;
|
||||
if (this.firstRender) this.out.write(cursor.hide);else this.out.write(erase.lines(this.choices.length + 1));
|
||||
super.render(); // Print prompt
|
||||
if (this.firstRender) this.out.write(cursor.hide);else this.out.write(clear(this.outputText));
|
||||
super.render();
|
||||
|
||||
this.out.write([style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(false), this.done ? this.selection.title : this.selection.disabled ? color.yellow(this.warn) : color.gray(this.hint)].join(' ')); // Print choices
|
||||
let _entriesToDisplay = entriesToDisplay(this.cursor, this.choices.length, this.optionsPerPage),
|
||||
startIndex = _entriesToDisplay.startIndex,
|
||||
endIndex = _entriesToDisplay.endIndex; // Print prompt
|
||||
|
||||
|
||||
this.outputText = [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(false), this.done ? this.selection.title : this.selection.disabled ? color.yellow(this.warn) : color.gray(this.hint)].join(' '); // Print choices
|
||||
|
||||
if (!this.done) {
|
||||
this.out.write('\n' + this.choices.map((v, i) => {
|
||||
let title, prefix;
|
||||
this.outputText += '\n';
|
||||
|
||||
for (let i = startIndex; i < endIndex; i++) {
|
||||
let title,
|
||||
prefix,
|
||||
desc = '',
|
||||
v = this.choices[i]; // Determine whether to display "more choices" indicators
|
||||
|
||||
if (i === startIndex && startIndex > 0) {
|
||||
prefix = figures.arrowUp;
|
||||
} else if (i === endIndex - 1 && endIndex < this.choices.length) {
|
||||
prefix = figures.arrowDown;
|
||||
} else {
|
||||
prefix = ' ';
|
||||
}
|
||||
|
||||
if (v.disabled) {
|
||||
title = this.cursor === i ? color.gray().underline(v.title) : color.strikethrough().gray(v.title);
|
||||
prefix = this.cursor === i ? color.bold().gray(figures.pointer) + ' ' : ' ';
|
||||
prefix = (this.cursor === i ? color.bold().gray(figures.pointer) + ' ' : ' ') + prefix;
|
||||
} else {
|
||||
title = this.cursor === i ? color.cyan().underline(v.title) : v.title;
|
||||
prefix = this.cursor === i ? color.cyan(figures.pointer) + ' ' : ' ';
|
||||
prefix = (this.cursor === i ? color.cyan(figures.pointer) + ' ' : ' ') + prefix;
|
||||
|
||||
if (v.description && this.cursor === i) {
|
||||
desc = ` - ${v.description}`;
|
||||
|
||||
if (prefix.length + title.length + desc.length >= this.out.columns || v.description.split(/\r?\n/).length > 1) {
|
||||
desc = '\n' + wrap(v.description, {
|
||||
margin: 3,
|
||||
width: this.out.columns
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return `${prefix} ${title}`;
|
||||
}).join('\n'));
|
||||
this.outputText += `${prefix} ${title}${color.gray(desc)}\n`;
|
||||
}
|
||||
}
|
||||
|
||||
this.out.write(this.outputText);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user