-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dup and close file descriptors (#5341)
* track one shot fds * dup fd * skip for rearm on mac * dup if fd * cleanup * force unregister on close * deinitForceUnregister * test * add prompts --------- Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
- Loading branch information
1 parent
f84fbd6
commit d26adde
Showing
6 changed files
with
95 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import prompt from "prompts"; | ||
|
||
const questions = [ | ||
{ | ||
type: "text", | ||
name: "twitter", | ||
message: `What's your twitter handle?`, | ||
format: v => `@${v}`, | ||
}, | ||
{ | ||
type: "number", | ||
name: "age", | ||
message: "How old are you?", | ||
validate: value => (value < 18 ? `Sorry, you have to be 18` : true), | ||
}, | ||
{ | ||
type: "password", | ||
name: "secret", | ||
message: "Tell me a secret", | ||
}, | ||
]; | ||
|
||
const answers = await prompt(questions); | ||
|
||
console.log(answers); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import path from "path"; | ||
import { bunExe, bunEnv } from "harness"; | ||
|
||
test("works with prompts", async () => { | ||
var child = Bun.spawn({ | ||
cmd: [bunExe(), path.join(import.meta.dir, "prompts.js")], | ||
env: bunEnv, | ||
stdout: "pipe", | ||
stdin: "pipe", | ||
}); | ||
|
||
child.stdin.write("dylan\n"); | ||
Bun.sleepSync(100); | ||
child.stdin.write("999\n"); | ||
Bun.sleepSync(100); | ||
child.stdin.write("hi\n"); | ||
|
||
var out = ""; | ||
for await (const chunk of child.stdout) { | ||
out += new TextDecoder().decode(chunk); | ||
} | ||
|
||
expect(await child.exited).toBe(0); | ||
|
||
expect(out).toContain('twitter: "@dylan"'); | ||
expect(out).toContain("age: 999"); | ||
expect(out).toContain('secret: "hi"'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters