Bump tabled

Fix cargo fmt

Up
This commit is contained in:
Maxim Zhiburt 2025-04-24 18:23:38 +03:00
parent b33f4b7f55
commit d9a0a27a13
8 changed files with 215 additions and 209 deletions

62
Cargo.lock generated
View File

@ -102,7 +102,16 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cf4578926a981ab0ca955dc023541d19de37112bc24c1a197bd806d3d86ad1d" checksum = "1cf4578926a981ab0ca955dc023541d19de37112bc24c1a197bd806d3d86ad1d"
dependencies = [ dependencies = [
"ansitok", "ansitok 0.2.0",
]
[[package]]
name = "ansi-str"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "060de1453b69f46304b28274f382132f4e72c55637cf362920926a70d090890d"
dependencies = [
"ansitok 0.3.0",
] ]
[[package]] [[package]]
@ -115,6 +124,16 @@ dependencies = [
"vte 0.10.1", "vte 0.10.1",
] ]
[[package]]
name = "ansitok"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0a8acea8c2f1c60f0a92a8cd26bf96ca97db56f10bbcab238bbe0cceba659ee"
dependencies = [
"nom 7.1.3",
"vte 0.14.1",
]
[[package]] [[package]]
name = "anstream" name = "anstream"
version = "0.6.18" version = "0.6.18"
@ -3772,7 +3791,7 @@ dependencies = [
name = "nu-explore" name = "nu-explore"
version = "0.103.1" version = "0.103.1"
dependencies = [ dependencies = [
"ansi-str", "ansi-str 0.8.0",
"anyhow", "anyhow",
"crossterm", "crossterm",
"log", "log",
@ -4590,14 +4609,14 @@ checksum = "fb37767f6569cd834a413442455e0f066d0d522de8630436e2a1761d9726ba56"
[[package]] [[package]]
name = "papergrid" name = "papergrid"
version = "0.13.0" version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2b0f8def1f117e13c895f3eda65a7b5650688da29d6ad04635f61bc7b92eebd" checksum = "30268a8d20c2c0d126b2b6610ab405f16517f6ba9f244d8c59ac2c512a8a1ce7"
dependencies = [ dependencies = [
"ansi-str", "ahash",
"ansitok", "ansi-str 0.9.0",
"ansitok 0.3.0",
"bytecount", "bytecount",
"fnv",
"unicode-width 0.2.0", "unicode-width 0.2.0",
] ]
@ -7041,13 +7060,14 @@ dependencies = [
[[package]] [[package]]
name = "tabled" name = "tabled"
version = "0.17.0" version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6709222f3973137427ce50559cd564dc187a95b9cfe01613d2f4e93610e510a" checksum = "228d124371171cd39f0f454b58f73ddebeeef3cef3207a82ffea1c29465aea43"
dependencies = [ dependencies = [
"ansi-str", "ansi-str 0.9.0",
"ansitok", "ansitok 0.3.0",
"papergrid", "papergrid",
"testing_table",
] ]
[[package]] [[package]]
@ -7121,6 +7141,16 @@ version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76"
[[package]]
name = "testing_table"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f8daae29995a24f65619e19d8d31dea5b389f3d853d8bf297bbf607cd0014cc"
dependencies = [
"ansitok 0.3.0",
"unicode-width 0.2.0",
]
[[package]] [[package]]
name = "textwrap" name = "textwrap"
version = "0.16.1" version = "0.16.1"
@ -7886,6 +7916,16 @@ dependencies = [
"vte_generate_state_changes", "vte_generate_state_changes",
] ]
[[package]]
name = "vte"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "231fdcd7ef3037e8330d8e17e61011a2c244126acc0a982f4040ac3f9f0bc077"
dependencies = [
"arrayvec 0.7.6",
"memchr",
]
[[package]] [[package]]
name = "vte_generate_state_changes" name = "vte_generate_state_changes"
version = "0.1.2" version = "0.1.2"

View File

@ -159,7 +159,7 @@ strum = "0.26"
strum_macros = "0.26" strum_macros = "0.26"
syn = "2.0" syn = "2.0"
sysinfo = "0.33" sysinfo = "0.33"
tabled = { version = "0.17.0", default-features = false } tabled = { version = "0.19", default-features = false }
tempfile = "3.15" tempfile = "3.15"
titlecase = "3.5" titlecase = "3.5"
toml = "0.8" toml = "0.8"

View File

@ -1,13 +1,14 @@
// note: Seems like could be simplified // note: Seems like could be simplified
// IMHO: it shall not take 300+ lines :) // IMHO: it shall not take 300+ lines :)
// TODO: simplify
use self::{global_horizontal_char::SetHorizontalChar, set_widths::SetWidths}; use self::global_horizontal_char::SetHorizontalChar;
use nu_protocol::engine::EngineState; use nu_protocol::engine::EngineState;
use nu_protocol::Value; use nu_protocol::Value;
use nu_table::{string_width, string_wrap}; use nu_table::{string_width, string_wrap};
use tabled::{ use tabled::{
grid::config::ColoredConfig, grid::config::ColoredConfig,
settings::{peaker::Priority, width::Wrap, Settings, Style}, settings::{peaker::Priority, width::Wrap, Style},
Table, Table,
}; };
@ -60,13 +61,12 @@ pub fn build_table(
desc_table.with(Style::rounded().remove_bottom().remove_horizontals()); desc_table.with(Style::rounded().remove_bottom().remove_horizontals());
let mut val_table = Table::from_iter(data); let mut val_table = Table::from_iter(data);
val_table.with( val_table.with(Style::rounded().corner_top_left('├').corner_top_right('┤'));
Settings::default() val_table.get_dimension_mut().set_widths(widths);
.with(Style::rounded().corner_top_left('├').corner_top_right('┤')) val_table.with((
.with(SetWidths(widths)) Wrap::new(width).priority(Priority::max(true)),
.with(Wrap::new(width).priority(Priority::max(true))) SetHorizontalChar::new('┼', '┴', 11 + 2 + 1),
.with(SetHorizontalChar::new('┼', '┴', 11 + 2 + 1)), ));
);
format!("{desc_table}\n{val_table}") format!("{desc_table}\n{val_table}")
} }
@ -315,8 +315,8 @@ mod util {
mod global_horizontal_char { mod global_horizontal_char {
use tabled::{ use tabled::{
grid::{ grid::{
config::{ColoredConfig, Offset}, config::{ColoredConfig, Offset, Position},
dimension::{CompleteDimensionVecRecords, Dimension}, dimension::{CompleteDimension, Dimension},
records::{ExactRecords, Records}, records::{ExactRecords, Records},
}, },
settings::TableOption, settings::TableOption,
@ -338,14 +338,14 @@ mod global_horizontal_char {
} }
} }
impl<R: Records + ExactRecords> TableOption<R, ColoredConfig, CompleteDimensionVecRecords<'_>> impl<R: Records + ExactRecords> TableOption<R, ColoredConfig, CompleteDimension<'_>>
for SetHorizontalChar for SetHorizontalChar
{ {
fn change( fn change(
self, self,
records: &mut R, records: &mut R,
cfg: &mut ColoredConfig, cfg: &mut ColoredConfig,
dimension: &mut CompleteDimensionVecRecords<'_>, dimension: &mut CompleteDimension<'_>,
) { ) {
let count_columns = records.count_columns(); let count_columns = records.count_columns();
let count_rows = records.count_rows(); let count_rows = records.count_rows();
@ -358,17 +358,21 @@ mod global_horizontal_char {
let has_vertical = cfg.has_vertical(0, count_columns); let has_vertical = cfg.has_vertical(0, count_columns);
if has_vertical && self.index == 0 { if has_vertical && self.index == 0 {
let mut border = cfg.get_border((0, 0), (count_rows, count_columns)); let mut border = cfg.get_border(Position::new(0, 0), (count_rows, count_columns));
border.left_top_corner = Some(self.intersection); border.left_top_corner = Some(self.intersection);
cfg.set_border((0, 0), border); cfg.set_border(Position::new(0, 0), border);
return; return;
} }
let mut i = 1; let mut i = 1;
for (col, width) in widths.into_iter().enumerate() { for (col, width) in widths.into_iter().enumerate() {
if self.index < i + width { if self.index < i + width {
let o = self.index - i; let offset = self.index - i;
cfg.set_horizontal_char((0, col), self.split, Offset::Begin(o)); cfg.set_horizontal_char(
Position::new(0, col),
Offset::Start(offset),
self.split,
);
return; return;
} }
@ -377,9 +381,10 @@ mod global_horizontal_char {
let has_vertical = cfg.has_vertical(col, count_columns); let has_vertical = cfg.has_vertical(col, count_columns);
if has_vertical { if has_vertical {
if self.index == i { if self.index == i {
let mut border = cfg.get_border((0, col), (count_rows, count_columns)); let mut border =
cfg.get_border(Position::new(0, col), (count_rows, count_columns));
border.right_top_corner = Some(self.intersection); border.right_top_corner = Some(self.intersection);
cfg.set_border((0, col), border); cfg.set_border(Position::new(0, col), border);
return; return;
} }
@ -389,7 +394,7 @@ mod global_horizontal_char {
} }
} }
fn get_widths(dims: &CompleteDimensionVecRecords<'_>, count_columns: usize) -> Vec<usize> { fn get_widths(dims: &CompleteDimension<'_>, count_columns: usize) -> Vec<usize> {
let mut widths = vec![0; count_columns]; let mut widths = vec![0; count_columns];
for (col, width) in widths.iter_mut().enumerate() { for (col, width) in widths.iter_mut().enumerate() {
*width = dims.get_width(col); *width = dims.get_width(col);
@ -398,23 +403,3 @@ mod global_horizontal_char {
widths widths
} }
} }
mod set_widths {
use tabled::{
grid::{config::ColoredConfig, dimension::CompleteDimensionVecRecords},
settings::TableOption,
};
pub struct SetWidths(pub Vec<usize>);
impl<R> TableOption<R, ColoredConfig, CompleteDimensionVecRecords<'_>> for SetWidths {
fn change(
self,
_: &mut R,
_: &mut ColoredConfig,
dims: &mut CompleteDimensionVecRecords<'_>,
) {
dims.set_widths(self.0);
}
}
}

View File

@ -665,13 +665,15 @@ fn test_expand_big_0() {
"open sample.toml | table --width=80 --expand" "open sample.toml | table --width=80 --expand"
)); ));
_print_lines(&actual.out, 80);
let expected = join_lines([ let expected = join_lines([
"╭──────────────────┬───────────────────────────────────────────────────────────╮", "╭──────────────────┬───────────────────────────────────────────────────────────╮",
"│ │ ╭───────────────┬───────────────────────────────────────╮ │", "│ │ ╭───────────────┬───────────────────────────────────────╮ │",
"│ package │ │ │ ╭───┬───────────────────────────────╮ │ │", "│ package │ │ │ ╭───┬────────────────────── │ │",
"│ │ │ authors │ │ 0 │ The Nushell Project │ │ │", "│ │ │ authors │ │ 0 │ The Nushell Project │ │ │",
"│ │ │ │ │ │ Developers │ │ │", "│ │ │ │ │ │ Developers │ │ │",
"│ │ │ │ ╰───┴───────────────────────────────╯ │ │", "│ │ │ │ ╰───┴────────────────────── │ │",
"│ │ │ default-run │ nu │ │", "│ │ │ default-run │ nu │ │",
"│ │ │ description │ A new type of shell │ │", "│ │ │ description │ A new type of shell │ │",
"│ │ │ documentation │ https://www.nushell.sh/book/ │ │", "│ │ │ documentation │ https://www.nushell.sh/book/ │ │",
@ -688,21 +690,21 @@ fn test_expand_big_0() {
"│ │ │ │ ╭──────────┬────────────────────────╮ │ │", "│ │ │ │ ╭──────────┬────────────────────────╮ │ │",
"│ │ │ metadata │ │ │ ╭───────────┬────────╮ │ │ │", "│ │ │ metadata │ │ │ ╭───────────┬────────╮ │ │ │",
"│ │ │ │ │ binstall │ │ pkg-url │ { repo │ │ │ │", "│ │ │ │ │ binstall │ │ pkg-url │ { repo │ │ │ │",
"│ │ │ │ │ │ │ │ }/rel │ │ │ │", "│ │ │ │ │ │ │ │ }/rele │ │ │ │",
"│ │ │ │ │ │ │ │ eases/ │ │ │ │", "│ │ │ │ │ │ │ │ ases/d │ │ │ │",
"│ │ │ │ │ │ │ │ downlo │ │ │ │", "│ │ │ │ │ │ │ │ ownloa │ │ │ │",
"│ │ │ │ │ │ │ │ ad/{ v │ │ │ │", "│ │ │ │ │ │ │ │ d/{ ve │ │ │ │",
"│ │ │ │ │ │ │ │ ersion │ │ │ │", "│ │ │ │ │ │ │ │ rsion │ │ │ │",
"│ │ │ │ │ │ │ │ }/{ │ │ │ │", "│ │ │ │ │ │ │ │ }/{ │ │ │ │",
"│ │ │ │ │ │ │ │ name │ │ │ │", "│ │ │ │ │ │ │ │ name │ │ │ │",
"│ │ │ │ │ │ │ │ }-{ ve │ │ │ │", "│ │ │ │ │ │ │ │ }-{ ve │ │ │ │",
"│ │ │ │ │ │ │ │ rsion │ │ │ │", "│ │ │ │ │ │ │ │ rsion │ │ │ │",
"│ │ │ │ │ │ │ │ }-{ │ │ │ │", "│ │ │ │ │ │ │ │ }-{ │ │ │ │",
"│ │ │ │ │ │ │ │ target │ │ │ │", "│ │ │ │ │ │ │ │ target │ │ │ │",
"│ │ │ │ │ │ │ │ }.{ a │ │ │ │", "│ │ │ │ │ │ │ │ }.{ ar │ │ │ │",
"│ │ │ │ │ │ │ │ rchive │ │ │ │", "│ │ │ │ │ │ │ │ chive- │ │ │ │",
"│ │ │ │ │ │ │ │ -forma │ │ │ │", "│ │ │ │ │ │ │ │ format │ │ │ │",
"│ │ │ │ │ │ │ │ t } │ │ │ │", "│ │ │ │ │ │ │ │ } │ │ │ │",
"│ │ │ │ │ │ │ pkg-fmt │ tgz │ │ │ │", "│ │ │ │ │ │ │ pkg-fmt │ tgz │ │ │ │",
"│ │ │ │ │ │ │ overrides │ {recor │ │ │ │", "│ │ │ │ │ │ │ overrides │ {recor │ │ │ │",
"│ │ │ │ │ │ │ │ d 1 │ │ │ │", "│ │ │ │ │ │ │ │ d 1 │ │ │ │",
@ -856,6 +858,8 @@ fn test_expand_big_0() {
"open sample.toml | table --expand --width=120" "open sample.toml | table --expand --width=120"
)); ));
_print_lines(&actual.out, 120);
let expected = join_lines([ let expected = join_lines([
"╭──────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────╮", "╭──────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────╮",
"│ │ ╭───────────────┬───────────────────────────────────────────────────────────────────────────────╮ │", "│ │ ╭───────────────┬───────────────────────────────────────────────────────────────────────────────╮ │",
@ -1185,7 +1189,7 @@ fn test_expand_big_0() {
"│ │ │ time │ 0.3.12 │ │", "│ │ │ time │ 0.3.12 │ │",
"│ │ ╰───────────────┴───────────────────╯ │", "│ │ ╰───────────────┴───────────────────╯ │",
"│ target │ {record 3 fields} │", "│ target │ {record 3 fields} │",
"│ │ ╭──────────────────────────────────╮ │", "│ │ ╭──────────────────────────────────╮ │",
"│ dev-dependencies │ │ nu-test-support │ {record 2 │ │", "│ dev-dependencies │ │ nu-test-support │ {record 2 │ │",
"│ │ │ │ fields} │ │", "│ │ │ │ fields} │ │",
"│ │ │ tempfile │ 3.2.0 │ │", "│ │ │ tempfile │ 3.2.0 │ │",
@ -1197,7 +1201,7 @@ fn test_expand_big_0() {
"│ │ │ rstest │ {record 2 │ │", "│ │ │ rstest │ {record 2 │ │",
"│ │ │ │ fields} │ │", "│ │ │ │ fields} │ │",
"│ │ │ itertools │ 0.10.3 │ │", "│ │ │ itertools │ 0.10.3 │ │",
"│ │ ╰──────────────────────────────────╯ │", "│ │ ╰──────────────────────────────────╯ │",
"│ │ ╭─────────────────────┬─────────────╮ │", "│ │ ╭─────────────────────┬─────────────╮ │",
"│ features │ │ │ ╭───┬─────╮ │ │", "│ features │ │ │ ╭───┬─────╮ │ │",
"│ │ │ plugin │ │ 0 │ nu- │ │ │", "│ │ │ plugin │ │ 0 │ nu- │ │ │",
@ -1667,75 +1671,72 @@ fn table_expande_with_no_header_internally_0() {
"│ │ │ │ │ 0 │ completion_menu │ none │ tab │ ╭───┬───────╮ │ {re │ │ │", "│ │ │ │ │ 0 │ completion_menu │ none │ tab │ ╭───┬───────╮ │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │", "│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 1 │ │ │", "│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ ld} │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ } │ │ │", "│ │ │ │ │ │ │ │ │ │ │ sert │ │ │ │ │",
"│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │", "│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │",
"│ │ │ │ │ 1 │ completion_previous │ shift │ backtab │ ╭───┬───────╮ │ {re │ │ │", "│ │ │ │ │ 1 │ completion_previous │ shift │ backtab │ ╭───┬───────╮ │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │", "│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 1 │ │ │", "│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ ld} │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ } │ │ │", "│ │ │ │ │ │ │ │ │ │ │ sert │ │ │ │ │",
"│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │", "│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │",
"│ │ │ │ │ 2 │ history_menu │ control │ char_r │ emacs │ {re │ │ │", "│ │ │ │ │ 2 │ history_menu │ control │ char_r │ emacs │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ cor │ │ │", "│ │ │ │ │ │ │ │ │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 2 │ │ │", "│ │ │ │ │ │ │ │ │ │ d 2 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ lds │ │ │",
"│ │ │ │ │ │ │ │ │ │ s} │ │ │", "│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ 3 │ next_page │ control │ char_x │ emacs │ {re │ │ │", "│ │ │ │ │ 3 │ next_page │ control │ char_x │ emacs │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ cor │ │ │", "│ │ │ │ │ │ │ │ │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │", "│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ 4 │ undo_or_previous_page │ control │ char_z │ emacs │ {re │ │ │", "│ │ │ │ │ 4 │ undo_or_previous_page │ control │ char_z │ emacs │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ cor │ │ │", "│ │ │ │ │ │ │ │ │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │", "│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ 5 │ yank │ control │ char_y │ emacs │ {re │ │ │", "│ │ │ │ │ 5 │ yank │ control │ char_y │ emacs │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ cor │ │ │", "│ │ │ │ │ │ │ │ │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │", "│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ 6 │ unix-line-discard │ control │ char_u │ ╭───┬───────╮ │ {re │ │ │", "│ │ │ │ │ 6 │ unix-line-discard │ control │ char_u │ ╭───┬───────╮ │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │", "│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 1 │ │ │", "│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ ld} │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ } │ │ │", "│ │ │ │ │ │ │ │ │ │ │ sert │ │ │ │ │",
"│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │", "│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │",
"│ │ │ │ │ 7 │ kill-line │ control │ char_k │ ╭───┬───────╮ │ {re │ │ │", "│ │ │ │ │ 7 │ kill-line │ control │ char_k │ ╭───┬───────╮ │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │", "│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 1 │ │ │", "│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ ld} │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ } │ │ │", "│ │ │ │ │ │ │ │ │ │ │ sert │ │ │ │ │",
"│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │", "│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │",
"│ │ │ │ │ 8 │ commands_menu │ control │ char_t │ ╭───┬───────╮ │ {re │ │ │", "│ │ │ │ │ 8 │ commands_menu │ control │ char_t │ ╭───┬───────╮ │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │", "│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 2 │ │ │", "│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 2 │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ lds │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ s} │ │ │", "│ │ │ │ │ │ │ │ │ │ │ sert │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │", "│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │",
"│ │ │ │ │ 9 │ vars_menu │ alt │ char_o │ ╭───┬───────╮ │ {re │ │ │", "│ │ │ │ │ 9 │ vars_menu │ alt │ char_o │ ╭───┬───────╮ │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │", "│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 2 │ │ │", "│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 2 │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ lds │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ s} │ │ │", "│ │ │ │ │ │ │ │ │ │ │ sert │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │", "│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │",
"│ │ │ │ │ 10 │ commands_with_description │ control │ char_s │ ╭───┬───────╮ │ {re │ │ │", "│ │ │ │ │ 10 │ commands_with_description │ control │ char_s │ ╭───┬───────╮ │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │", "│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 2 │ │ │", "│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 2 │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ lds │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ s} │ │ │", "│ │ │ │ │ │ │ │ │ │ │ sert │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │", "│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │",
"│ │ │ │ ╰────┴───────────────────────────┴──────────┴─────────┴───────────────┴─────╯ │ │", "│ │ │ │ ╰────┴───────────────────────────┴──────────┴─────────┴───────────────┴─────╯ │ │",
"│ │ ╰──────────────────────────────────┴───────────────────────────────────────────────────────────────────────────────╯ │", "│ │ ╰──────────────────────────────────┴───────────────────────────────────────────────────────────────────────────────╯ │",
@ -1936,69 +1937,62 @@ fn table_expande_with_no_header_internally_1() {
"│ │ │ │ │ 0 │ completion_menu │ none │ tab │ [list 3 │ {re │ │ │", "│ │ │ │ │ 0 │ completion_menu │ none │ tab │ [list 3 │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ items] │ cor │ │ │", "│ │ │ │ │ │ │ │ │ items] │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │", "│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ 1 │ completion_previous │ shift │ backtab │ [list 3 │ {re │ │ │", "│ │ │ │ │ 1 │ completion_previous │ shift │ backtab │ [list 3 │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ items] │ cor │ │ │", "│ │ │ │ │ │ │ │ │ items] │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │", "│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ 2 │ history_menu │ control │ char_r │ emacs │ {re │ │ │", "│ │ │ │ │ 2 │ history_menu │ control │ char_r │ emacs │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ cor │ │ │", "│ │ │ │ │ │ │ │ │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 2 │ │ │", "│ │ │ │ │ │ │ │ │ │ d 2 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ lds │ │ │",
"│ │ │ │ │ │ │ │ │ │ s} │ │ │", "│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ 3 │ next_page │ control │ char_x │ emacs │ {re │ │ │", "│ │ │ │ │ 3 │ next_page │ control │ char_x │ emacs │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ cor │ │ │", "│ │ │ │ │ │ │ │ │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │", "│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ 4 │ undo_or_previous_page │ control │ char_z │ emacs │ {re │ │ │", "│ │ │ │ │ 4 │ undo_or_previous_page │ control │ char_z │ emacs │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ cor │ │ │", "│ │ │ │ │ │ │ │ │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │", "│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ 5 │ yank │ control │ char_y │ emacs │ {re │ │ │", "│ │ │ │ │ 5 │ yank │ control │ char_y │ emacs │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ cor │ │ │", "│ │ │ │ │ │ │ │ │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │", "│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ 6 │ unix-line-discard │ control │ char_u │ [list 3 │ {re │ │ │", "│ │ │ │ │ 6 │ unix-line-discard │ control │ char_u │ [list 3 │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ items] │ cor │ │ │", "│ │ │ │ │ │ │ │ │ items] │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │", "│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ 7 │ kill-line │ control │ char_k │ [list 3 │ {re │ │ │", "│ │ │ │ │ 7 │ kill-line │ control │ char_k │ [list 3 │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ items] │ cor │ │ │", "│ │ │ │ │ │ │ │ │ items] │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │", "│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ 8 │ commands_menu │ control │ char_t │ [list 3 │ {re │ │ │", "│ │ │ │ │ 8 │ commands_menu │ control │ char_t │ [list 3 │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ items] │ cor │ │ │", "│ │ │ │ │ │ │ │ │ items] │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 2 │ │ │", "│ │ │ │ │ │ │ │ │ │ d 2 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ lds │ │ │",
"│ │ │ │ │ │ │ │ │ │ s} │ │ │", "│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ 9 │ vars_menu │ alt │ char_o │ [list 3 │ {re │ │ │", "│ │ │ │ │ 9 │ vars_menu │ alt │ char_o │ [list 3 │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ items] │ cor │ │ │", "│ │ │ │ │ │ │ │ │ items] │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 2 │ │ │", "│ │ │ │ │ │ │ │ │ │ d 2 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ lds │ │ │",
"│ │ │ │ │ │ │ │ │ │ s} │ │ │", "│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ 10 │ commands_with_description │ control │ char_s │ [list 3 │ {re │ │ │", "│ │ │ │ │ 10 │ commands_with_description │ control │ char_s │ [list 3 │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ items] │ cor │ │ │", "│ │ │ │ │ │ │ │ │ items] │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 2 │ │ │", "│ │ │ │ │ │ │ │ │ │ d 2 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │", "│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │", "│ │ │ │ │ │ │ │ │ │ lds │ │ │",
"│ │ │ │ │ │ │ │ │ │ s} │ │ │", "│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ ╰────┴───────────────────────────┴──────────┴─────────┴──────────┴─────╯ │ │", "│ │ │ │ ╰────┴───────────────────────────┴──────────┴─────────┴──────────┴─────╯ │ │",
"│ │ ╰──────────────────────────────────┴──────────────────────────────────────────────────────────────────────────╯ │", "│ │ ╰──────────────────────────────────┴──────────────────────────────────────────────────────────────────────────╯ │",
"╰────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", "╰────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯",
@ -2168,11 +2162,10 @@ fn test_collapse_big_0() {
"│ ├───────────────┼──────────┬───────────┬────────────────────┤", "│ ├───────────────┼──────────┬───────────┬────────────────────┤",
"│ │ metadata │ binstall │ pkg-url │ { repo }/releases/ │", "│ │ metadata │ binstall │ pkg-url │ { repo }/releases/ │",
"│ │ │ │ │ download/{ v │", "│ │ │ │ │ download/{ v │",
"│ │ │ │ │ ersion │", "│ │ │ │ │ ersion }/{ name }- │",
"│ │ │ │ │ }/{ name }-{ vers │", "│ │ │ │ │ { version }- │",
"│ │ │ │ │ ion }- │", "│ │ │ │ │ { target }.{ archi │",
"│ │ │ │ │ { target }.{ │", "│ │ │ │ │ ve-format } │",
"│ │ │ │ │ archive-format } │",
"│ │ │ ├───────────┼────────────────────┤", "│ │ │ ├───────────┼────────────────────┤",
"│ │ │ │ pkg-fmt │ tgz │", "│ │ │ │ pkg-fmt │ tgz │",
"│ │ │ ├───────────┼────────────────────┤", "│ │ │ ├───────────┼────────────────────┤",

View File

@ -16,7 +16,7 @@ use tabled::{
config::{ config::{
AlignmentHorizontal, ColoredConfig, Entity, Indent, Position, Sides, SpannedConfig, AlignmentHorizontal, ColoredConfig, Entity, Indent, Position, Sides, SpannedConfig,
}, },
dimension::{CompleteDimensionVecRecords, SpannedGridDimension}, dimension::{CompleteDimension, Dimension, PeekableGridDimension},
records::{ records::{
vec_records::{Text, VecRecords}, vec_records::{Text, VecRecords},
ExactRecords, Records, ExactRecords, Records,
@ -85,7 +85,7 @@ impl NuTable {
} }
pub fn insert(&mut self, pos: Position, text: String) { pub fn insert(&mut self, pos: Position, text: String) {
self.data[pos.0][pos.1] = Text::new(text); self.data[pos.row][pos.col] = Text::new(text);
} }
pub fn insert_row(&mut self, index: usize, row: Vec<String>) { pub fn insert_row(&mut self, index: usize, row: Vec<String>) {
@ -331,8 +331,8 @@ fn remove_header(t: &mut NuTable) -> HeadInfo {
.alignments .alignments
.cells .cells
.drain() .drain()
.filter(|(k, _)| k.0 != 0) .filter(|(k, _)| k.row != 0)
.map(|(k, v)| ((k.0 - 1, k.1), v)) .map(|(k, v)| (k - (1, 0), v))
.collect(); .collect();
t.alignments.header = AlignmentHorizontal::Center; t.alignments.header = AlignmentHorizontal::Center;
@ -341,8 +341,8 @@ fn remove_header(t: &mut NuTable) -> HeadInfo {
.styles .styles
.cells .cells
.drain() .drain()
.filter(|(k, _)| k.0 != 0) .filter(|(k, _)| k.row != 0)
.map(|(k, v)| ((k.0 - 1, k.1), v)) .map(|(k, v)| (k - (1, 0), v))
.collect(); .collect();
t.styles.header = Color::empty(); t.styles.header = Color::empty();
@ -475,12 +475,12 @@ impl WidthEstimation {
} }
} }
impl TableOption<NuRecords, ColoredConfig, CompleteDimensionVecRecords<'_>> for WidthCtrl { impl TableOption<NuRecords, ColoredConfig, CompleteDimension<'_>> for WidthCtrl {
fn change( fn change(
self, self,
recs: &mut NuRecords, recs: &mut NuRecords,
cfg: &mut ColoredConfig, cfg: &mut ColoredConfig,
dims: &mut CompleteDimensionVecRecords<'_>, dims: &mut CompleteDimension<'_>,
) { ) {
if self.width.truncate { if self.width.truncate {
width_ctrl_truncate(self, recs, cfg, dims); width_ctrl_truncate(self, recs, cfg, dims);
@ -501,7 +501,7 @@ fn width_ctrl_expand(
ctrl: WidthCtrl, ctrl: WidthCtrl,
recs: &mut NuRecords, recs: &mut NuRecords,
cfg: &mut ColoredConfig, cfg: &mut ColoredConfig,
dims: &mut CompleteDimensionVecRecords, dims: &mut CompleteDimension,
) { ) {
let opt = Width::increase(ctrl.max_width); let opt = Width::increase(ctrl.max_width);
TableOption::<VecRecords<_>, _, _>::change(opt, recs, cfg, dims); TableOption::<VecRecords<_>, _, _>::change(opt, recs, cfg, dims);
@ -511,7 +511,7 @@ fn width_ctrl_truncate(
ctrl: WidthCtrl, ctrl: WidthCtrl,
recs: &mut NuRecords, recs: &mut NuRecords,
cfg: &mut ColoredConfig, cfg: &mut ColoredConfig,
dims: &mut CompleteDimensionVecRecords, dims: &mut CompleteDimension,
) { ) {
for (col, (&width, width_original)) in ctrl for (col, (&width, width_original)) in ctrl
.width .width
@ -547,6 +547,7 @@ fn width_ctrl_truncate(
} }
fn align_table(table: &mut Table, alignments: Alignments, structure: &TableStructure) { fn align_table(table: &mut Table, alignments: Alignments, structure: &TableStructure) {
// note: IDK why it was originally here. Is it desirable? I maybe PerCell better?
table.with(AlignmentStrategy::PerLine); table.with(AlignmentStrategy::PerLine);
table.with(Alignment::from(alignments.data)); table.with(Alignment::from(alignments.data));
@ -559,9 +560,11 @@ fn align_table(table: &mut Table, alignments: Alignments, structure: &TableStruc
} }
if structure.with_header { if structure.with_header {
table.modify(Rows::first(), AlignmentStrategy::PerCell);
table.modify(Rows::first(), Alignment::from(alignments.header)); table.modify(Rows::first(), Alignment::from(alignments.header));
if structure.with_footer { if structure.with_footer {
table.modify(Rows::last(), AlignmentStrategy::PerCell);
table.modify(Rows::last(), Alignment::from(alignments.header)); table.modify(Rows::last(), Alignment::from(alignments.header));
} }
} }
@ -965,8 +968,8 @@ fn convert_alignment(alignment: nu_color_config::Alignment) -> AlignmentHorizont
// TODO: expose it get_dims_mut() // TODO: expose it get_dims_mut()
struct SetDimensions(Vec<usize>); struct SetDimensions(Vec<usize>);
impl<R> TableOption<R, ColoredConfig, CompleteDimensionVecRecords<'_>> for SetDimensions { impl<R> TableOption<R, ColoredConfig, CompleteDimension<'_>> for SetDimensions {
fn change(self, _: &mut R, _: &mut ColoredConfig, dims: &mut CompleteDimensionVecRecords<'_>) { fn change(self, _: &mut R, _: &mut ColoredConfig, dims: &mut CompleteDimension<'_>) {
dims.set_widths(self.0); dims.set_widths(self.0);
} }
} }
@ -981,7 +984,7 @@ fn build_width(records: &NuRecords, pad: usize) -> Vec<usize> {
cfg.set_padding(Entity::Global, padding); cfg.set_padding(Entity::Global, padding);
SpannedGridDimension::width(records, &cfg) PeekableGridDimension::width(records, &cfg)
} }
// It's laverages a use of guuaranted cached widths before hand // It's laverages a use of guuaranted cached widths before hand
@ -998,32 +1001,27 @@ impl SetLineHeaders {
} }
} }
impl TableOption<NuRecords, ColoredConfig, CompleteDimensionVecRecords<'_>> for SetLineHeaders { impl TableOption<NuRecords, ColoredConfig, CompleteDimension<'_>> for SetLineHeaders {
fn change( fn change(
self, self,
recs: &mut NuRecords, recs: &mut NuRecords,
cfg: &mut ColoredConfig, cfg: &mut ColoredConfig,
dims: &mut CompleteDimensionVecRecords<'_>, dims: &mut CompleteDimension<'_>,
) { ) {
let widths = match dims.get_widths() { if dims.is_empty() {
Some(widths) => widths,
None => {
// we don't have widths cached; which means that NO width adjustments were done // we don't have widths cached; which means that NO width adjustments were done
// which means we are OK to leave columns as they are. // which means we are OK to leave columns as they are.
// //
// but we actually always have to have widths at this point // but we actually always have to have widths at this point
unreachable!("must never be the case"); unreachable!("must never be the case");
} }
};
let columns: Vec<_> = self let mut columns = self.head.values;
.head for (i, name) in columns.iter_mut().enumerate() {
.values let width = dims.get_width(i);
.into_iter() let width = width - self.pad;
.zip(widths.iter().cloned()) // it must be always safe to do *name = Truncate::truncate(name, width).into_owned();
.map(|(s, width)| Truncate::truncate(&s, width - self.pad).into_owned()) }
.collect();
let mut names = ColumnNames::new(columns) let mut names = ColumnNames::new(columns)
.line(self.line) .line(self.line)
@ -1045,17 +1043,3 @@ fn theme_copy_horizontal_line(theme: &mut tabled::settings::Theme, from: usize,
theme.insert_horizontal_line(to, *line); theme.insert_horizontal_line(to, *line);
} }
} }
// todo: create a method
#[derive(Debug, Default)]
struct GetDims(Vec<usize>);
impl<R, C> TableOption<R, C, CompleteDimensionVecRecords<'_>> for &mut GetDims {
fn change(self, _: &mut R, _: &mut C, dims: &mut CompleteDimensionVecRecords<'_>) {
self.0 = dims.get_widths().expect("expected to get it").to_vec();
}
fn hint_change(&self) -> Option<Entity> {
None
}
}

View File

@ -201,7 +201,7 @@ fn expand_list(input: &[Value], cfg: Cfg<'_>) -> TableResult {
let value = NuRecordsValue::new(cell.text); let value = NuRecordsValue::new(cell.text);
data[row].push(value); data[row].push(value);
data_styles.insert((row, with_index as usize), cell.style); data_styles.insert(Position::new(row, with_index as usize), cell.style);
rows_count = rows_count.saturating_add(cell.size); rows_count = rows_count.saturating_add(cell.size);
} }
@ -288,7 +288,10 @@ fn expand_list(input: &[Value], cfg: Cfg<'_>) -> TableResult {
let value = NuRecordsValue::new(cell.text); let value = NuRecordsValue::new(cell.text);
data[row + 1].push(value); data[row + 1].push(value);
data_styles.insert((row + 1, col + with_index as usize), cell.style); data_styles.insert(
Position::new(row + 1, col + with_index as usize),
cell.style,
);
column_rows = column_rows.saturating_add(cell.size); column_rows = column_rows.saturating_add(cell.size);
} }

View File

@ -1,6 +1,7 @@
use nu_color_config::TextStyle; use nu_color_config::TextStyle;
use nu_engine::column::get_columns; use nu_engine::column::get_columns;
use nu_protocol::{Config, Record, ShellError, Value}; use nu_protocol::{Config, Record, ShellError, Value};
use tabled::grid::config::Position;
use crate::{ use crate::{
clean_charset, colorize_space, clean_charset, colorize_space,
@ -111,7 +112,7 @@ fn create_table_with_header(
for (col, header) in headers.iter().enumerate() { for (col, header) in headers.iter().enumerate() {
let (text, style) = get_string_value_with_header(item, header.as_ref(), opts); let (text, style) = get_string_value_with_header(item, header.as_ref(), opts);
let pos = (row + 1, col); let pos = Position::new(row + 1, col);
table.insert(pos, text); table.insert(pos, text);
table.insert_style(pos, style); table.insert_style(pos, style);
} }
@ -142,12 +143,12 @@ fn create_table_with_header_and_index(
check_value(item)?; check_value(item)?;
let text = get_table_row_index(item, opts.config, row, row_offset); let text = get_table_row_index(item, opts.config, row, row_offset);
table.insert((row + 1, 0), text); table.insert(Position::new(row + 1, 0), text);
for (col, header) in headers.iter().enumerate().skip(1) { for (col, header) in headers.iter().enumerate().skip(1) {
let (text, style) = get_string_value_with_header(item, header.as_ref(), opts); let (text, style) = get_string_value_with_header(item, header.as_ref(), opts);
let pos = (row + 1, col); let pos = Position::new(row + 1, col);
table.insert(pos, text); table.insert(pos, text);
table.insert_style(pos, style); table.insert_style(pos, style);
} }
@ -169,7 +170,7 @@ fn create_table_with_no_header(
let (text, style) = get_string_value(item, opts); let (text, style) = get_string_value(item, opts);
let pos = (row, 0); let pos = Position::new(row, 0);
table.insert(pos, text); table.insert(pos, text);
table.insert_style(pos, style); table.insert_style(pos, style);
} }
@ -190,11 +191,11 @@ fn create_table_with_no_header_and_index(
check_value(item)?; check_value(item)?;
let text = get_table_row_index(item, opts.config, row, row_offset); let text = get_table_row_index(item, opts.config, row, row_offset);
table.insert((row, 0), text); table.insert(Position::new(row, 0), text);
let (text, style) = get_string_value(item, opts); let (text, style) = get_string_value(item, opts);
let pos = (row, 1); let pos = Position::new(row, 1);
table.insert(pos, text); table.insert(pos, text);
table.insert_style(pos, style); table.insert_style(pos, style);
} }