arg underlining now only affects the last argument
This commit is contained in:
@@ -20,6 +20,7 @@ use crate::{
|
||||
pub struct Highlighter {
|
||||
input: String,
|
||||
output: String,
|
||||
linebuf_cursor_pos: usize,
|
||||
style_stack: Vec<StyleSet>,
|
||||
last_was_reset: bool,
|
||||
}
|
||||
@@ -30,6 +31,7 @@ impl Highlighter {
|
||||
Self {
|
||||
input: String::new(),
|
||||
output: String::new(),
|
||||
linebuf_cursor_pos: 0,
|
||||
style_stack: Vec::new(),
|
||||
last_was_reset: true, // start as true so we don't emit a leading reset
|
||||
}
|
||||
@@ -39,9 +41,10 @@ impl Highlighter {
|
||||
///
|
||||
/// The input is passed through the annotator which inserts Unicode markers
|
||||
/// indicating token types and sub-token constructs (strings, variables, etc.)
|
||||
pub fn load_input(&mut self, input: &str) {
|
||||
pub fn load_input(&mut self, input: &str, linebuf_cursor_pos: usize) {
|
||||
let input = annotate_input(input);
|
||||
self.input = input;
|
||||
self.linebuf_cursor_pos = linebuf_cursor_pos;
|
||||
}
|
||||
|
||||
/// Processes the annotated input and generates ANSI-styled output
|
||||
@@ -100,6 +103,11 @@ impl Highlighter {
|
||||
|
||||
markers::ARG => {
|
||||
let mut arg = String::new();
|
||||
let is_last_arg = !input_chars.clone().any(|c| c == markers::ARG || c.is_whitespace());
|
||||
|
||||
if !is_last_arg {
|
||||
self.push_style(Style::White);
|
||||
} else {
|
||||
let mut chars_clone = input_chars.clone();
|
||||
while let Some(ch) = chars_clone.next() {
|
||||
if ch == markers::RESET {
|
||||
@@ -117,6 +125,7 @@ impl Highlighter {
|
||||
self.push_style(style);
|
||||
self.last_was_reset = false;
|
||||
}
|
||||
}
|
||||
|
||||
markers::COMMAND => {
|
||||
let mut cmd_name = String::new();
|
||||
@@ -180,7 +189,7 @@ impl Highlighter {
|
||||
};
|
||||
|
||||
let mut recursive_highlighter = Self::new();
|
||||
recursive_highlighter.load_input(inner_content);
|
||||
recursive_highlighter.load_input(inner_content, self.linebuf_cursor_pos);
|
||||
recursive_highlighter.highlight();
|
||||
self.push_style(Style::Blue);
|
||||
self.output.push_str(prefix);
|
||||
|
||||
@@ -363,7 +363,7 @@ impl FernVi {
|
||||
let line = self.editor.to_string();
|
||||
let hint = self.editor.get_hint_text();
|
||||
if crate::state::read_shopts(|s| s.prompt.highlight) {
|
||||
self.highlighter.load_input(&line);
|
||||
self.highlighter.load_input(&line,self.editor.cursor_byte_pos());
|
||||
self.highlighter.highlight();
|
||||
let highlighted = self.highlighter.take();
|
||||
format!("{highlighted}{hint}")
|
||||
|
||||
Reference in New Issue
Block a user