-
Notifications
You must be signed in to change notification settings - Fork 93
feat(cli): improve interactive prompt UI with @clack/prompts #1370
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
9f22efe
79c795c
78d1288
99b3141
e1461e6
bc5d1e2
a06c7e8
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 |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| import type * as child_process from 'child_process'; | ||
| import * as fs from 'fs'; | ||
| import * as os from 'os'; | ||
| import * as path from 'path'; | ||
| import type { TestContext } from './integ-test'; | ||
| import { Process } from './process'; | ||
|
|
@@ -69,7 +68,10 @@ export async function shell(command: string[], options: ShellOptions = {}): Prom | |
| // now write the input with a slight delay to ensure | ||
| // the child process has already started reading. | ||
| const sendInput = () => { | ||
| child.writeStdin(interaction.input + (interaction.end ?? os.EOL)); | ||
| // Use \r (carriage return) as default line ending — this is what real terminals | ||
| // send when Enter is pressed. Some prompt libraries (e.g. @clack/core) only | ||
| // recognize \r as the submit key, not \n. | ||
| child.writeStdin(interaction.input + (interaction.end ?? '\r')); | ||
| }; | ||
|
|
||
| if (interaction.beforeInput) { | ||
|
|
@@ -340,7 +342,11 @@ class LastLine { | |
| private lastLine: string = ''; | ||
|
|
||
| public append(chunk: string): void { | ||
| const lines = chunk.split(os.EOL); | ||
| // Strip ANSI escape codes so prompt matching works regardless of terminal styling | ||
| const clean = chunk.replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, ''); | ||
|
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. Extracting this to a function might be nice, then we don't need the comment anymore. |
||
| // Split on \r, \n, or \r\n — interactive prompt libraries like @clack/prompts | ||
| // use \r and cursor movement instead of plain \n for re-rendering | ||
|
Comment on lines
+347
to
+348
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. I believe that they expect only |
||
| const lines = clean.split(/\r?\n|\r/); | ||
| if (lines.length === 1) { | ||
| // chunk doesn't contain a new line so just append | ||
| this.lastLine += lines[0]; | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
If this is true, then how does it work for production code? All our code is CJS, so how do we load an ESM module then? It's only in recent Node versions that CJS can finally directly
require()ESM, and I didn't see anawait import()?