[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.

fix: handle line duplication bug with proper line wrapping

Nate Moore (Mar 5, 2023, 10:21 AM -0600) 58a1df11 68dc69fd

+61 -2
+6
.changeset/good-islands-provide.md
··· 1 + --- 2 + '@clack/core': patch 3 + '@clack/prompts': patch 4 + --- 5 + 6 + Fix line duplication bug by automatically wrapping prompts to `process.stdout.columns`
+3
packages/core/package.json
··· 55 55 "dependencies": { 56 56 "picocolors": "^1.0.0", 57 57 "sisteransi": "^1.0.5" 58 + }, 59 + "devDependencies": { 60 + "wrap-ansi": "^8.1.0" 58 61 } 59 62 }
+6 -2
packages/core/src/prompts/prompt.ts
··· 5 5 import { Readable, Writable } from 'node:stream'; 6 6 import { WriteStream } from 'node:tty'; 7 7 import { cursor, erase } from 'sisteransi'; 8 + import wrap from 'wrap-ansi'; 8 9 9 10 function diffLines(a: string, b: string) { 10 11 if (a === b) return; ··· 104 105 105 106 this.input.on('keypress', this.onKeypress); 106 107 setRawMode(this.input, true); 108 + this.output.on('resize', this.render); 107 109 108 110 this.render(); 109 111 110 112 return new Promise<string | symbol>((resolve, reject) => { 111 113 this.once('submit', () => { 112 114 this.output.write(cursor.show); 115 + this.output.off('resize', this.render); 113 116 setRawMode(this.input, false); 114 117 resolve(this.value); 115 118 }); 116 119 this.once('cancel', () => { 117 120 this.output.write(cursor.show); 121 + this.output.off('resize', this.render); 118 122 setRawMode(this.input, false); 119 123 resolve(cancel); 120 124 }); ··· 203 207 204 208 // TODO: handle wrapping 205 209 private restoreCursor() { 206 - const lines = this._prevFrame.split('\n').length - 1; 210 + const lines = wrap(this._prevFrame, process.stdout.columns).split('\n').length - 1; 207 211 this.output.write(cursor.move(-999, lines * -1)); 208 212 } 209 213 210 214 private _prevFrame = ''; 211 215 private render() { 212 - const frame = this._render(this) ?? ''; 216 + const frame = wrap(this._render(this) ?? '', process.stdout.columns); 213 217 if (frame === this._prevFrame) return; 214 218 215 219 if (this.state === 'initial') {
+46
pnpm-lock.yaml
··· 50 50 specifiers: 51 51 picocolors: ^1.0.0 52 52 sisteransi: ^1.0.5 53 + wrap-ansi: ^8.1.0 53 54 dependencies: 54 55 picocolors: 1.0.0 55 56 sisteransi: 1.0.5 57 + devDependencies: 58 + wrap-ansi: 8.1.0 56 59 57 60 packages/prompts: 58 61 specifiers: ··· 903 906 engines: {node: '>=8'} 904 907 dev: true 905 908 909 + /ansi-regex/6.0.1: 910 + resolution: {integrity: sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==} 911 + engines: {node: '>=12'} 912 + dev: true 913 + 906 914 /ansi-styles/3.2.1: 907 915 resolution: {integrity: sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==} 908 916 engines: {node: '>=4'} ··· 915 923 engines: {node: '>=8'} 916 924 dependencies: 917 925 color-convert: 2.0.1 926 + dev: true 927 + 928 + /ansi-styles/6.2.1: 929 + resolution: {integrity: sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==} 930 + engines: {node: '>=12'} 918 931 dev: true 919 932 920 933 /argparse/1.0.10: ··· 1203 1216 path-type: 4.0.0 1204 1217 dev: true 1205 1218 1219 + /eastasianwidth/0.2.0: 1220 + resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} 1221 + dev: true 1222 + 1206 1223 /editorconfig/0.15.3: 1207 1224 resolution: {integrity: sha512-M9wIMFx96vq0R4F+gRpY3o2exzb8hEj/n9S8unZtHSvYjibBp/iMufSzvmOcV/laG0ZtuTVGtiJggPOSW2r93g==} 1208 1225 hasBin: true ··· 1219 1236 1220 1237 /emoji-regex/8.0.0: 1221 1238 resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} 1239 + dev: true 1240 + 1241 + /emoji-regex/9.2.2: 1242 + resolution: {integrity: sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==} 1222 1243 dev: true 1223 1244 1224 1245 /enquirer/2.3.6: ··· 2506 2527 strip-ansi: 6.0.1 2507 2528 dev: true 2508 2529 2530 + /string-width/5.1.2: 2531 + resolution: {integrity: sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==} 2532 + engines: {node: '>=12'} 2533 + dependencies: 2534 + eastasianwidth: 0.2.0 2535 + emoji-regex: 9.2.2 2536 + strip-ansi: 7.0.1 2537 + dev: true 2538 + 2509 2539 /string.prototype.trimend/1.0.6: 2510 2540 resolution: {integrity: sha512-JySq+4mrPf9EsDBEDYMOb/lM7XQLulwg5R/m1r0PXEFqrV0qHvl58sdTilSXtKOflCsK2E8jxf+GKC0T07RWwQ==} 2511 2541 dependencies: ··· 2527 2557 engines: {node: '>=8'} 2528 2558 dependencies: 2529 2559 ansi-regex: 5.0.1 2560 + dev: true 2561 + 2562 + /strip-ansi/7.0.1: 2563 + resolution: {integrity: sha512-cXNxvT8dFNRVfhVME3JAe98mkXDYN2O1l7jmcwMnOslDeESg1rF/OZMtK0nRAhiari1unG5cD4jG3rapUAkLbw==} 2564 + engines: {node: '>=12'} 2565 + dependencies: 2566 + ansi-regex: 6.0.1 2530 2567 dev: true 2531 2568 2532 2569 /strip-bom/3.0.0: ··· 2802 2839 ansi-styles: 4.3.0 2803 2840 string-width: 4.2.3 2804 2841 strip-ansi: 6.0.1 2842 + dev: true 2843 + 2844 + /wrap-ansi/8.1.0: 2845 + resolution: {integrity: sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==} 2846 + engines: {node: '>=12'} 2847 + dependencies: 2848 + ansi-styles: 6.2.1 2849 + string-width: 5.1.2 2850 + strip-ansi: 7.0.1 2805 2851 dev: true 2806 2852 2807 2853 /wrappy/1.0.2: