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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
//! Provides completion methods for [`prompt`] when reading lines.
//!
//! By default, no completions are performed upon user interaction. However, if a [`Completer`]
//! or a [`Suggester`] are provided, the [`prompt`] will query for completions for the current
//! state of the line.
//!
//! This module also includes a convenience wrapper for lists, allowing quick implementation
//! of completions.
//!
//! # Examples
//!
//! Basic implementation for in-line completion:
//!
//! ```no_run
//! use rucline::Buffer;
//! use rucline::completion::Completer;
//! use std::borrow::Cow;
//!
//! struct Basic(Vec<String>);
//! impl Completer for Basic {
//! fn complete_for(&self, buffer: &Buffer) -> Option<Cow<'_, str>> {
//! if buffer.is_empty() {
//! None
//! } else {
//! self.0
//! .iter()
//! .find(|completion| completion.starts_with(buffer.as_str()))
//! .map(|completion| (&completion[buffer.len()..]).into())
//! }
//! }
//! }
//! ```
//!
//! Basic implementation for drop-down suggestions:
//!
//! ```no_run
//! use rucline::Buffer;
//! use rucline::completion::Suggester;
//! use std::borrow::Cow;
//!
//! struct Basic(Vec<String>);
//! impl Suggester for Basic {
//! fn suggest_for(&self, buffer: &Buffer) -> Vec<Cow<'_, str>> {
//! self.0.iter().map(|suggestion| suggestion.into()).collect()
//! }
//! }
//! ```
//!
//! Basic implementation for drop-down suggestions with list:
//!
//! ```no_run
//! use rucline::completion::Completer;
//!
//! let completions = vec!["abc", "def", "example word", "weird \"˚∆˙\""];
//! let completer: &dyn Completer = &completions;
//! ```
//!
//! # See also
//! * [`Actions`]
//!
//! [`Actions`]: ../actions/index.html
//! [`Completer`]: trait.Completer.html
//! [`Suggester`]: trait.Suggester.html
//! [`prompt`]: ../prompt/index.html
pub use crateBuffer;
/// Completes the buffer in-line.
///
/// Whenever the line is edited, e.g. [`Write`] or [`Delete`], the [`prompt`] will ask the
/// `Completer` for a possible completion to **append** to the current buffer. The implementation
/// may use the [`Buffer`] to decide which completions are applicable.
///
/// When the `Completer` is invoked, the buffer is not actually changed, the completion is
/// only rendered. A [`Complete`] action must be issued to incorporate the completion into
/// the buffer.
///
/// # Example
///
/// Basic implementation:
///
/// ```no_run
/// use rucline::Buffer;
/// use rucline::completion::Completer;
/// use std::borrow::Cow;
///
/// struct Basic(Vec<String>);
/// impl Completer for Basic {
/// fn complete_for(&self, buffer: &Buffer) -> Option<Cow<'_, str>> {
/// if buffer.is_empty() {
/// None
/// } else {
/// self.0
/// .iter()
/// .find(|completion| completion.starts_with(buffer.as_str()))
/// .map(|completion| (&completion[buffer.len()..]).into())
/// }
/// }
/// }
/// ```
///
/// # See also
/// * [`Suggester`]
///
/// [`Buffer`]: ../buffer/struct.Buffer.html
/// [`Complete`]: ../actions/enum.Action.html#variant.Complete
/// [`Delete`]: ../actions/enum.Action.html#variant.Delete
/// [`Suggester`]: trait.Suggester.html
/// [`Write`]: ../actions/enum.Action.html#variant.Write
/// [`prompt`]: ../prompt/index.html
/// Generates a list of possible values for the [`prompt`] buffer, usually associated with the
/// `Tab` key.
///
/// Whenever the [`Suggest`] action is triggered, the [`prompt`] will ask the
/// `Suggester` for a list of values to **replace** to the current buffer.
/// This list is kept by the [`prompt`] for cycling back and forth until it is dropped by
/// either accepting a suggestion or canceling it. The implementation
/// may use the [`Buffer`] to decide which completions are applicable.
///
/// The buffer is not actually changed until the suggestion is accepted by either a [`Write`], a
/// [`Delete`], [`Accept`] or a [`Move`], while a suggestion is selected.
///
/// # See also
/// * [`Completer`]
///
/// [`Accept`]: ../actions/enum.Action.html#variant.Accept
/// [`Buffer`]: ../buffer/struct.Buffer.html
/// [`Completer`]: trait.Completer.html
/// [`Delete`]: ../actions/enum.Action.html#variant.Delete
/// [`Move`]: ../actions/enum.Action.html#variant.Move
/// [`Suggest`]: ../actions/enum.Action.html#variant.Suggest
/// [`Write`]: ../actions/enum.Action.html#variant.Write
/// [`prompt`]: ../prompt/index.html