@@ -11,6 +11,164 @@ Best paired with other libraries in the family:
11
11
* [ console] ( https://github.com/console-rs/console )
12
12
* [ indicatif] ( https://github.com/console-rs/indicatif )
13
13
14
+ ## Usage
15
+
16
+ Add the library to your ` Cargo.toml ` :
17
+
18
+ ``` shell
19
+ cargo add dialoguer
20
+ ```
21
+
22
+ ## Examples
23
+
24
+ ### Confirm
25
+
26
+ Docs: [ dialoguer::Confirm] ( https://docs.rs/dialoguer/latest/dialoguer/struct.Confirm.html )
27
+
28
+ ``` rust
29
+ use dialoguer :: {theme :: ColorfulTheme , Confirm };
30
+
31
+ if Confirm :: with_theme (& ColorfulTheme :: default ())
32
+ . with_prompt (" Do you want to continue?" )
33
+ . interact ()?
34
+ {
35
+ println! (" Looks like you want to continue" );
36
+ }
37
+ ```
38
+
39
+ ![ confirm] ( https://vhs.charm.sh/vhs-5ianSRV6gBIQw8zHbXZs7X.gif )
40
+
41
+ With a default value:
42
+
43
+ ``` rust
44
+ use dialoguer :: {theme :: ColorfulTheme , Confirm };
45
+
46
+ if Confirm :: new ()
47
+ . with_prompt (" Do you want to continue?" )
48
+ . default (true )
49
+ . interact ()?
50
+ {
51
+ println! (" Looks like you want to continue" );
52
+ }
53
+ ```
54
+
55
+ ![ confirm-with-default] ( https://vhs.charm.sh/vhs-KumYDsqM2KSxaMUHRr8IV.gif )
56
+
57
+ ## Input
58
+
59
+ Docs: [ dialoguer::Input] ( https://docs.rs/dialoguer/latest/dialoguer/struct.Input.html )
60
+
61
+ ``` rust
62
+ use dialoguer :: {theme :: ColorfulTheme , Input };
63
+
64
+ let name : String = dialoguer :: Input :: with_theme (& ColorfulTheme :: default ())
65
+ . with_prompt (" What is your name?" )
66
+ . interact ()? ;
67
+ println! (" Hello, {name}" );
68
+ ```
69
+
70
+ ![ input] ( https://vhs.charm.sh/vhs-7EYUy5VCybcotdxrL8QCXk.gif )
71
+
72
+ ## Password
73
+
74
+ Docs: [ dialoguer::Password] ( https://docs.rs/dialoguer/latest/dialoguer/struct.Password.html )
75
+
76
+ ``` rust
77
+ use dialoguer :: {theme :: ColorfulTheme , Password };
78
+
79
+ let password : String = Password :: with_theme (& ColorfulTheme :: default ())
80
+ . with_prompt (" Enter your password" )
81
+ . interact ()? ;
82
+ println! (" Your password is: {password}" );
83
+ ```
84
+
85
+ ![ password] ( https://vhs.charm.sh/vhs-1HTgKYmFc09dNtuHu5hWOO.gif )
86
+
87
+ ## Editor
88
+
89
+ Docs: [ dialoguer::Editor] ( https://docs.rs/dialoguer/latest/dialoguer/struct.Editor.html )
90
+
91
+ ``` rust
92
+ use dialoguer :: Editor ;
93
+
94
+ match dialoguer :: Editor :: new (). edit (" Some content" )? {
95
+ Some (content ) => println! (" Content: {content:?}" ),
96
+ None => println! (" File was not saved" ),
97
+ }
98
+ ```
99
+
100
+ ![ editor] ( https://vhs.charm.sh/vhs-3DISbkWUNwMms076djOQ3e.gif )
101
+
102
+ ## Select
103
+
104
+ Docs: [ dialoguer::Select] ( https://docs.rs/dialoguer/latest/dialoguer/struct.Select.html )
105
+
106
+ ``` rust
107
+ use dialoguer :: {theme :: ColorfulTheme , Select };
108
+
109
+ let items = vec! [" Apple" , " Banana" , " Cherry" ];
110
+ let selection = Select :: with_theme (& ColorfulTheme :: default ())
111
+ . with_prompt (" What is your favourite fruit?" )
112
+ . items (& items )
113
+ . interact ()? ;
114
+ println! (" You picked: {selection}" , selection = items [selection ]);
115
+ ```
116
+
117
+ ![ select] ( https://vhs.charm.sh/vhs-3ylAvmWOIiBkYexnG7j4F9.gif )
118
+
119
+ ## FuzzySelect
120
+
121
+ Docs: [ dialoguer::FuzzySelect] ( https://docs.rs/dialoguer/latest/dialoguer/struct.FuzzySelect.html )
122
+
123
+ ``` rust
124
+ use dialoguer :: {theme :: ColorfulTheme , FuzzySelect };
125
+
126
+ let items = vec! [" Apple" , " Banana" , " Cherry" ];
127
+ let selection = FuzzySelect :: with_theme (& ColorfulTheme :: default ())
128
+ . with_prompt (" What is your favourite fruit?" )
129
+ . items (& items )
130
+ . interact ()? ;
131
+ println! (" You picked: {selection}" , selection = items [selection ]);
132
+ ```
133
+
134
+ ![ fuzzy-select] ( https://vhs.charm.sh/vhs-3JUdbUNwnUKWVjk6J5XoKh.gif )
135
+
136
+ ## MultiSelect
137
+
138
+ Docs: [ dialoguer::MultiSelect] ( https://docs.rs/dialoguer/latest/dialoguer/struct.MultiSelect.html )
139
+
140
+ ``` rust
141
+ use dialoguer :: {theme :: ColorfulTheme , MultiSelect };
142
+
143
+ let items = vec! [" Apple" , " Banana" , " Cherry" ];
144
+ let selection = MultiSelect :: with_theme (& ColorfulTheme :: default ())
145
+ . with_prompt (" What are your favourite fruits?" )
146
+ . items (& items )
147
+ . interact ()? ;
148
+ let selected_items : Vec <_ > = selection . iter (). map (| i | items [* i ]). collect ();
149
+ println! (" You picked: {selected_items:?}" );
150
+ ```
151
+
152
+ ![ multi-select] ( https://vhs.charm.sh/vhs-5Jje1Pdxsw4w5jLJjeWNbI.gif )
153
+
154
+ ## Sort
155
+
156
+ Docs: [ dialoguer::Sort] ( https://docs.rs/dialoguer/latest/dialoguer/struct.Sort.html )
157
+
158
+ ``` rust
159
+ use dialoguer :: {theme :: ColorfulTheme , Sort };
160
+
161
+ let items = vec! [" Apple" , " Banana" , " Cherry" ];
162
+ let selection = Sort :: with_theme (& ColorfulTheme :: default ())
163
+ . with_prompt (" Sort the fruits" )
164
+ . items (& items )
165
+ . interact ()? ;
166
+ let sorted_items : Vec <_ > = selection . iter (). map (| i | items [* i ]). collect ();
167
+ println! (" You sorted: {sorted_items:?}" );
168
+ ```
169
+
170
+ ![ sort] ( https://vhs.charm.sh/vhs-mcxq0aABXECgIdafLBNZN.gif )
171
+
14
172
## License and Links
15
173
16
174
* [ Documentation] ( https://docs.rs/dialoguer/ )
0 commit comments