Allow aliases to expand and ignore painting outside of lines (#3492)

This commit is contained in:
JT 2021-05-26 17:58:32 +12:00 committed by GitHub
parent 1ee51f2afa
commit 41834d16d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View file

@ -374,6 +374,10 @@ impl FromValue for Vec<Value> {
value: UntaggedValue::Table(t),
..
} => Ok(t.clone()),
Value {
value: UntaggedValue::Row(_),
..
} => Ok(vec![v.clone()]),
Value { tag, .. } => Err(ShellError::labeled_error(
"Can't convert to table",
"can't convert to table",

View file

@ -46,7 +46,9 @@ impl Painter {
fn paint(&mut self, styled_span: &Spanned<Style>) {
for pos in styled_span.span.start()..styled_span.span.end() {
self.styles[pos] = styled_span.item;
if pos < self.styles.len() {
self.styles[pos] = styled_span.item;
}
}
}

View file

@ -306,6 +306,18 @@ fn run_custom_command_with_empty_rest() {
assert_eq!(actual.err, r#""#);
}
#[test]
fn alias_a_load_env() {
let actual = nu!(
cwd: ".",
r#"
def activate-helper [] { [[name, value]; [BOB, SAM]] }; alias activate = load-env (activate-helper); activate; $nu.env.BOB
"#
);
assert_eq!(actual.out, r#"SAM"#);
}
#[test]
fn let_variable() {
let actual = nu!(