diff --git a/crates/nu-command/src/viewers/table.rs b/crates/nu-command/src/viewers/table.rs index 189f2fb754..4b6ce006b3 100644 --- a/crates/nu-command/src/viewers/table.rs +++ b/crates/nu-command/src/viewers/table.rs @@ -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) -> 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) -> StringResult { diff --git a/crates/nu-command/tests/commands/table.rs b/crates/nu-command/tests/commands/table.rs index 058c457466..8e5746e839 100644 --- a/crates/nu-command/tests/commands/table.rs +++ b/crates/nu-command/tests/commands/table.rs @@ -2369,3 +2369,19 @@ fn _split_str_by_width(s: &str, w: usize) -> Vec { 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); +} diff --git a/crates/nu-explore/src/nu_common/table.rs b/crates/nu-explore/src/nu_common/table.rs index ead93f4034..5286216d3f 100644 --- a/crates/nu-explore/src/nu_common/table.rs +++ b/crates/nu-explore/src/nu_common/table.rs @@ -50,7 +50,7 @@ fn try_build_list( style_computer: &StyleComputer, ) -> String { let opts = BuildConfig::new(ctrlc, config, style_computer, Span::unknown(), usize::MAX); - let result = ExpandedTable::new(None, false, String::new()).build_list(&vals, opts); + let result = ExpandedTable::new(None, false, String::new()).build_list(&vals, opts, 0); match result { Ok(Some(out)) => out, Ok(None) | Err(_) => { diff --git a/crates/nu-table/src/types/expanded.rs b/crates/nu-table/src/types/expanded.rs index a5a80ca741..991cebf761 100644 --- a/crates/nu-table/src/types/expanded.rs +++ b/crates/nu-table/src/types/expanded.rs @@ -59,7 +59,12 @@ impl ExpandedTable { expanded_table_kv(cols, vals, opts) } - pub fn build_list(&self, vals: &[Value], opts: BuildConfig<'_>) -> StringResult { + pub fn build_list( + &self, + vals: &[Value], + opts: BuildConfig<'_>, + row_offset: usize, + ) -> StringResult { let opts1 = Options { ctrlc: opts.ctrlc, config: opts.config, @@ -68,7 +73,7 @@ impl ExpandedTable { span: opts.span, format: self.clone(), }; - let out = match expanded_table_list(vals, 0, opts1)? { + let out = match expanded_table_list(vals, row_offset, opts1)? { Some(out) => out, None => return Ok(None), };