reedline/hinter/
mod.rs

1mod cwd_aware;
2mod default;
3pub use cwd_aware::CwdAwareHinter;
4pub use default::DefaultHinter;
5
6use unicode_segmentation::UnicodeSegmentation;
7
8pub fn is_whitespace_str(s: &str) -> bool {
9    s.chars().all(char::is_whitespace)
10}
11
12pub fn get_first_token(string: &str) -> String {
13    let mut reached_content = false;
14    let result = string
15        .split_word_bounds()
16        .take_while(|word| match (is_whitespace_str(word), reached_content) {
17            (_, true) => false,
18            (true, false) => true,
19            (false, false) => {
20                reached_content = true;
21                true
22            }
23        })
24        .collect::<Vec<&str>>()
25        .join("")
26        .to_string();
27    result
28}
29
30use crate::History;
31/// A trait that's responsible for returning the hint for the current line and position
32/// Hints are often shown in-line as part of the buffer, showing the user text they can accept or ignore
33pub trait Hinter: Send {
34    /// Handle the hinting duty by using the line, position, and current history
35    ///
36    /// Returns the formatted output to show the user
37    fn handle(
38        &mut self,
39        line: &str,
40        pos: usize,
41        history: &dyn History,
42        use_ansi_coloring: bool,
43    ) -> String;
44
45    /// Return the current hint unformatted to perform the completion of the full hint
46    fn complete_hint(&self) -> String;
47
48    /// Return the first semantic token of the hint
49    /// for incremental completion
50    fn next_hint_token(&self) -> String;
51}