use std::borrow::Cow; use std::cell::RefCell; use nu_ansi_term::{Color as AnsiColor, Style}; use reedline::{ Color, PromptEditMode, PromptHistorySearch, PromptHistorySearchStatus, Reedline, StyledText, ValidationResult, }; use tree_sitter_highlight::{Highlight, HighlightConfiguration, HighlightEvent}; pub(super) fn create() -> Reedline { Reedline::create() .with_highlighter(Box::new(Highlighter::new())) .with_validator(Box::new(Validator)) } pub(super) struct Prompt; impl reedline::Prompt for Prompt { fn render_prompt_left(&self) -> Cow<'_, str> { Cow::Borrowed("") } fn render_prompt_right(&self) -> Cow<'_, str> { Cow::Borrowed("") } fn render_prompt_indicator(&self, _mode: PromptEditMode) -> Cow<'_, str> { Cow::Borrowed("> ") } fn render_prompt_multiline_indicator(&self) -> Cow<'_, str> { Cow::Borrowed("… ") } fn render_prompt_history_search_indicator(&self, search: PromptHistorySearch) -> Cow<'_, str> { let failing = match search.status { PromptHistorySearchStatus::Passing => "", PromptHistorySearchStatus::Failing => "failing ", }; Cow::Owned(format!("({failing}reverse-search: {}) ", search.term)) } fn get_indicator_color(&self) -> Color { Color::Green } fn get_prompt_multiline_color(&self) -> AnsiColor { AnsiColor::DarkGray } } struct Validator; impl reedline::Validator for Validator { fn validate(&self, line: &str) -> ValidationResult { if super::is_incomplete(&format!("{line}\n")) { ValidationResult::Incomplete } else { ValidationResult::Complete } } } struct Highlighter { config: HighlightConfiguration, styles: Vec