Autocompleter

Struct Autocompleter 

Source
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

Source

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;
Source

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 commands
Source

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 against
  • state - 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;
}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.