UNPKG

@aritslimited/commitlint

Version:

A commit linting commitizen adapter & branch naming convention tool tailored for ARITS Limited with Jira Issue & Project Tracking Software; to track commits to Jira issues and transition them to the next stage of development workflow automatically.

69 lines (68 loc) 2.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LimitedInputPrompt = void 0; const tslib_1 = require("tslib"); const LimitedInputPrompt = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const InquirerInputPrompt = yield import("inquirer/lib/prompts/input.js").then((m) => m.default); class InputPrompt extends InquirerInputPrompt { constructor(...args) { super(...args); if (!this.opt.maxLength) { this.throwParamError("maxLength"); } this.originalMessage = this.opt.message; this.spacer = new Array(this.opt.maxLength).fill("-").join(""); if (this.opt.leadingLabel) { if (typeof this.opt.leadingLabel === "function") { this.leadingLabel = " " + this.opt.leadingLabel(this.answers); } else { this.leadingLabel = " " + this.opt.leadingLabel; } } else { this.leadingLabel = ""; } this.leadingLength = this.leadingLabel.length; } remainingChar() { return this.opt.maxLength - this.leadingLength - this.rl.line.length; } onKeypress() { if (this.rl.line.length > this.opt.maxLength - this.leadingLength) { this.rl.line = this.rl.line.slice(0, this.opt.maxLength - this.leadingLength); this.rl.cursor--; } this.render(); } getCharsLeftText() { const chars = this.remainingChar(); if (chars > 1) { return `${chars} chars left`; } else { return `${chars} char left`; } } render(error = null) { let bottomContent = ""; let message = this.getQuestion(); let appendContent = ""; const isFinal = this.status === "answered"; if (isFinal) { appendContent = this.answer; } else { appendContent = this.rl.line; } message = `${message} [${this.spacer}] ${this.getCharsLeftText()} ${this.leadingLabel} ${appendContent}`; if (error) { bottomContent = ">> " + error; } this.screen.render(message, bottomContent); } } return InputPrompt; }); exports.LimitedInputPrompt = LimitedInputPrompt;