MCPcopy Create free account
hub / github.com/bombshell-dev/clack / TextPrompt

Class TextPrompt

packages/core/src/prompts/text.ts:9–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7}
8
9export default class TextPrompt extends Prompt<string> {
10 get userInputWithCursor() {
11 if (this.state === 'submit') {
12 return this.userInput;
13 }
14 const userInput = this.userInput;
15 if (this.cursor >= userInput.length) {
16 return `${this.userInput}█`;
17 }
18 const s1 = userInput.slice(0, this.cursor);
19 const [s2, ...s3] = userInput.slice(this.cursor);
20 return `${s1}${styleText('inverse', s2)}${s3.join('')}`;
21 }
22 get cursor() {
23 return this._cursor;
24 }
25 constructor(opts: TextOptions) {
26 super({
27 ...opts,
28 initialUserInput: opts.initialUserInput ?? opts.initialValue,
29 });
30
31 this.on('userInput', (input) => {
32 this._setValue(input);
33 });
34 this.on('finalize', () => {
35 if (!this.value) {
36 this.value = opts.defaultValue;
37 }
38 if (this.value === undefined) {
39 this.value = '';
40 }
41 });
42 }
43}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected