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"
checksum = "1cf4578926a981ab0ca955dc023541d19de37112bc24c1a197bd806d3d86ad1d"
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]]
@ -115,6 +124,16 @@ dependencies = [
"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]]
name = "anstream"
version = "0.6.18"
@ -3772,7 +3791,7 @@ dependencies = [
name = "nu-explore"
version = "0.103.1"
dependencies = [
"ansi-str",
"ansi-str 0.8.0",
"anyhow",
"crossterm",
"log",
@ -4590,14 +4609,14 @@ checksum = "fb37767f6569cd834a413442455e0f066d0d522de8630436e2a1761d9726ba56"
[[package]]
name = "papergrid"
version = "0.13.0"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2b0f8def1f117e13c895f3eda65a7b5650688da29d6ad04635f61bc7b92eebd"
checksum = "30268a8d20c2c0d126b2b6610ab405f16517f6ba9f244d8c59ac2c512a8a1ce7"
dependencies = [
"ansi-str",
"ansitok",
"ahash",
"ansi-str 0.9.0",
"ansitok 0.3.0",
"bytecount",
"fnv",
"unicode-width 0.2.0",
]
@ -7041,13 +7060,14 @@ dependencies = [
[[package]]
name = "tabled"
version = "0.17.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6709222f3973137427ce50559cd564dc187a95b9cfe01613d2f4e93610e510a"
checksum = "228d124371171cd39f0f454b58f73ddebeeef3cef3207a82ffea1c29465aea43"
dependencies = [
"ansi-str",
"ansitok",
"ansi-str 0.9.0",
"ansitok 0.3.0",
"papergrid",
"testing_table",
]
[[package]]
@ -7121,6 +7141,16 @@ version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "textwrap"
version = "0.16.1"
@ -7886,6 +7916,16 @@ dependencies = [
"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]]
name = "vte_generate_state_changes"
version = "0.1.2"

View File

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

View File

@ -1,13 +1,14 @@
// note: Seems like could be simplified
// 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::Value;
use nu_table::{string_width, string_wrap};
use tabled::{
grid::config::ColoredConfig,
settings::{peaker::Priority, width::Wrap, Settings, Style},
settings::{peaker::Priority, width::Wrap, Style},
Table,
};
@ -60,13 +61,12 @@ pub fn build_table(
desc_table.with(Style::rounded().remove_bottom().remove_horizontals());
let mut val_table = Table::from_iter(data);
val_table.with(
Settings::default()
.with(Style::rounded().corner_top_left('├').corner_top_right('┤'))
.with(SetWidths(widths))
.with(Wrap::new(width).priority(Priority::max(true)))
.with(SetHorizontalChar::new('┼', '┴', 11 + 2 + 1)),
);
val_table.with(Style::rounded().corner_top_left('├').corner_top_right('┤'));
val_table.get_dimension_mut().set_widths(widths);
val_table.with((
Wrap::new(width).priority(Priority::max(true)),
SetHorizontalChar::new('┼', '┴', 11 + 2 + 1),
));
format!("{desc_table}\n{val_table}")
}
@ -315,8 +315,8 @@ mod util {
mod global_horizontal_char {
use tabled::{
grid::{
config::{ColoredConfig, Offset},
dimension::{CompleteDimensionVecRecords, Dimension},
config::{ColoredConfig, Offset, Position},
dimension::{CompleteDimension, Dimension},
records::{ExactRecords, Records},
},
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
{
fn change(
self,
records: &mut R,
cfg: &mut ColoredConfig,
dimension: &mut CompleteDimensionVecRecords<'_>,
dimension: &mut CompleteDimension<'_>,
) {
let count_columns = records.count_columns();
let count_rows = records.count_rows();
@ -358,17 +358,21 @@ mod global_horizontal_char {
let has_vertical = cfg.has_vertical(0, count_columns);
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);
cfg.set_border((0, 0), border);
cfg.set_border(Position::new(0, 0), border);
return;
}
let mut i = 1;
for (col, width) in widths.into_iter().enumerate() {
if self.index < i + width {
let o = self.index - i;
cfg.set_horizontal_char((0, col), self.split, Offset::Begin(o));
let offset = self.index - i;
cfg.set_horizontal_char(
Position::new(0, col),
Offset::Start(offset),
self.split,
);
return;
}
@ -377,9 +381,10 @@ mod global_horizontal_char {
let has_vertical = cfg.has_vertical(col, count_columns);
if has_vertical {
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);
cfg.set_border((0, col), border);
cfg.set_border(Position::new(0, col), border);
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];
for (col, width) in widths.iter_mut().enumerate() {
*width = dims.get_width(col);
@ -398,23 +403,3 @@ mod global_horizontal_char {
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"
));
_print_lines(&actual.out, 80);
let expected = join_lines([
"╭──────────────────┬───────────────────────────────────────────────────────────╮",
"│ │ ╭───────────────┬───────────────────────────────────────╮ │",
"│ package │ │ │ ╭───┬───────────────────────────────╮ │ │",
"│ │ │ authors │ │ 0 │ The Nushell Project │ │",
"│ │ │ │ │ │ Developers │ │",
"│ │ │ │ ╰───┴───────────────────────────────╯ │ │",
"│ package │ │ │ ╭───┬────────────────────── │ │",
"│ │ │ authors │ │ 0 │ The Nushell Project │ │",
"│ │ │ │ │ │ Developers │ │",
"│ │ │ │ ╰───┴────────────────────── │ │",
"│ │ │ default-run │ nu │ │",
"│ │ │ description │ A new type of shell │ │",
"│ │ │ documentation │ https://www.nushell.sh/book/ │ │",
@ -688,21 +690,21 @@ fn test_expand_big_0() {
"│ │ │ │ ╭──────────┬────────────────────────╮ │ │",
"│ │ │ metadata │ │ │ ╭───────────┬────────╮ │ │ │",
"│ │ │ │ │ binstall │ │ pkg-url │ { repo │ │ │ │",
"│ │ │ │ │ │ │ │ }/rel │ │ │ │",
"│ │ │ │ │ │ │ │ eases/ │ │ │ │",
"│ │ │ │ │ │ │ │ downlo │ │ │ │",
"│ │ │ │ │ │ │ │ ad/{ v │ │ │ │",
"│ │ │ │ │ │ │ │ ersion │ │ │ │",
"│ │ │ │ │ │ │ │ }/{ │ │ │ │",
"│ │ │ │ │ │ │ │ }/rele │ │ │ │",
"│ │ │ │ │ │ │ │ ases/d │ │ │ │",
"│ │ │ │ │ │ │ │ ownloa │ │ │ │",
"│ │ │ │ │ │ │ │ d/{ ve │ │ │ │",
"│ │ │ │ │ │ │ │ rsion │ │ │ │",
"│ │ │ │ │ │ │ │ }/{ │ │ │ │",
"│ │ │ │ │ │ │ │ name │ │ │ │",
"│ │ │ │ │ │ │ │ }-{ ve │ │ │ │",
"│ │ │ │ │ │ │ │ rsion │ │ │ │",
"│ │ │ │ │ │ │ │ }-{ │ │ │ │",
"│ │ │ │ │ │ │ │ target │ │ │ │",
"│ │ │ │ │ │ │ │ }.{ a │ │ │ │",
"│ │ │ │ │ │ │ │ rchive │ │ │ │",
"│ │ │ │ │ │ │ │ -forma │ │ │ │",
"│ │ │ │ │ │ │ │ t } │ │ │ │",
"│ │ │ │ │ │ │ │ }.{ ar │ │ │ │",
"│ │ │ │ │ │ │ │ chive- │ │ │ │",
"│ │ │ │ │ │ │ │ format │ │ │ │",
"│ │ │ │ │ │ │ │ } │ │ │ │",
"│ │ │ │ │ │ │ pkg-fmt │ tgz │ │ │ │",
"│ │ │ │ │ │ │ overrides │ {recor │ │ │ │",
"│ │ │ │ │ │ │ │ d 1 │ │ │ │",
@ -856,6 +858,8 @@ fn test_expand_big_0() {
"open sample.toml | table --expand --width=120"
));
_print_lines(&actual.out, 120);
let expected = join_lines([
"╭──────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────╮",
"│ │ ╭───────────────┬───────────────────────────────────────────────────────────────────────────────╮ │",
@ -948,7 +952,7 @@ fn test_expand_big_0() {
"│ │ │ │ │ dependencies │ │ │ ╭──────────┬─────────╮ │ │ │ │",
"│ │ │ │ │ │ │ openssl │ │ version │ 0.10.38 │ │ │ │ │",
"│ │ │ │ │ │ │ │ │ features │ [list 1 │ │ │ │ │",
"│ │ │ │ │ │ │ │ │ │ item] │ │ │ │ │",
"│ │ │ │ │ │ │ │ │ │ item] │ │ │ │ │",
"│ │ │ │ │ │ │ │ │ optional │ true │ │ │ │ │",
"│ │ │ │ │ │ │ │ ╰──────────┴─────────╯ │ │ │ │",
"│ │ │ │ │ │ │ signal-hook │ {record 2 fields} │ │ │ │",
@ -1185,19 +1189,19 @@ fn test_expand_big_0() {
"│ │ │ time │ 0.3.12 │ │",
"│ │ ╰───────────────┴───────────────────╯ │",
"│ target │ {record 3 fields} │",
"│ │ ╭──────────────────────────────────╮ │",
"│ dev-dependencies │ │ nu-test-support │ {record 2 │ │",
"│ │ │ │ fields} │ │",
"│ │ │ tempfile │ 3.2.0 │ │",
"│ │ │ assert_cmd │ 2.0.2 │ │",
"│ │ │ criterion │ 0.4 │ │",
"│ │ │ pretty_assertions │ 1.0.0 │ │",
"│ │ │ serial_test │ 0.10.0 │ │",
"│ │ │ hamcrest2 │ 0.3.0 │ │",
"│ │ │ rstest │ {record 2 │ │",
"│ │ │ │ fields} │ │",
"│ │ │ itertools │ 0.10.3 │ │",
"│ │ ╰──────────────────────────────────╯ │",
"│ │ ╭──────────────────────────────────╮ │",
"│ dev-dependencies │ │ nu-test-support │ {record 2 │ │",
"│ │ │ │ fields} │ │",
"│ │ │ tempfile │ 3.2.0 │ │",
"│ │ │ assert_cmd │ 2.0.2 │ │",
"│ │ │ criterion │ 0.4 │ │",
"│ │ │ pretty_assertions │ 1.0.0 │ │",
"│ │ │ serial_test │ 0.10.0 │ │",
"│ │ │ hamcrest2 │ 0.3.0 │ │",
"│ │ │ rstest │ {record 2 │ │",
"│ │ │ │ fields} │ │",
"│ │ │ itertools │ 0.10.3 │ │",
"│ │ ╰──────────────────────────────────╯ │",
"│ │ ╭─────────────────────┬─────────────╮ │",
"│ features │ │ │ ╭───┬─────╮ │ │",
"│ │ │ plugin │ │ 0 │ nu- │ │ │",
@ -1667,75 +1671,72 @@ fn table_expande_with_no_header_internally_0() {
"│ │ │ │ │ 0 │ completion_menu │ none │ tab │ ╭───┬───────╮ │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ ld} │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ │ │ │",
"│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │",
"│ │ │ │ │ 1 │ completion_previous │ shift │ backtab │ ╭───┬───────╮ │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ ld} │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ │ │ │",
"│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │",
"│ │ │ │ │ 2 │ history_menu │ control │ char_r │ emacs │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 2 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ s} │ │ │",
"│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ lds │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ 3 │ next_page │ control │ char_x │ emacs │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ 4 │ undo_or_previous_page │ control │ char_z │ emacs │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ 5 │ yank │ control │ char_y │ emacs │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ 6 │ unix-line-discard │ control │ char_u │ ╭───┬───────╮ │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ ld} │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ │ │ │",
"│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │",
"│ │ │ │ │ 7 │ kill-line │ control │ char_k │ ╭───┬───────╮ │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ ld} │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ │ │ │",
"│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │",
"│ │ │ │ │ 8 │ commands_menu │ control │ char_t │ ╭───┬───────╮ │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 2 │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ s} │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ lds │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │",
"│ │ │ │ │ 9 │ vars_menu │ alt │ char_o │ ╭───┬───────╮ │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 2 │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ s} │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ lds │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │",
"│ │ │ │ │ 10 │ commands_with_description │ control │ char_s │ ╭───┬───────╮ │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ 0 │ emacs │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ 1 │ vi_no │ │ d 2 │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ s} │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ rmal │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ 2 │ vi_in │ │ lds │ │ │",
"│ │ │ │ │ │ │ │ │ │ │ sert │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ ╰───┴───────╯ │ │ │ │",
"│ │ │ │ ╰────┴───────────────────────────┴──────────┴─────────┴───────────────┴─────╯ │ │",
"│ │ ╰──────────────────────────────────┴───────────────────────────────────────────────────────────────────────────────╯ │",
@ -1936,69 +1937,62 @@ fn table_expande_with_no_header_internally_1() {
"│ │ │ │ │ 0 │ completion_menu │ none │ tab │ [list 3 │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ items] │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ 1 │ completion_previous │ shift │ backtab │ [list 3 │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ items] │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ 2 │ history_menu │ control │ char_r │ emacs │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 2 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ s} │ │ │",
"│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ lds │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ 3 │ next_page │ control │ char_x │ emacs │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ 4 │ undo_or_previous_page │ control │ char_z │ emacs │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ 5 │ yank │ control │ char_y │ emacs │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ 6 │ unix-line-discard │ control │ char_u │ [list 3 │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ items] │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ 7 │ kill-line │ control │ char_k │ [list 3 │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ items] │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 1 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ ld} │ │ │",
"│ │ │ │ │ 8 │ commands_menu │ control │ char_t │ [list 3 │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ items] │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 2 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ s} │ │ │",
"│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ lds │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ 9 │ vars_menu │ alt │ char_o │ [list 3 │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ items] │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 2 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ s} │ │ │",
"│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ lds │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ │ 10 │ commands_with_description │ control │ char_s │ [list 3 │ {re │ │ │",
"│ │ │ │ │ │ │ │ │ items] │ cor │ │ │",
"│ │ │ │ │ │ │ │ │ │ d 2 │ │ │",
"│ │ │ │ │ │ │ │ │ │ fi │ │ │",
"│ │ │ │ │ │ │ │ │ │ eld │ │ │",
"│ │ │ │ │ │ │ │ │ │ s} │ │ │",
"│ │ │ │ │ │ │ │ │ │ fie │ │ │",
"│ │ │ │ │ │ │ │ │ │ lds │ │ │",
"│ │ │ │ │ │ │ │ │ │ } │ │ │",
"│ │ │ │ ╰────┴───────────────────────────┴──────────┴─────────┴──────────┴─────╯ │ │",
"│ │ ╰──────────────────────────────────┴──────────────────────────────────────────────────────────────────────────╯ │",
"╰────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯",
@ -2168,11 +2162,10 @@ fn test_collapse_big_0() {
"│ ├───────────────┼──────────┬───────────┬────────────────────┤",
"│ │ metadata │ binstall │ pkg-url │ { repo }/releases/ │",
"│ │ │ │ │ download/{ v │",
"│ │ │ │ │ ersion │",
"│ │ │ │ │ }/{ name }-{ vers │",
"│ │ │ │ │ ion }- │",
"│ │ │ │ │ { target }.{ │",
"│ │ │ │ │ archive-format } │",
"│ │ │ │ │ ersion }/{ name }- │",
"│ │ │ │ │ { version }- │",
"│ │ │ │ │ { target }.{ archi │",
"│ │ │ │ │ ve-format } │",
"│ │ │ ├───────────┼────────────────────┤",
"│ │ │ │ pkg-fmt │ tgz │",
"│ │ │ ├───────────┼────────────────────┤",

View File

@ -16,7 +16,7 @@ use tabled::{
config::{
AlignmentHorizontal, ColoredConfig, Entity, Indent, Position, Sides, SpannedConfig,
},
dimension::{CompleteDimensionVecRecords, SpannedGridDimension},
dimension::{CompleteDimension, Dimension, PeekableGridDimension},
records::{
vec_records::{Text, VecRecords},
ExactRecords, Records,
@ -85,7 +85,7 @@ impl NuTable {
}
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>) {
@ -331,8 +331,8 @@ fn remove_header(t: &mut NuTable) -> HeadInfo {
.alignments
.cells
.drain()
.filter(|(k, _)| k.0 != 0)
.map(|(k, v)| ((k.0 - 1, k.1), v))
.filter(|(k, _)| k.row != 0)
.map(|(k, v)| (k - (1, 0), v))
.collect();
t.alignments.header = AlignmentHorizontal::Center;
@ -341,8 +341,8 @@ fn remove_header(t: &mut NuTable) -> HeadInfo {
.styles
.cells
.drain()
.filter(|(k, _)| k.0 != 0)
.map(|(k, v)| ((k.0 - 1, k.1), v))
.filter(|(k, _)| k.row != 0)
.map(|(k, v)| (k - (1, 0), v))
.collect();
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(
self,
recs: &mut NuRecords,
cfg: &mut ColoredConfig,
dims: &mut CompleteDimensionVecRecords<'_>,
dims: &mut CompleteDimension<'_>,
) {
if self.width.truncate {
width_ctrl_truncate(self, recs, cfg, dims);
@ -501,7 +501,7 @@ fn width_ctrl_expand(
ctrl: WidthCtrl,
recs: &mut NuRecords,
cfg: &mut ColoredConfig,
dims: &mut CompleteDimensionVecRecords,
dims: &mut CompleteDimension,
) {
let opt = Width::increase(ctrl.max_width);
TableOption::<VecRecords<_>, _, _>::change(opt, recs, cfg, dims);
@ -511,7 +511,7 @@ fn width_ctrl_truncate(
ctrl: WidthCtrl,
recs: &mut NuRecords,
cfg: &mut ColoredConfig,
dims: &mut CompleteDimensionVecRecords,
dims: &mut CompleteDimension,
) {
for (col, (&width, width_original)) in ctrl
.width
@ -547,6 +547,7 @@ fn width_ctrl_truncate(
}
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(Alignment::from(alignments.data));
@ -559,9 +560,11 @@ fn align_table(table: &mut Table, alignments: Alignments, structure: &TableStruc
}
if structure.with_header {
table.modify(Rows::first(), AlignmentStrategy::PerCell);
table.modify(Rows::first(), Alignment::from(alignments.header));
if structure.with_footer {
table.modify(Rows::last(), AlignmentStrategy::PerCell);
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()
struct SetDimensions(Vec<usize>);
impl<R> TableOption<R, ColoredConfig, CompleteDimensionVecRecords<'_>> for SetDimensions {
fn change(self, _: &mut R, _: &mut ColoredConfig, dims: &mut CompleteDimensionVecRecords<'_>) {
impl<R> TableOption<R, ColoredConfig, CompleteDimension<'_>> for SetDimensions {
fn change(self, _: &mut R, _: &mut ColoredConfig, dims: &mut CompleteDimension<'_>) {
dims.set_widths(self.0);
}
}
@ -981,7 +984,7 @@ fn build_width(records: &NuRecords, pad: usize) -> Vec<usize> {
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
@ -998,32 +1001,27 @@ impl SetLineHeaders {
}
}
impl TableOption<NuRecords, ColoredConfig, CompleteDimensionVecRecords<'_>> for SetLineHeaders {
impl TableOption<NuRecords, ColoredConfig, CompleteDimension<'_>> for SetLineHeaders {
fn change(
self,
recs: &mut NuRecords,
cfg: &mut ColoredConfig,
dims: &mut CompleteDimensionVecRecords<'_>,
dims: &mut CompleteDimension<'_>,
) {
let widths = match dims.get_widths() {
Some(widths) => widths,
None => {
// 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.
//
// but we actually always have to have widths at this point
if dims.is_empty() {
// 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.
//
// 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
.head
.values
.into_iter()
.zip(widths.iter().cloned()) // it must be always safe to do
.map(|(s, width)| Truncate::truncate(&s, width - self.pad).into_owned())
.collect();
let mut columns = self.head.values;
for (i, name) in columns.iter_mut().enumerate() {
let width = dims.get_width(i);
let width = width - self.pad;
*name = Truncate::truncate(name, width).into_owned();
}
let mut names = ColumnNames::new(columns)
.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);
}
}
// 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);
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);
}
@ -288,7 +288,10 @@ fn expand_list(input: &[Value], cfg: Cfg<'_>) -> TableResult {
let value = NuRecordsValue::new(cell.text);
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);
}

View File

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

View File

@ -81,8 +81,8 @@ fn wrap_test() {
let tests = [
(15, Some("┏━━━━━━━┳━━━━━┓\n┃ 123 4 ┃ ... ┃\n┃ 5678 ┃ ┃\n┣━━━━━━━╋━━━━━┫\n┃ 0 ┃ ... ┃\n┃ 0 ┃ ... ┃\n┗━━━━━━━┻━━━━━┛")),
(21, Some("┏━━━━━━━━━━━┳━━━━━┓\n┃ 123 45678 ┃ ... ┃\n┣━━━━━━━━━━━╋━━━━━┫\n┃ 0 ┃ ... ┃\n┃ 0 ┃ ... ┃\n┗━━━━━━━━━━━┻━━━━━┛")),
(29, Some("┏━━━━━━━━━━━┳━━━━━━━━━┳━━━━━┓\n┃ 123 45678 ┃ qweqw e ┃ ... ┃\n┃ ┃ qwe ┃ ┃\n┣━━━━━━━━━━━╋━━━━━━━━━╋━━━━━┫\n┃ 0 ┃ 1 ┃ ... ┃\n┃ 0 ┃ 1 ┃ ... ┃\n┗━━━━━━━━━━━┻━━━━━━━━━┻━━━━━┛")),
(49, Some("┏━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━┓\n┃ 123 45678 ┃ qweqw eqwe ┃ xxx xx xx x xx ┃ ... ┃\n┃ ┃ ┃ x xx xx ┃ ┃\n┣━━━━━━━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━╋━━━━━┫\n┃ 0 ┃ 1 ┃ 2 ┃ ... ┃\n┃ 0 ┃ 1 ┃ 2 ┃ ... ┃\n┗━━━━━━━━━━━┻━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━┻━━━━━┛")),
(29, Some("┏━━━━━━━━━━━┳━━━━━━━━━┳━━━━━┓\n┃ 123 45678 ┃ qweqw e ┃ ... ┃\n┃ ┃ qwe ┃ ┃\n┣━━━━━━━━━━━╋━━━━━━━━━╋━━━━━┫\n┃ 0 ┃ 1 ┃ ... ┃\n┃ 0 ┃ 1 ┃ ... ┃\n┗━━━━━━━━━━━┻━━━━━━━━━┻━━━━━┛")),
(49, Some("┏━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━┓\n┃ 123 45678 ┃ qweqw eqwe ┃ xxx xx xx x xx ┃ ... ┃\n┃ ┃ ┃ x xx xx ┃ ┃\n┣━━━━━━━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━╋━━━━━┫\n┃ 0 ┃ 1 ┃ 2 ┃ ... ┃\n┃ 0 ┃ 1 ┃ 2 ┃ ... ┃\n┗━━━━━━━━━━━┻━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━┻━━━━━┛")),
];
test_trim(&tests, TrimStrategy::wrap(false));
@ -98,7 +98,7 @@ fn wrap_keep_words_test() {
(15, Some("┏━━━━━━━┳━━━━━┓\n┃ 123 ┃ ... ┃\n┃ 45678 ┃ ┃\n┣━━━━━━━╋━━━━━┫\n┃ 0 ┃ ... ┃\n┃ 0 ┃ ... ┃\n┗━━━━━━━┻━━━━━┛")),
(21, Some("┏━━━━━━━━━━━┳━━━━━┓\n┃ 123 45678 ┃ ... ┃\n┣━━━━━━━━━━━╋━━━━━┫\n┃ 0 ┃ ... ┃\n┃ 0 ┃ ... ┃\n┗━━━━━━━━━━━┻━━━━━┛")),
(29, Some("┏━━━━━━━━━━━┳━━━━━━━━━┳━━━━━┓\n┃ 123 45678 ┃ qweqw ┃ ... ┃\n┃ ┃ eqwe ┃ ┃\n┣━━━━━━━━━━━╋━━━━━━━━━╋━━━━━┫\n┃ 0 ┃ 1 ┃ ... ┃\n┃ 0 ┃ 1 ┃ ... ┃\n┗━━━━━━━━━━━┻━━━━━━━━━┻━━━━━┛")),
(49, Some("┏━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━┓\n┃ 123 45678 ┃ qweqw eqwe ┃ xxx xx xx x xx ┃ ... ┃\n┃ ┃ ┃ x xx xx ┃ ┃\n┣━━━━━━━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━╋━━━━━┫\n┃ 0 ┃ 1 ┃ 2 ┃ ... ┃\n┃ 0 ┃ 1 ┃ 2 ┃ ... ┃\n┗━━━━━━━━━━━┻━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━┻━━━━━┛")),
(49, Some("┏━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━┓\n┃ 123 45678 ┃ qweqw eqwe ┃ xxx xx xx x xx ┃ ... ┃\n┃ ┃ ┃ x xx xx ┃ ┃\n┣━━━━━━━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━╋━━━━━┫\n┃ 0 ┃ 1 ┃ 2 ┃ ... ┃\n┃ 0 ┃ 1 ┃ 2 ┃ ... ┃\n┗━━━━━━━━━━━┻━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━┻━━━━━┛")),
];
test_trim(&tests, TrimStrategy::wrap(true));