Implemented functions and aliases
This commit is contained in:
@@ -16,7 +16,7 @@ impl<'a> Highlighter for SynHelper<'a> {
|
||||
let raw = token.to_string();
|
||||
match token.rule() {
|
||||
TkRule::Comment => {
|
||||
let styled = style_text(&raw, Style::BrightBlack);
|
||||
let styled = &raw.styled(Style::BrightBlack);
|
||||
result.push_str(&styled);
|
||||
}
|
||||
TkRule::ErrPipeOp |
|
||||
@@ -26,46 +26,70 @@ impl<'a> Highlighter for SynHelper<'a> {
|
||||
TkRule::RedirOp |
|
||||
TkRule::BgOp => {
|
||||
is_command = true;
|
||||
let styled = style_text(&raw, Style::Cyan);
|
||||
let styled = &raw.styled(Style::Cyan);
|
||||
result.push_str(&styled);
|
||||
}
|
||||
TkRule::FuncName => {
|
||||
let name = raw.strip_suffix("()").unwrap_or(&raw);
|
||||
let styled = name.styled(Style::Cyan);
|
||||
let rebuilt = format!("{styled}()");
|
||||
result.push_str(&rebuilt);
|
||||
}
|
||||
TkRule::Keyword => {
|
||||
if &raw == "for" {
|
||||
in_array = true;
|
||||
}
|
||||
let styled = style_text(&raw, Style::Yellow);
|
||||
let styled = &raw.styled(Style::Yellow);
|
||||
result.push_str(&styled);
|
||||
}
|
||||
TkRule::BraceGrp => {
|
||||
let body = &raw[1..raw.len() - 1];
|
||||
let highlighted = self.highlight(body, 0).to_string();
|
||||
let styled_o_brace = "{".styled(Style::BrightBlue);
|
||||
let styled_c_brace = "}".styled(Style::BrightBlue);
|
||||
let rebuilt = format!("{styled_o_brace}{highlighted}{styled_c_brace}");
|
||||
|
||||
is_command = false;
|
||||
result.push_str(&rebuilt);
|
||||
}
|
||||
TkRule::Subshell => {
|
||||
let body = &raw[1..raw.len() - 1];
|
||||
let highlighted = self.highlight(body, 0).to_string();
|
||||
let styled_o_paren = style_text("(", Style::BrightBlue);
|
||||
let styled_c_paren = style_text(")", Style::BrightBlue);
|
||||
let styled_o_paren = "(".styled(Style::BrightBlue);
|
||||
let styled_c_paren = ")".styled(Style::BrightBlue);
|
||||
let rebuilt = format!("{styled_o_paren}{highlighted}{styled_c_paren}");
|
||||
|
||||
is_command = false;
|
||||
result.push_str(&rebuilt);
|
||||
}
|
||||
TkRule::Ident => {
|
||||
if in_array {
|
||||
if &raw == "in" {
|
||||
let styled = style_text(&raw, Style::Yellow);
|
||||
let styled = &raw.styled(Style::Yellow);
|
||||
result.push_str(&styled);
|
||||
} else {
|
||||
let styled = style_text(&raw, Style::Magenta);
|
||||
let styled = &raw.styled(Style::Magenta);
|
||||
result.push_str(&styled);
|
||||
}
|
||||
|
||||
} else if &raw == "{" || &raw == "}" {
|
||||
result.push_str(&raw);
|
||||
|
||||
} else if is_command {
|
||||
if get_bin_path(&token.to_string(), self.shenv).is_some() ||
|
||||
self.shenv.logic().get_alias(&raw).is_some() ||
|
||||
self.shenv.logic().get_function(&raw).is_some() ||
|
||||
BUILTINS.contains(&raw.as_str()) {
|
||||
let styled = style_text(&raw, Style::Green);
|
||||
let styled = &raw.styled(Style::Green);
|
||||
result.push_str(&styled);
|
||||
|
||||
} else {
|
||||
let styled = style_text(&raw, Style::Red | Style::Bold);
|
||||
let styled = &raw.styled(Style::Red | Style::Bold);
|
||||
result.push_str(&styled);
|
||||
}
|
||||
|
||||
is_command = false;
|
||||
|
||||
} else {
|
||||
result.push_str(&raw);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user