rusty_repl 0.3.0

REPL library with customisable prompts and clean terminal management.
Documentation
//! Minimalist prompt adapter for `reedline`.
//!
//! [`CleanPrompt`] provides a streamlined, distraction-free prompt display
//! by wrapping [`reedline::DefaultPrompt`] while suppressing extra visual indicators.
//!
//! This is intended for REPLs or command interfaces that already provide
//! their own context or status indicators and do not need Reedline’s default
//! decorations, such as:
//! - edit-mode markers (e.g., `-- INSERT --`),
//! - multiline input arrows,
//! - history search hints.
//!
//! # Overview
//!
//! `CleanPrompt` keeps the prompt text and color configuration from the inner
//! [`DefaultPrompt`] but removes Reedline’s noisy decorations.
//! It is ideal when you want full control over prompt appearance and a clean input line.
//!
//! # Features
//! - Customizable left and right segments using [`DefaultPromptSegment`].
//! - Suppresses edit-mode, multiline, and history search indicators.
//! - Implements [`Deref`] to allow access to all [`DefaultPrompt`] methods.
//!
//! # Example
//! ```ignore
//! use reedline::{DefaultPrompt, Reedline};
//! use crate::repl::prompt::CleanPrompt; // adjust path as needed
//!
//! let prompt = CleanPrompt::default();
//! let mut line_editor = Reedline::create();
//!
//! // Read a line using the clean prompt
//! let signal = line_editor.read_line(&prompt);
//! ```
//!
//! The resulting prompt behaves like [`DefaultPrompt`] but without mode
//! or continuation indicators, leaving full control of appearance to the application.

use reedline::{DefaultPrompt, DefaultPromptSegment, Prompt, PromptEditMode, PromptHistorySearch};
use std::borrow::Cow;
use std::ops::Deref;

/// A simplified [`Prompt`] implementation that suppresses Reedline's
/// extra visual indicators while keeping your custom prompt text.
///
/// # Notes
/// - Use [`Deref`] to access all methods of the inner [`DefaultPrompt`].
/// - Configure prompt text and colors via the inner [`DefaultPrompt`].
pub struct CleanPrompt(pub DefaultPrompt);

impl Default for CleanPrompt {
    fn default() -> Self {
        Self::from(
            DefaultPromptSegment::Basic("❯❯❯ ".to_string()),
            DefaultPromptSegment::Empty,
        )
    }
}

impl CleanPrompt {
    /// Creates a new `CleanPrompt` from custom left and right prompt segments.
    ///
    /// # Arguments
    /// * `left_prompt` — The left-side prompt segment.
    /// * `right_prompt` — The right-side prompt segment.
    pub fn from(left_prompt: DefaultPromptSegment, right_prompt: DefaultPromptSegment) -> Self {
        let default_prompt = DefaultPrompt::new(left_prompt, right_prompt);

        CleanPrompt(default_prompt)
    }
}

impl Prompt for CleanPrompt {
    fn render_prompt_left(&self) -> Cow<'_, str> {
        self.0.render_prompt_left()
    }

    fn render_prompt_right(&self) -> Cow<'_, str> {
        self.0.render_prompt_right()
    }

    fn render_prompt_indicator(&self, _prompt_mode: PromptEditMode) -> Cow<'_, str> {
        Cow::from("")
    }

    fn render_prompt_multiline_indicator(&self) -> Cow<'_, str> {
        Cow::from("")
    }

    fn render_prompt_history_search_indicator(
        &self,
        _history_search: PromptHistorySearch,
    ) -> Cow<'_, str> {
        Cow::from("")
    }
}

impl Deref for CleanPrompt {
    type Target = DefaultPrompt;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}