mirror of
https://github.com/nushell/nushell.git
synced 2025-08-21 09:40:28 +02:00
Adding coloring to help examples (#1754)
This commit is contained in:
@@ -43,10 +43,16 @@ impl WholeStreamCommand for Alias {
|
||||
}
|
||||
|
||||
fn examples(&self) -> &[Example] {
|
||||
&[Example {
|
||||
description: "Some people prefer to write one letter instead of two",
|
||||
example: "alias l [x] { ls $x }",
|
||||
}]
|
||||
&[
|
||||
Example {
|
||||
description: "An alias without parameters",
|
||||
example: "alias say-hi [] { echo 'Hello!' }",
|
||||
},
|
||||
Example {
|
||||
description: "An alias with a single parameter",
|
||||
example: "alias l [x] { ls $x }",
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -272,14 +272,19 @@ pub(crate) fn get_help(
|
||||
|
||||
let examples = cmd.examples();
|
||||
if !examples.is_empty() {
|
||||
long_desc.push_str("\nExamples:\n");
|
||||
long_desc.push_str("\nExamples:");
|
||||
}
|
||||
for example in examples {
|
||||
long_desc.push_str("\n");
|
||||
long_desc.push_str(" ");
|
||||
long_desc.push_str(example.description);
|
||||
long_desc.push_str(&format!("\n > {}\n", example.example));
|
||||
let colored_example =
|
||||
crate::shell::helper::Painter::paint_string(example.example, registry);
|
||||
long_desc.push_str(&format!("\n > {}\n", colored_example));
|
||||
}
|
||||
|
||||
long_desc.push_str("\n");
|
||||
|
||||
help.push_back(ReturnSuccess::value(
|
||||
UntaggedValue::string(long_desc).into_value(Tag::from((0, cmd_name.len(), None))),
|
||||
));
|
||||
|
Reference in New Issue
Block a user