use crate::{KeywordStyle, repl::prompt::CleanPrompt};
use reedline::Prompt;
use std::sync::Arc;
pub struct ReplConfig {
title: String,
prompt: Option<Arc<dyn Prompt>>,
kw_style: Option<KeywordStyle>,
}
impl Default for ReplConfig {
fn default() -> Self {
Self {
title: "Rusty REPL".into(),
prompt: Some(Arc::new(CleanPrompt::default())),
kw_style: None,
}
}
}
impl ReplConfig {
pub fn new(title: impl Into<String>) -> Self {
Self {
title: title.into(),
prompt: None,
kw_style: None,
}
}
pub fn with_prompt<P: Prompt + 'static>(mut self, prompt: P) -> Self {
self.prompt = Some(Arc::new(prompt));
self
}
pub fn with_kw_style(mut self, kw_style: KeywordStyle) -> Self {
self.kw_style = Some(kw_style);
self
}
pub fn title(&self) -> &str {
&self.title
}
pub fn prompt(&self) -> Option<Arc<dyn Prompt>> {
self.prompt.clone()
}
pub fn kw_style(&self) -> Option<&KeywordStyle> {
self.kw_style.as_ref()
}
}