-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-2.js
51 lines (45 loc) · 1.49 KB
/
example-2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const chalk = require("chalk");
const { Prompt } = require("./dist/index");
const { keyPressAutoComplete } = require("./dist/key-press/autocomplete");
const { keyPressHistory } = require("./dist/key-press/history");
const complete = keyPressAutoComplete(["abc1", "ab12", "abcdefg", "a123"]);
const prompt = new Prompt({ prompt: chalk`{blue default> }` });
const defaultKP = [...prompt.keyPressers];
function newPrompt() {
Object.assign(prompt, { keyPressers: [...defaultKP, keyPressHistory] });
return prompt
.start({
header: "Can have a header",
prompt: "thePrompt> ",
footer: "Can have a footer"
})
.then(command => console.log(`received: "${command}"`))
.then(() =>
prompt.start({
header: "Can have a default",
prompt: "thePrompt> ",
default: "help"
})
)
.then(command => console.log(`received: "${command}"`))
.then(() =>
prompt.start({
header: "Input can be masked",
prompt: "thePrompt> ",
maskInput: true
})
)
.then(command => console.log(`received: "${command}"`))
.then(() => {
Object.assign(prompt, {
keyPressers: [...defaultKP, keyPressHistory, complete]
});
return prompt.start({
header: chalk`Can update footer/prompt/header and do autocomplete {grey (try abcd [tab])}`,
prompt: "thePrompt> "
});
})
.then(command => console.log(`received: "${command}"`))
.then(newPrompt);
}
newPrompt().catch(console.error);