Completion

Struct Completion 

Source
pub struct Completion {
    pub words: Vec<String>,
    pub word_index: usize,
    pub line: String,
    pub cursor_index: usize,
    pub completion_type: CompletionType,
    pub key: char,
}
Expand description

A completion request. ref.

Fields§

§words: Vec<String>

An array of all the words in the command line, including the command itself. Corresponds to COMP_WORDS.

§word_index: usize

The index of the word in words that is currently being completed. Corresponds to COMP_CWORD.

§line: String

The current command line. Corresponds to COMP_LINE.

§cursor_index: usize

The index of the current cursor position relative to the beginning of the current command. Corresponds to COMP_POINT.

§completion_type: CompletionType

The type of completion attempted. Corresponds to COMP_TYPE.

§key: char

The key (or final key of a key sequence) used to invoke the current completion function. Corresponds to COMP_KEY.

Implementations§

Source§

impl Completion

Source

pub fn init() -> Result<Option<Self>, CompletersError>

Construct a Completion object from command line arguments and envs. If COMPLETE environment variable:

  • Is not set, or set to 0 or empty, return None.
  • Is set to 1, return a Completion object.
  • Is set to bash/nu/nushell, generate shell code and exit successfully.
§Errors

If COMPLETE is set to any other value, return CompletersError::UnrecognizedEnvVar; If generate fails, return ShellCodeError.

Source

pub fn from_args(args: Vec<String>) -> Result<Self, CompletersError>

Constructs a Completion object from the arguments, without the first argument (the program name).

§Errors

Errors if provided args could not be parsed successfully.

Source

pub fn complete<I>(candidates: I)
where I: IntoIterator, I::Item: Display,

Process the completion request and exit successfully.

Source

pub fn delegate(self)

Delegate to the completion request and exit successfully.

Source

pub fn empty()

Answer the completion request with no candidates.

Source

pub fn generate_bash() -> Result<String, ShellCodeError>

Generate Bash completion code.

§Errors

If the program name cannot be determined or is not a valid identifier in Bash, return ShellCodeError::Encoding. If IO error occurs, return ShellCodeError::IO.

Source

pub fn generate_nu() -> Result<String, ShellCodeError>

Generate Nushell completion code.

§Errors

Errors if failed to resolve name and path of current executable.

Trait Implementations§

Source§

impl Clone for Completion

Source§

fn clone(&self) -> Completion

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Completion

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.