From 718b9d51792d07f3e26ab21af1e042c9673ec8c9 Mon Sep 17 00:00:00 2001 From: Bruno Rocha Date: Tue, 26 Nov 2024 15:36:03 -0300 Subject: [PATCH] chore: rebase branch --- package.json | 2 +- packages/prompts/src/index.ts | 88 +++++++++++++++++------------------ pnpm-lock.yaml | 67 ++++++++++++-------------- 3 files changed, 72 insertions(+), 85 deletions(-) diff --git a/package.json b/package.json index 7e876711..7e61a166 100644 --- a/package.json +++ b/package.json @@ -30,4 +30,4 @@ "volta": { "node": "20.18.1" } -} \ No newline at end of file +} diff --git a/packages/prompts/src/index.ts b/packages/prompts/src/index.ts index 694e98fb..14f3eb9b 100644 --- a/packages/prompts/src/index.ts +++ b/packages/prompts/src/index.ts @@ -9,8 +9,8 @@ import { SelectKeyPrompt, SelectPrompt, State, - TextPrompt, strLength, + TextPrompt } from '@clack/core'; import isUnicodeSupported from 'is-unicode-supported'; import color from 'picocolors'; @@ -138,7 +138,9 @@ function applyTheme(data: ThemeParams): string { style: (line) => color.strikethrough(color.dim(line)), }, }), - ].join('\n'); + ] + .filter(Boolean) + .join('\n'); case 'error': return [ @@ -311,17 +313,16 @@ export const select = (opts: SelectOptions) => { value = opt(this.options[this.cursor], 'selected'); break; case 'cancel': - return `${title}${color.gray(S_BAR)} ${opt( - this.options[this.cursor], - 'cancelled' - )}\n${color.gray(S_BAR)}`; + value = opt(this.options[this.cursor], 'cancelled'); + break; default: { - return `${title}${color.cyan(S_BAR)} ${limitOptions({ + value = limitOptions({ cursor: this.cursor, options: this.options, maxItems: opts.maxItems, style: (item, active) => opt(item, active ? 'active' : 'inactive'), - }).join(`\n${color.cyan(S_BAR)} `)}\n${color.cyan(S_BAR_END)}\n`; + }).join('\n'); + break; } } return applyTheme({ @@ -362,26 +363,20 @@ export const selectKey = (opts: SelectOptions) => { switch (this.state) { case 'submit': - return `${title}${color.gray(S.BAR)} ${opt( + return `${title}\n${color.gray(S_BAR)} ${opt( this.options.find((opt) => opt.value === this.value)!, 'selected' )}`; case 'cancel': - return `${title}${color.gray(S_BAR)} ${opt(this.options[0], 'cancelled')}\n${color.gray( - S_BAR - )}`; + return `${title}\n${color.gray(S_BAR)} ${opt( + this.options[0], + 'cancelled' + )}\n${color.gray(S_BAR)}`; default: - return `${title}${color.cyan(S_BAR)} ${this.options + return `${title}\n${color.cyan(S_BAR)} ${this.options .map((option, i) => opt(option, i === this.cursor ? 'active' : 'inactive')) .join(`\n${color.cyan(S_BAR)} `)}\n${color.cyan(S_BAR_END)}\n`; } - - return applyTheme({ - ctx: this, - message: opts.message, - value, - valueWithCursor: undefined, - }); }, }).prompt() as Promise; }; @@ -465,34 +460,36 @@ export const multiselect = (opts: MultiSelectOptions) => { .join(color.dim(', ')) ?? ''; } case 'error': { - const footer = this.error - .split('\n') - .map((ln, i) => - i === 0 ? `${color.yellow(S_BAR_END)} ${color.yellow(ln)}` : ` ${ln}` - ) - .join('\n'); - return ( - title + - color.yellow(S_BAR) + - ' ' + - limitOptions({ - options: this.options, - cursor: this.cursor, - maxItems: opts.maxItems, - style: styleOption, - }).join(`\n${color.yellow(S_BAR)} `) + - '\n' + - footer + - '\n' + error = format( + this.error + .split('\n') + .map((ln, i) => (i === 0 ? color.yellow(ln) : ln)) + .join('\n'), + { + firstLine: { + start: color.yellow(S_BAR_END), + }, + default: { + start: color.hidden('-'), + }, + } ); + value = limitOptions({ + cursor: this.cursor, + maxItems: opts.maxItems, + options: this.options, + style: styleOption, + }).join('\n'); + break; } default: { - return `${title}${color.cyan(S_BAR)} ${limitOptions({ - options: this.options, + value = limitOptions({ cursor: this.cursor, maxItems: opts.maxItems, + options: this.options, style: styleOption, - }).join(`\n${color.cyan(S_BAR)} `)}\n${color.cyan(S_BAR_END)}\n`; + }).join('\n'); + break; } } return applyTheme({ @@ -585,7 +582,7 @@ export const groupMultiselect = (opts: GroupMultiSelectOptions) => } }; - let title = `${color.gray(S_BAR)}\n${symbol(this.state)} ${opts.message}\n`; + let title = `${color.gray(S_BAR)}\n${symbol(this.state)} ${opts.message}`; switch (this.state) { case 'submit': { @@ -868,9 +865,8 @@ export const spinner = () => { : code === 1 ? color.red(S_STEP_CANCEL) : color.red(S_STEP_ERROR); - process.stdout.write(cursor.move(-999, 0)); - process.stdout.write(erase.down(1)); - process.stdout.write(`${step} ${_message}\n`); + _message = formatMessage(step, msg || _message); + process.stdout.write(_message + '\n'); clearHooks(); unblock(); }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 383e590b..7293ecb7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,14 +7,6 @@ settings: importers: .: - specifiers: - '@changesets/cli': ^2.26.0 - '@types/node': '18' - merge2: ^1.4.1 - organize-imports-cli: ^0.10.0 - prettier: ^2.8.4 - typescript: ^4.9.5 - unbuild: 1.1.2 devDependencies: '@changesets/cli': specifier: ^2.26.2 @@ -36,36 +28,38 @@ importers: version: 2.0.0(typescript@5.2.2) examples/basic: - specifiers: - '@clack/core': workspace:* - '@clack/prompts': workspace:* - jiti: ^1.17.0 - picocolors: ^1.0.0 - dependencies: - '@clack/core': link:../../packages/core - '@clack/prompts': link:../../packages/prompts - picocolors: 1.0.0 + dependencies: + '@clack/core': + specifier: workspace:* + version: link:../../packages/core + '@clack/prompts': + specifier: workspace:* + version: link:../../packages/prompts + picocolors: + specifier: ^1.0.0 + version: 1.0.0 devDependencies: - jiti: 1.19.3 + jiti: + specifier: ^1.17.0 + version: 1.17.0 examples/changesets: - specifiers: - '@clack/core': workspace:* - '@clack/prompts': workspace:* - jiti: ^1.17.0 - picocolors: ^1.0.0 - dependencies: - '@clack/core': link:../../packages/core - '@clack/prompts': link:../../packages/prompts - picocolors: 1.0.0 + dependencies: + '@clack/core': + specifier: workspace:* + version: link:../../packages/core + '@clack/prompts': + specifier: workspace:* + version: link:../../packages/prompts + picocolors: + specifier: ^1.0.0 + version: 1.0.0 devDependencies: - jiti: 1.19.3 + jiti: + specifier: ^1.17.0 + version: 1.17.0 packages/core: - specifiers: - picocolors: ^1.0.0 - sisteransi: ^1.0.5 - wrap-ansi: ^8.1.0 dependencies: picocolors: specifier: ^1.0.0 @@ -82,11 +76,6 @@ importers: version: 8.1.0 packages/prompts: - specifiers: - '@clack/core': ^0.3.3 - is-unicode-supported: ^1.3.0 - picocolors: ^1.0.0 - sisteransi: ^1.0.5 dependencies: '@clack/core': specifier: workspace:* @@ -98,7 +87,9 @@ importers: specifier: ^1.0.5 version: 1.0.5 devDependencies: - is-unicode-supported: 1.3.0 + is-unicode-supported: + specifier: ^1.3.0 + version: 1.3.0 packages: