use crate::cell::{AttributeChange, CellAttributes};
use crate::input::InputEvent;
use crate::lineedit::actions::Action;
use crate::lineedit::{BasicHistory, History, LineEditor};
use crate::surface::Change;
pub enum OutputElement {
Attribute(AttributeChange),
AllAttributes(CellAttributes),
Text(String),
}
impl Into<Change> for OutputElement {
fn into(self) -> Change {
match self {
OutputElement::Attribute(a) => Change::Attribute(a),
OutputElement::AllAttributes(a) => Change::AllAttributes(a),
OutputElement::Text(t) => Change::Text(t),
}
}
}
pub trait LineEditorHost {
fn render_prompt(&self, prompt: &str) -> Vec<OutputElement> {
vec![OutputElement::Text(prompt.to_owned())]
}
fn render_preview(&self, _line: &str) -> Vec<OutputElement> {
Vec::new()
}
fn highlight_line(&self, line: &str, cursor_position: usize) -> (Vec<OutputElement>, usize) {
let cursor_x_pos = crate::cell::unicode_column_width(&line[0..cursor_position], None);
(vec![OutputElement::Text(line.to_owned())], cursor_x_pos)
}
fn history(&mut self) -> &mut dyn History;
fn complete(&self, _line: &str, _cursor_position: usize) -> Vec<CompletionCandidate> {
vec![]
}
fn resolve_action(&mut self, _event: &InputEvent, _editor: &mut LineEditor) -> Option<Action> {
None
}
}
pub struct CompletionCandidate {
pub range: std::ops::Range<usize>,
pub text: String,
}
#[derive(Default)]
pub struct NopLineEditorHost {
history: BasicHistory,
}
impl LineEditorHost for NopLineEditorHost {
fn history(&mut self) -> &mut dyn History {
&mut self.history
}
}