UNPKG

standard-commit

Version:
46 lines (45 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const enquirer_1 = require("enquirer"); class SuggestPrompt extends enquirer_1.StringPrompt { constructor(options) { super(options); this.suggestionIndex = 0; this.suggest(); } suggest() { this.initial = this.suggestions && this.suggestions[this.suggestionIndex]; this.input = this.initial; this.cursor = this.input.length; this.render(); } suggestNext() { this.suggestionIndex = (this.suggestionIndex + 1) % this.suggestions.length; this.suggest(); } suggestPrev() { this.suggestionIndex = (this.suggestionIndex - 1 + this.suggestions.length) % this.suggestions.length; this.suggest(); } next() { if ((this.cursor = this.input.length)) { this.suggestNext(); } else this.completion(); } completion() { this.input = this.initial; this.cursor = this.input.length; return this.render(); } up() { this.suggestPrev(); } down() { this.suggestNext(); } } exports.default = SuggestPrompt;