ReplInterface

Struct ReplInterface 

Source
pub struct ReplInterface { /* private fields */ }
Expand description

REPL (Read-Eval-Print Loop) interface

Provides an interactive command-line interface with:

  • Line editing and history
  • Persistent command history
  • Graceful error handling
  • Special commands (exit, quit, help)

§Architecture

User input → rustyline → ReplParser → CommandExecutor → Handler
                                            ↓
                                      ExecutionContext

§Special Commands

The REPL recognizes these built-in commands:

  • exit, quit - Exit the REPL
  • help - Show available commands (if registered)

§History

Command history is stored in the user’s config directory:

  • Linux: ~/.config/<app_name>/history.txt
  • macOS: ~/Library/Application Support/<app_name>/history.txt
  • Windows: %APPDATA%\<app_name>\history.txt

Implementations§

Source§

impl ReplInterface

Source

pub fn new( registry: CommandRegistry, context: Box<dyn ExecutionContext>, prompt: String, ) -> Result<Self>

Create a new REPL interface

§Arguments
  • registry - Command registry with all registered commands
  • context - Execution context
  • prompt - Prompt prefix (e.g., “myapp” will display as “myapp > “)
§Errors

Returns an error if rustyline initialization fails (rare).

§Example
use dynamic_cli::interface::ReplInterface;
use dynamic_cli::prelude::*;

let registry = CommandRegistry::new();
let context = Box::new(MyContext::default());

let repl = ReplInterface::new(registry, context, "myapp".to_string())?;
Source

pub fn run(self) -> Result<()>

Run the REPL loop

Enters an interactive loop that:

  1. Displays the prompt
  2. Reads user input
  3. Parses and executes the command
  4. Displays results or errors
  5. Repeats until user exits
§Returns
  • Ok(()) when user exits normally (via exit or quit)
  • Err(_) on critical errors (I/O failures, etc.)
§Example
use dynamic_cli::interface::ReplInterface;
use dynamic_cli::prelude::*;

let registry = CommandRegistry::new();
let context = Box::new(MyContext::default());

let repl = ReplInterface::new(registry, context, "myapp".to_string())?;
repl.run()?; // Starts the REPL loop

Trait Implementations§

Source§

impl Drop for ReplInterface

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

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.