Add example for command n,g,p and grid, update date now examples (#4622)

This commit is contained in:
Justin Ma
2022-02-24 20:17:05 +08:00
committed by GitHub
parent 784382edde
commit c3979ef1cf
11 changed files with 191 additions and 14 deletions

View File

@ -8,8 +8,8 @@ use nu_engine::CallExt;
use nu_protocol::{
ast::{Call, PathMember},
engine::{Command, EngineState, Stack},
Category, Config, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape,
Value,
Category, Config, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span,
SyntaxShape, Value,
};
use nu_term_grid::grid::{Alignment, Cell, Direction, Filling, Grid, GridOptions};
use terminal_size::{Height, Width};
@ -131,6 +131,51 @@ prints out the list properly."#
}
}
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Render a simple list to a grid",
example: "[1 2 3 a b c] | grid",
result: Some(Value::String {
val: "1 │ 2 │ 3 │ a │ b │ c".to_string(),
span: Span::test_data(),
}),
},
Example {
description: "The above example is the same as:",
example: "[1 2 3 a b c] | wrap name | grid",
result: Some(Value::String {
val: "1 │ 2 │ 3 │ a │ b │ c".to_string(),
span: Span::test_data(),
}),
},
Example {
description: "Render a record to a grid",
example: "{name: 'foo', b: 1, c: 2} | grid",
result: Some(Value::String {
val: "foo".to_string(),
span: Span::test_data(),
}),
},
Example {
description: "Render a list of records to a grid",
example: "[{name: 'A', v: 1} {name: 'B', v: 2} {name: 'C', v: 3}] | grid",
result: Some(Value::String {
val: "A │ B │ C".to_string(),
span: Span::test_data(),
}),
},
Example {
description: "Render a table with 'name' column in it to a grid",
example: "[[name patch]; [0.1.0 $false] [0.1.1 $true] [0.2.0 $false]] | grid",
result: Some(Value::String {
val: "0.1.0 │ 0.1.1 │ 0.2.0".to_string(),
span: Span::test_data(),
}),
},
]
}
}
/// Removes ANSI escape codes and some ASCII control characters