mirror of
https://github.com/nushell/nushell.git
synced 2025-06-20 01:48:09 +02:00
add back some shell coloring
This commit is contained in:
parent
37c4fb92f8
commit
dc081151bc
@ -94,10 +94,10 @@ pub struct PathNode {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Getters, new)]
|
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Getters, new)]
|
||||||
pub struct PipelineElement {
|
pub struct PipelineElement {
|
||||||
pre_ws: Option<Span>,
|
pub pre_ws: Option<Span>,
|
||||||
#[get = "crate"]
|
#[get = "crate"]
|
||||||
call: Spanned<CallNode>,
|
call: Spanned<CallNode>,
|
||||||
post_ws: Option<Span>,
|
pub post_ws: Option<Span>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PipelineElement {
|
impl PipelineElement {
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
use crate::shell::completer::NuCompleter;
|
use crate::shell::completer::NuCompleter;
|
||||||
|
use crate::parser::parse2::PipelineElement;
|
||||||
|
use crate::parser::parse2::token_tree::TokenNode;
|
||||||
|
use crate::parser::parse2::tokens::RawToken;
|
||||||
|
use crate::parser::parse2::span::Spanned;
|
||||||
use crate::parser::nom_input;
|
use crate::parser::nom_input;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use ansi_term::Color;
|
use ansi_term::Color;
|
||||||
@ -68,26 +71,24 @@ impl Highlighter for Helper {
|
|||||||
|
|
||||||
let mut iter = tokens.into_iter();
|
let mut iter = tokens.into_iter();
|
||||||
|
|
||||||
match iter.next() {
|
// match iter.next() {
|
||||||
None => return Cow::Owned(out),
|
// None => return Cow::Owned(out),
|
||||||
Some(v) => out.push_str(v.span().slice(line)),
|
// Some(v) => out.push_str(v.span().slice(line)),
|
||||||
};
|
// };
|
||||||
|
let mut first = true;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match iter.next() {
|
match iter.next() {
|
||||||
None => return Cow::Owned(out),
|
None => return Cow::Owned(out),
|
||||||
Some(token) => {
|
Some(token) => {
|
||||||
// let styled = token_style(&token, state);
|
let styled = paint_pipeline_element(&token, line);
|
||||||
|
|
||||||
// trace!("token={:?}", token);
|
if !first {
|
||||||
// trace!("style={:?}", style);
|
out.push_str("|");
|
||||||
// trace!("new_state={:?}", new_state);
|
} else {
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
|
||||||
// state = new_state;
|
|
||||||
// let slice = &line[*start..*end];
|
|
||||||
// let styled = style.paint(slice);
|
|
||||||
out.push_str("|");
|
|
||||||
let styled = Color::Black.bold().paint(token.span().slice(line));
|
|
||||||
out.push_str(&styled.to_string());
|
out.push_str(&styled.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,4 +102,45 @@ impl Highlighter for Helper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn paint_token_node(token_node: &TokenNode, line: &str) -> String {
|
||||||
|
let styled = match token_node {
|
||||||
|
TokenNode::Call(..) => Color::Cyan.bold().paint(token_node.span().slice(line)),
|
||||||
|
TokenNode::Whitespace(..) => Color::White.normal().paint(token_node.span().slice(line)),
|
||||||
|
TokenNode::Flag(..) => Color::Black.bold().paint(token_node.span().slice(line)),
|
||||||
|
TokenNode::Identifier(..) => Color::Yellow.bold().paint(token_node.span().slice(line)),
|
||||||
|
TokenNode::Path(..) => Color::Green.bold().paint(token_node.span().slice(line)),
|
||||||
|
TokenNode::Error(..) => Color::Red.bold().paint(token_node.span().slice(line)),
|
||||||
|
TokenNode::Delimited(..) => Color::White.paint(token_node.span().slice(line)),
|
||||||
|
TokenNode::Operator(..) => Color::Purple.bold().paint(token_node.span().slice(line)),
|
||||||
|
TokenNode::Pipeline(..) => Color::Blue.normal().paint(token_node.span().slice(line)),
|
||||||
|
TokenNode::Token(Spanned { item: RawToken::Integer(..), ..}) => Color::Purple.bold().paint(token_node.span().slice(line)),
|
||||||
|
TokenNode::Token(Spanned { item: RawToken::Size(..), ..}) => Color::Purple.bold().paint(token_node.span().slice(line)),
|
||||||
|
TokenNode::Token(Spanned { item: RawToken::String(..), ..}) => Color::Green.normal().paint(token_node.span().slice(line)),
|
||||||
|
TokenNode::Token(Spanned { item: RawToken::Variable(..), ..}) => Color::Yellow.bold().paint(token_node.span().slice(line)),
|
||||||
|
TokenNode::Token(Spanned { item: RawToken::Bare, ..}) => Color::Green.normal().paint(token_node.span().slice(line)),
|
||||||
|
};
|
||||||
|
|
||||||
|
styled.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn paint_pipeline_element(pipeline_element: &PipelineElement, line: &str) -> String {
|
||||||
|
let mut styled = String::new();
|
||||||
|
|
||||||
|
if let Some(ws) = pipeline_element.pre_ws {
|
||||||
|
styled.push_str(&Color::White.normal().paint(ws.slice(line)));
|
||||||
|
}
|
||||||
|
styled.push_str(&paint_token_node(pipeline_element.call().head(), line));
|
||||||
|
|
||||||
|
if let Some(children) = pipeline_element.call().children() {
|
||||||
|
for child in children {
|
||||||
|
styled.push_str(&paint_token_node(child, line));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(ws) = pipeline_element.post_ws {
|
||||||
|
styled.push_str(&Color::White.normal().paint(ws.slice(line)));
|
||||||
|
}
|
||||||
|
|
||||||
|
styled.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
impl rustyline::Helper for Helper {}
|
impl rustyline::Helper for Helper {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user