Struct Repl

Source
pub struct Repl<L: LangInterface = DefaultLangInterface> { /* private fields */ }
Expand description

Repl interacts with the terminal to provide easy interactive shells.

Configuration:

  • leader What to print as the prompt:

    > <some-code>
    ^^- leader
  • continued_leader If the command is more than one line long, what to print on subsequent lines

    > <some-code>
    . <some-code>
  • path Path to a file to use as persistent history. If given, on construction, the history will be populated from the contents of this file, and will automatically write it to the file on being dropped. In case a path is not specified, the history is lost when Repl is dropped.

  • capacity The maximum amount of commands stored in the history. Default capacity is 64. If there are already 64 commands in the history, the oldest one will be forgotten.

  • exit_keyword The keyword to exit the repl, it exits the process, so should not be used if any cleanup is a required before closing repl. See set_exit_keyword

  • clear_keyword Clears the screen. See set_clear_keyword

Implementations§

Source§

impl<L: LangInterface> Repl<L>

Source

pub fn iter(self, color: Color) -> ReplIter<L>

Shorthand to get iterator from self

Source§

impl Repl<DefaultLangInterface>

Source

pub fn newd( leader: &'static str, continued_leader: &'static str, path: Option<PathBuf>, ) -> Self

Create a Repl with default language interface.

Source

pub fn with_capacityd( leader: &'static str, continued_leader: &'static str, capacity: usize, path: Option<PathBuf>, ) -> Self

Create a Repl with default language interface, and specified history capacity.

Source§

impl<L: LangInterface> Repl<L>

Source

pub fn new( leader: &'static str, continued_leader: &'static str, path: Option<PathBuf>, ) -> Self

Create a Repl with specified language interface.

Source

pub fn with_capacity( leader: &'static str, continued_leader: &'static str, capacity: usize, path: Option<PathBuf>, ) -> Self

Create a Repl with specified language interface, and specified history capacity.

Source

pub fn set_exit_keyword(&mut self, exit_keyword: &'static str)

Sets the exit keyword. If you don’t want any exit keyword, set it to an empty string

Source

pub fn set_clear_keyword(&mut self, clear_keyword: &'static str)

Sets the clear keyword. If you don’t want any clear keyword, set it to an empty string

Source

pub fn next(&mut self, colour: Color) -> Result<String>

The main function, gives the next command

Trait Implementations§

Source§

impl<L: LangInterface> Drop for Repl<L>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<L = DefaultLangInterface> !Freeze for Repl<L>

§

impl<L = DefaultLangInterface> !RefUnwindSafe for Repl<L>

§

impl<L> Send for Repl<L>
where L: Send,

§

impl<L = DefaultLangInterface> !Sync for Repl<L>

§

impl<L> Unpin for Repl<L>
where L: Unpin,

§

impl<L> UnwindSafe for Repl<L>
where L: UnwindSafe,

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

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.