-
Notifications
You must be signed in to change notification settings - Fork 153
feat: add withBorder option #409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@clack/prompts": patch | ||
| "@clack/core": patch | ||
| --- | ||
|
|
||
| Add a new `withBorder` option to all prompts to disable the default clack border |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "extends": "../../tsconfig.json", | ||
| "include": ["src"] | ||
| "include": ["src", "test"] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,4 +57,5 @@ export interface CommonOptions { | |
| input?: Readable; | ||
| output?: Writable; | ||
| signal?: AbortSignal; | ||
| withBorder?: boolean; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above question re: whether this is the correct naming or if it should be |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,9 @@ export const text = (opts: TextOptions) => { | |
| signal: opts.signal, | ||
| input: opts.input, | ||
| render() { | ||
| const title = `${color.gray(S_BAR)}\n${symbol(this.state)} ${opts.message}\n`; | ||
| const withBorder = opts.withBorder !== false; | ||
| const titlePrefix = withBorder ? `${color.gray(S_BAR)}\n${symbol(this.state)} ` : ''; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC this means no symbols prefixing prompts when disabling the border? It’s personal preference I guess, but I’d still expect some kind of leading marker even when disabling borders/guides. These markers can be helpful indicators of state. For example, to mirror something a bit like what And then post-confirm These could definitely just be the standard clack symbols by default but the left border/guide seems a distinct UI element from these status indicators to me.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks a little weird without some rework since the symbol shows up where the guide line would usually be, detached from the box I'll have a think |
||
| const title = `${titlePrefix}${opts.message}\n`; | ||
| const placeholder = opts.placeholder | ||
| ? color.inverse(opts.placeholder[0]) + color.dim(opts.placeholder.slice(1)) | ||
| : color.inverse(color.hidden('_')); | ||
|
|
@@ -30,20 +32,26 @@ export const text = (opts: TextOptions) => { | |
| switch (this.state) { | ||
| case 'error': { | ||
| const errorText = this.error ? ` ${color.yellow(this.error)}` : ''; | ||
| return `${title.trim()}\n${color.yellow(S_BAR)} ${userInput}\n${color.yellow( | ||
| S_BAR_END | ||
| )}${errorText}\n`; | ||
| const errorPrefix = withBorder ? `${color.yellow(S_BAR)} ` : ''; | ||
| const errorPrefixEnd = withBorder ? color.yellow(S_BAR_END) : ''; | ||
| return `${title.trim()}\n${errorPrefix}${userInput}\n${errorPrefixEnd}${errorText}\n`; | ||
| } | ||
| case 'submit': { | ||
| const valueText = value ? ` ${color.dim(value)}` : ''; | ||
| return `${title}${color.gray(S_BAR)}${valueText}`; | ||
| const submitPrefix = withBorder ? color.gray(S_BAR) : ''; | ||
| return `${title}${submitPrefix}${valueText}`; | ||
| } | ||
| case 'cancel': { | ||
| const valueText = value ? ` ${color.strikethrough(color.dim(value))}` : ''; | ||
| return `${title}${color.gray(S_BAR)}${valueText}${value.trim() ? `\n${color.gray(S_BAR)}` : ''}`; | ||
| const cancelPrefix = withBorder ? color.gray(S_BAR) : ''; | ||
| return `${title}${cancelPrefix}${valueText}${value.trim() ? `\n${cancelPrefix}` : ''}`; | ||
| } | ||
| default: { | ||
| const defaultPrefix = withBorder ? `${color.cyan(S_BAR)} ` : ''; | ||
| const defaultPrefixEnd = withBorder ? color.cyan(S_BAR_END) : ''; | ||
| color.cyan(S_BAR_END); | ||
| return `${title}${defaultPrefix}${userInput}\n${defaultPrefixEnd}\n`; | ||
| } | ||
| default: | ||
| return `${title}${color.cyan(S_BAR)} ${userInput}\n${color.cyan(S_BAR_END)}\n`; | ||
| } | ||
| }, | ||
| }).prompt() as Promise<string | symbol>; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this means boxes would render without a left border? i.e. something like
I’m not sure, but this one feels like even when rendering without a left border, you’d still want boxes to render with the four sides intact. At least if this is a generic option set at a global level. (And if a local thing like
box('example', null, { withBorder: false }), then I’d expect no border at all, not only the left border to be missing.Maybe there’s an argument that what we’re describing as a “border” is not really a border in the generic rendering sense. It has a UI function in connecting prompts, guiding the eye from step to step, etc. So something like
withGuidecould be a more appropriate naming? And then that would make it more obvious that a box would not be impacted (but might have other styling hooks given it genuinely is a bordered element).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a fair point
This is configuring the "guide" , the box would still have a left border (as part of the box).
withGuidemight work 🤔 but yeah that's basically what I'm trying to make configurable here - the left "guide line" 😅