Skip to main content

TermRead

Struct TermRead 

Source
pub struct TermRead<'t, 'p, P, T: IoProvider = StdioProvider>
where P: Predicate<Event>,
{ /* private fields */ }
Available on crate features raw and readers only.
Expand description

Terminal reader. Supports only single line. Newlines are skipped.

§Unstable API

API of TermRead will likely change in the future.

Implementations§

Source§

impl<'t, T: IoProvider> TermRead<'t, '_, KeyCode, T>

Source

pub fn lines(term: &'t mut Terminal<T>) -> Self

Gets reader that ends on enter.

Source§

impl<'t, 'p, P, T> TermRead<'t, 'p, P, T>
where P: Predicate<Event>, T: IoProvider,

Source

pub fn new(term: &'t mut Terminal<T>, exit: P) -> Self

Creates new terminal reader that exits with the given predicate.

Source

pub fn from_config( term: &'t mut Terminal<T>, exit: P, conf: ReadConf<'p>, ) -> Self

Create terminal reader from configuration.

Source

pub fn edit_str(&mut self, s: &mut String, pos: Option<usize>) -> Result<()>

Edit the given string.

§Errors
Source

pub fn edit(&mut self, s: impl AsRef<str>, pos: Option<usize>) -> Result<String>

Edit the given string. Return new edited string (the old is unchanged).

§Errors
Source

pub fn edit_vec(&mut self, s: &mut Vec<char>, pos: Option<usize>) -> Result<()>

Edit the given vector. This is the most optimal edit as it doesn’t do any copy of the passed data.

§Errors
Source

pub fn read_to_str(&mut self, s: &mut String) -> Result<()>

Appends readed text to a string.

§Errors
Source

pub fn read_str(&mut self) -> Result<String>

Reads from console and returns the readed string.

§Errors
Source

pub fn finish_to_str(&mut self, s: &mut String) -> Result<()>

Continue reading all data and reset.

§Errors
Source

pub fn finish(&mut self) -> Result<String>

Continue reading all the data and reset.

§Errors
Source

pub fn get_input(&self) -> &[char]

Get the readed characters.

Source

pub fn get_pos(&self) -> usize

Get the position of cursor within the readed characters.

Source

pub fn set_edit(&mut self, s: impl AsRef<str>, pos: Option<usize>)

Set string to edit.

Source

pub fn set_pos(&mut self, pos: Option<usize>)

Set the position within the buffer.

Source

pub fn clear(&mut self)

Reset the buffer.

Source

pub fn reshow(&mut self) -> Result<()>

Refresh the view.

§Errors
Source

pub fn set_prompt(&mut self, prompt: impl Into<TermText<'p>>)

Set the prompt.

Source

pub fn configure(&mut self, conf: ReadConf<'p>)

Reconfigure the reader.

Source

pub fn set_buf(&mut self, buf: Vec<char>, pos: Option<usize>)

Set the read buffer. It is filtered for non control characters.

Source

pub unsafe fn read_one(&mut self) -> Result<bool>

Read one next character or nothing. Doesn’t block. Returns true if the input has ended and the result may be retrieved with TermRead::finish or TermRead::finish_to_str.

§Errors
§Safety

This is unsafe because calls to set_ functions may break the input if this is called.

Source

pub fn is_finished(&self) -> bool

Check if the reading is finished.

Source

pub fn set_end_condition(&mut self, c: P)

Sets the exit condition for the reader.

Source

pub fn splice( &mut self, range: impl RangeBounds<usize>, it: impl IntoIterator<Item = char>, )

Modify the buffer. Control characters are ignored.

Source

pub fn last_event(&self) -> Option<&Event>

Gets the last event.

Source

pub fn queue(&mut self, evt: impl IntoIterator<Item = Event>)

Queue event to the reader.

Auto Trait Implementations§

§

impl<'t, 'p, P, T = StdioProvider> !Freeze for TermRead<'t, 'p, P, T>

§

impl<'t, 'p, P, T = StdioProvider> !RefUnwindSafe for TermRead<'t, 'p, P, T>

§

impl<'t, 'p, P, T = StdioProvider> !Sync for TermRead<'t, 'p, P, T>

§

impl<'t, 'p, P, T = StdioProvider> !UnwindSafe for TermRead<'t, 'p, P, T>

§

impl<'t, 'p, P, T> Send for TermRead<'t, 'p, P, T>
where &'t mut Terminal<T>: Send, P: Send,

§

impl<'t, 'p, P, T> Unpin for TermRead<'t, 'p, P, T>
where &'t mut Terminal<T>: Unpin, P: Unpin,

§

impl<'t, 'p, P, T> UnsafeUnpin for TermRead<'t, 'p, P, T>
where &'t mut Terminal<T>: UnsafeUnpin, P: UnsafeUnpin,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.