-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathClackPrompts.res
More file actions
70 lines (53 loc) · 1.78 KB
/
ClackPrompts.res
File metadata and controls
70 lines (53 loc) · 1.78 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module Spinner = {
type t
@send
external start: (t, string) => unit = "start"
@send
external stop: (t, string) => unit = "stop"
}
module Log = {
@module("@clack/prompts") @scope("log") external message: string => unit = "message"
@module("@clack/prompts") @scope("log") external info: string => unit = "info"
@module("@clack/prompts") @scope("log") external error: string => unit = "error"
}
type promptResult<'a>
@module("@clack/prompts") external isCancel: promptResult<'a> => bool = "isCancel"
external unsafeGetResultValue: promptResult<'a> => 'a = "%identity"
@module("@clack/prompts") external intro: string => unit = "intro"
@module("@clack/prompts") external outro: string => unit = "outro"
@module("@clack/prompts") external cancel: string => unit = "cancel"
@module("@clack/prompts") external note: (~message: string, ~title: string) => unit = "note"
type confirmOptions = {message: string}
@module("@clack/prompts")
external confirm: confirmOptions => promise<promptResult<bool>> = "confirm"
type selectOption = {
value: string,
label?: string,
hint?: string,
}
type selectOptions = {
message: string,
options: array<selectOption>,
initialValue?: string,
}
@module("@clack/prompts")
external select: selectOptions => promise<promptResult<string>> = "select"
type textOptions = {
message: string,
placeholder?: string,
defaultValue?: string,
initialValue?: string,
validate?: string => option<string>,
}
@module("@clack/prompts")
external text: textOptions => promise<promptResult<string>> = "text"
@module("@clack/prompts") external spinner: unit => Spinner.t = "spinner"
exception Canceled
let resultOrRaise = async promise => {
let result = await promise
if result->isCancel {
throw(Canceled)
} else {
result->unsafeGetResultValue
}
}