pub struct Autocompleter { /* private fields */ }Expand description
Tab completion provider for the interpreter.
Autocompleter maintains a list of valid commands and provides
case-insensitive prefix matching for tab completion.
§Conceptual Role
The autocompleter integrates with readline-style interfaces to provide interactive tab completion. It queries Tor once at initialization to build a comprehensive command list.
§Thread Safety
Autocompleter is Send and Sync after construction, as it only
contains an immutable command list.
§Example
use stem_rs::Controller;
use stem_rs::interpreter::autocomplete::Autocompleter;
let autocompleter = Autocompleter::new(&mut controller).await;
// Case-insensitive matching
let matches = autocompleter.matches("getinfo");
assert!(matches.iter().any(|m| m.starts_with("GETINFO")));Implementations§
Source§impl Autocompleter
impl Autocompleter
Sourcepub async fn new(controller: &mut Controller) -> Self
pub async fn new(controller: &mut Controller) -> Self
Creates a new autocompleter by querying Tor for available commands.
This queries Tor for available options and builds a comprehensive list of completions. If any query fails, fallback completions are used for that category.
§Arguments
controller- An authenticated controller connection
§Example
use stem_rs::Controller;
use stem_rs::interpreter::autocomplete::Autocompleter;
let autocompleter = Autocompleter::new(&mut controller).await;Sourcepub fn matches(&self, text: &str) -> Vec<&str>
pub fn matches(&self, text: &str) -> Vec<&str>
Returns all commands matching the given prefix.
Matching is case-insensitive. The returned strings preserve their original case.
§Arguments
text- The prefix to match against
§Returns
A vector of references to matching commands.
§Example
use stem_rs::Controller;
use stem_rs::interpreter::autocomplete::Autocompleter;
let autocompleter = Autocompleter::new(&mut controller).await;
// Get all interpreter commands
let matches = autocompleter.matches("/");
assert!(matches.contains(&"/help"));
// Case-insensitive matching
let matches = autocompleter.matches("signal");
// Returns SIGNAL commandsSourcepub fn complete(&self, text: &str, state: usize) -> Option<&str>
pub fn complete(&self, text: &str, state: usize) -> Option<&str>
Returns the completion at the given index, for readline integration.
This method is designed to work with readline’s set_completer
function, which calls the completer repeatedly with increasing
state values until None is returned.
§Arguments
text- The prefix to match againststate- The index of the match to return (0-based)
§Returns
The completion at the given index, or None if the index is
out of bounds.
§Example
use stem_rs::Controller;
use stem_rs::interpreter::autocomplete::Autocompleter;
let autocompleter = Autocompleter::new(&mut controller).await;
// Iterate through all matches
let mut state = 0;
while let Some(completion) = autocompleter.complete("/", state) {
println!("{}", completion);
state += 1;
}