UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

70 lines 2.6 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const chalk_1 = __importDefault(require("chalk")); const terminal_kit_1 = __importDefault(require("terminal-kit")); const widget_utilities_1 = __importDefault(require("../widget.utilities")); const termKit_utility_1 = __importDefault(require("./termKit.utility")); const TkBaseWidget_1 = __importDefault(require("./TkBaseWidget")); const termKit = terminal_kit_1.default; class TkInputWidget extends TkBaseWidget_1.default { type = 'input'; input; constructor(options) { super(options); const frame = termKit_utility_1.default.buildFrame(options, options.parent); const { parent, ...rest } = options; this.input = new termKit.InlineInput({ parent: parent ? parent.getTermKitElement() : undefined, textAttr: { bgColor: 'black', color: 'yellow' }, voidAttr: { bgColor: 'black', color: 'yellow' }, placeholder: options.placeholder ? chalk_1.default.italic.black(options.placeholder) : undefined, placeholderHasMarkup: true, prompt: { content: options.label ? `${options.label} > ` : undefined, contentHasMarkup: true, }, cancelable: true, ...rest, ...frame, }); this.input.__widget = this; this.input.on('submit', this.handleSubmit.bind(this)); this.input.on('cancel', this.handleCancel.bind(this)); this.calculateSizeLockDeltas(); } setFrame(frame) { const oldFrame = this.getFrame(); const newFrame = widget_utilities_1.default.buildFrame(frame, this.parent); this.input.setSizeAndPosition({ x: newFrame.left ?? oldFrame.left, y: newFrame.top ?? oldFrame.top, width: newFrame.width ?? oldFrame.width, height: newFrame.height ?? oldFrame.height, }); this.input.draw(); } async handleCancel() { await this.emit('cancel'); } async handleSubmit() { await this.emit('submit', { value: this.getValue(), }); } getValue() { return this.input.getValue(); } setValue(value) { this.input.setContent(value); } getTermKitElement() { return this.input; } } exports.default = TkInputWidget; //# sourceMappingURL=TkInputWidget.js.map