mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 00:13:21 +01: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:
parent
69bf43ef56
commit
2ec1364925
@ -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);
|
||||
}
|
||||
|
@ -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(_) => {
|
||||
|
@ -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),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user