Skip to content

Commit 99f0b32

Browse files
committed
add clearPromptOnDone for path component
1 parent e1ccb9f commit 99f0b32

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

packages/prompts/src/path.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { existsSync, lstatSync, readdirSync } from 'node:fs';
22
import { dirname, join } from 'node:path';
33
import { autocomplete } from './autocomplete.js';
4-
import type { CommonOptions } from './common.js';
4+
import type { CommonPromptOptions } from './common.js';
55

6-
export interface PathOptions extends CommonOptions {
6+
export interface PathOptions extends CommonPromptOptions {
77
root?: string;
88
directory?: boolean;
99
initialValue?: string;

packages/prompts/test/__snapshots__/path.test.ts.snap

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,27 @@ exports[`text (isCI = false) > cannot submit unknown value 1`] = `
7878
]
7979
`;
8080
81+
exports[`text (isCI = false) > clear prompt after done 1`] = `
82+
[
83+
"<cursor.hide>",
84+
"│
85+
◆ foo
86+
│
87+
│ Search: /tmp/█
88+
│ ● /tmp/bar
89+
│ ○ /tmp/root.zip
90+
│ ↑/↓ to select • Enter: confirm • Type: to search
91+
└",
92+
"<cursor.backward count=999><cursor.up count=7>",
93+
"",
94+
"<erase.down>",
95+
"<cursor.up count=1>",
96+
"
97+
",
98+
"<cursor.show>",
99+
]
100+
`;
101+
81102
exports[`text (isCI = false) > initialValue sets the value 1`] = `
82103
[
83104
"<cursor.hide>",
@@ -379,6 +400,27 @@ exports[`text (isCI = true) > cannot submit unknown value 1`] = `
379400
]
380401
`;
381402
403+
exports[`text (isCI = true) > clear prompt after done 1`] = `
404+
[
405+
"<cursor.hide>",
406+
"│
407+
◆ foo
408+
│
409+
│ Search: /tmp/█
410+
│ ● /tmp/bar
411+
│ ○ /tmp/root.zip
412+
│ ↑/↓ to select • Enter: confirm • Type: to search
413+
└",
414+
"<cursor.backward count=999><cursor.up count=7>",
415+
"",
416+
"<erase.down>",
417+
"<cursor.up count=1>",
418+
"
419+
",
420+
"<cursor.show>",
421+
]
422+
`;
423+
382424
exports[`text (isCI = true) > initialValue sets the value 1`] = `
383425
[
384426
"<cursor.hide>",

packages/prompts/test/path.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,21 @@ describe.each(['true', 'false'])('text (isCI = %s)', (isCI) => {
191191
expect(value).toBe('/tmp/bar');
192192
expect(output.buffer).toMatchSnapshot();
193193
});
194+
195+
test('clear prompt after done', async () => {
196+
const result = prompts.path({
197+
message: 'foo',
198+
input,
199+
output,
200+
root: '/tmp/',
201+
clearPromptOnDone: true,
202+
});
203+
204+
input.emit('keypress', '', { name: 'return' });
205+
206+
const value = await result;
207+
208+
expect(output.buffer).toMatchSnapshot();
209+
expect(value).toBe('/tmp/bar');
210+
});
194211
});

0 commit comments

Comments
 (0)