1
0
mirror of https://github.com/actions/labeler synced 2026-05-12 01:31:10 +02:00
This commit is contained in:
David Kale
2020-09-08 13:25:36 -04:00
parent e4246d2b5b
commit 91fcbb0108
4227 changed files with 416837 additions and 457884 deletions

View File

@@ -1,7 +1,7 @@
const color = require('kleur');
const Prompt = require('./prompt');
const { cursor, erase } = require('sisteransi');
const { style, clear, figures, strip } = require('../util');
const { style, figures, clear, lines } = require('../util');
const isNumber = /[0-9]/;
const isDef = any => any !== undefined;
@@ -119,6 +119,9 @@ class NumberPrompt extends Prompt {
up() {
this.typed = ``;
if(this.value === '') {
this.value = this.min - this.inc;
}
if (this.value >= this.max) return this.bell();
this.value += this.inc;
this.color = `cyan`;
@@ -128,6 +131,9 @@ class NumberPrompt extends Prompt {
down() {
this.typed = ``;
if(this.value === '') {
this.value = this.min + this.inc;
}
if (this.value <= this.min) return this.bell();
this.value -= this.inc;
this.color = `cyan`;
@@ -139,6 +145,9 @@ class NumberPrompt extends Prompt {
let val = this.value.toString();
if (val.length === 0) return this.bell();
this.value = this.parse((val = val.slice(0, -1))) || ``;
if (this.value !== '' && this.value < this.min) {
this.value = this.min;
}
this.color = `cyan`;
this.fire();
this.render();
@@ -170,32 +179,30 @@ class NumberPrompt extends Prompt {
render() {
if (this.closed) return;
super.render();
let clear = erase.line + (this.lines ? erase.down(this.lines) : ``) + cursor.to(0);
this.lines = 0;
let error = ``;
if (this.error) {
let lines = this.errorMsg.split(`\n`);
error += lines.reduce((a, l, i) => a + `\n${i ? ` ` : figures.pointerSmall} ${color.red().italic(l)}`, ``);
this.lines = lines.length;
if (!this.firstRender) {
if (this.outputError)
this.out.write(cursor.down(lines(this.outputError) - 1) + clear(this.outputError));
this.out.write(clear(this.outputText));
}
super.render();
this.outputError = '';
let underline = !this.done || (!this.done && !this.placeholder);
let prompt = [
// Print prompt
this.outputText = [
style.symbol(this.done, this.aborted),
color.bold(this.msg),
style.delimiter(this.done),
underline ? color[this.color]().underline(this.rendered) : this.rendered
!this.done || (!this.done && !this.placeholder)
? color[this.color]().underline(this.rendered) : this.rendered
].join(` `);
let position = ``;
if (this.lines) {
position += cursor.up(this.lines);
position += cursor.left+cursor.to(strip(prompt).length);
// Print error
if (this.error) {
this.outputError += this.errorMsg.split(`\n`)
.reduce((a, l, i) => a + `\n${i ? ` ` : figures.pointerSmall} ${color.red().italic(l)}`, ``);
}
this.out.write(clear+prompt+error+position);
this.out.write(erase.line + cursor.to(0) + this.outputText + cursor.save + this.outputError + cursor.restore);
}
}