[READ-ONLY] Mirror of https://github.com/bombshell-dev/clack. Effortlessly build beautiful command-line apps bomb.sh/docs/clack/basics/getting-started/
cli command-line command-line-app node prompt prompts
5

Configure Feed

Select the types of activity you want to include in your feed.

Fixes cursor position for TextPrompt (#220)

authored by

Nate Moore and committed by
GitHub
(Dec 27, 2024, 10:00 PM -0600) 8cba8e3f 0ada41e3

+16 -11
+5
.changeset/seven-fireants-cover.md
··· 1 + --- 2 + "@clack/core": patch 3 + --- 4 + 5 + Fixes a rendering bug with cursor positions for `TextPrompt`
+11 -11
packages/core/src/prompts/text.ts
··· 7 7 } 8 8 9 9 export default class TextPrompt extends Prompt { 10 - valueWithCursor = ''; 10 + get valueWithCursor() { 11 + if (this.state === 'submit') { 12 + return this.value; 13 + } 14 + if (this.cursor >= this.value.length) { 15 + return `${this.value}${color.inverse(color.hidden('_'))}`; 16 + } 17 + const s1 = this.value.slice(0, this.cursor); 18 + const [s2, ...s3] = this.value.slice(this.cursor); 19 + return `${s1}${color.inverse(s2)}${s3.join('')}`; 20 + } 11 21 get cursor() { 12 22 return this._cursor; 13 23 } ··· 17 27 this.on('finalize', () => { 18 28 if (!this.value) { 19 29 this.value = opts.defaultValue; 20 - } 21 - this.valueWithCursor = this.value; 22 - }); 23 - this.on('value', () => { 24 - if (this.cursor >= this.value.length) { 25 - this.valueWithCursor = `${this.value}${color.inverse(color.hidden('_'))}`; 26 - } else { 27 - const s1 = this.value.slice(0, this.cursor); 28 - const s2 = this.value.slice(this.cursor); 29 - this.valueWithCursor = `${s1}${color.inverse(s2[0])}${s2.slice(1)}`; 30 30 } 31 31 }); 32 32 }