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