Struct rline::Readline

source ·
pub struct Readline { /* private fields */ }
Expand description

A struct representing a context for reading a line using libreadline.

Implementations§

source§

impl Readline

source

pub fn new() -> Self

Create a new Readline instance.

Panics

Panics on failure to allocate internally used C objects.

source

pub fn feed(&mut self, key: impl AsRef<[u8]>) -> Option<CString>

Feed a key to libreadline.

The provided buffer should comprise not more than a single key, which may be a single byte only or an escape sequence.

Panics

Panics if too many bytes are supplied. libreadline’s internal buffer is said to hold 512 bytes, so any slice of equal or greater size may cause a panic.

source

pub fn reset<S>(&mut self, line: S, cursor: usize, clear_undo: bool)
where S: AsRef<CStr>,

Reset libreadline’s line state to the given line with the given cursor position. If clear_undo is set, the undo list associated with the current line is cleared

Note that this method does not deal with input related modes. For example, libreadline always starts in input mode, but, depending on user configuration, it can be transitioned to vi-movement-mode in which key bindings behave differently (other similar modes exist). When resetting the line using this method the input mode is unaffected. If you truly need to manually force libreadline into input mode, a new Readline will help:

current = Readline::new();
Panics

Panics if the cursor is not less than or equal to the number of characters in the given line.

source

pub fn peek<F, R>(&self, peeker: F) -> R
where F: FnOnce(&CStr, usize) -> R,

Peek at the current line state through a closure.

Trait Implementations§

source§

impl Debug for Readline

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for Readline

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Drop for Readline

source§

fn drop(&mut self)

Executes the destructor for this type. 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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.