mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
nu-table/ Fix indexing issue for table --expand
(#9484)
close #9481 --------- Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
This commit is contained in:
@ -424,7 +424,7 @@ fn build_table_batch(
|
||||
flatten_separator,
|
||||
} => {
|
||||
let sep = flatten_separator.unwrap_or_else(|| String::from(' '));
|
||||
ExpandedTable::new(limit, flatten, sep).build_list(&vals, opts)
|
||||
ExpandedTable::new(limit, flatten, sep).build_list(&vals, opts, row_offset)
|
||||
}
|
||||
TableView::Collapsed => {
|
||||
let span = opts.span();
|
||||
@ -659,7 +659,7 @@ impl PagingTableCreator {
|
||||
flatten_separator,
|
||||
};
|
||||
|
||||
build_table_batch(batch, view, 0, opts)
|
||||
build_table_batch(batch, view, self.row_offset, opts)
|
||||
}
|
||||
|
||||
fn build_collapsed(&mut self, batch: Vec<Value>) -> StringResult {
|
||||
@ -674,7 +674,7 @@ impl PagingTableCreator {
|
||||
let span = self.head;
|
||||
let opts = BuildConfig::new(ctrlc, &config, &style_computer, span, term_width);
|
||||
|
||||
build_table_batch(batch, TableView::Collapsed, 0, opts)
|
||||
build_table_batch(batch, TableView::Collapsed, self.row_offset, opts)
|
||||
}
|
||||
|
||||
fn build_general(&mut self, batch: Vec<Value>) -> StringResult {
|
||||
|
@ -2369,3 +2369,19 @@ fn _split_str_by_width(s: &str, w: usize) -> Vec<String> {
|
||||
|
||||
lines
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn table_expand_index_offset() {
|
||||
let actual = nu!(r#"1..1002 | table --expand"#);
|
||||
let suffix = "╭──────┬──────╮│ 1000 │ 1001 ││ 1001 │ 1002 │╰──────┴──────╯";
|
||||
let expected_suffix = actual.out.strip_suffix(suffix);
|
||||
assert!(expected_suffix.is_some(), "{:?}", actual.out);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn table_index_offset() {
|
||||
let actual = nu!(r#"1..1002 | table"#);
|
||||
let suffix = "╭──────┬──────╮│ 1000 │ 1001 ││ 1001 │ 1002 │╰──────┴──────╯";
|
||||
let expected_suffix = actual.out.strip_suffix(suffix);
|
||||
assert!(expected_suffix.is_some(), "{:?}", actual.out);
|
||||
}
|
||||
|
Reference in New Issue
Block a user