mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 03:34:58 +02:00
Fix table wrap emojie (#15138)
I did a naive fix; which is probably all right. But I want to spend some time to refactor a neighboring stuff. And it's yet not to be released I guess; I hope to add a few things beforehand. I've just opened it so you can verify that it must be addressed. close #15104, #14910, #15256
This commit is contained in:
@ -1,14 +1,17 @@
|
||||
// note: Seems like could be simplified
|
||||
// IMHO: it shall not take 300+ lines :)
|
||||
// TODO: Simplify
|
||||
// NOTE: Pool table could be used?
|
||||
// FIXME: `inspect` wrapping produces too much new lines with small terminal
|
||||
|
||||
use self::{global_horizontal_char::SetHorizontalChar, set_widths::SetWidths};
|
||||
use self::global_horizontal_char::SetHorizontalChar;
|
||||
use nu_protocol::Value;
|
||||
use nu_protocol::engine::EngineState;
|
||||
use nu_table::{string_width, string_wrap};
|
||||
use tabled::{
|
||||
Table,
|
||||
grid::config::ColoredConfig,
|
||||
settings::{Settings, Style, peaker::Priority, width::Wrap},
|
||||
settings::{Style, peaker::Priority, width::Wrap},
|
||||
};
|
||||
|
||||
pub fn build_table(
|
||||
@ -60,13 +63,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.get_dimension_mut().set_widths(widths);
|
||||
val_table.with(Style::rounded().corner_top_left('├').corner_top_right('┤'));
|
||||
val_table.with((
|
||||
Wrap::new(width).priority(Priority::max(true)),
|
||||
SetHorizontalChar::new('┼', '┴', 11 + 2 + 1),
|
||||
));
|
||||
|
||||
format!("{desc_table}\n{val_table}")
|
||||
}
|
||||
@ -315,10 +317,11 @@ mod util {
|
||||
}
|
||||
|
||||
mod global_horizontal_char {
|
||||
use nu_table::NuRecords;
|
||||
use tabled::{
|
||||
grid::{
|
||||
config::{ColoredConfig, Offset},
|
||||
dimension::{CompleteDimensionVecRecords, Dimension},
|
||||
config::{ColoredConfig, Offset, Position},
|
||||
dimension::{CompleteDimension, Dimension},
|
||||
records::{ExactRecords, Records},
|
||||
},
|
||||
settings::TableOption,
|
||||
@ -340,14 +343,12 @@ mod global_horizontal_char {
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Records + ExactRecords> TableOption<R, ColoredConfig, CompleteDimensionVecRecords<'_>>
|
||||
for SetHorizontalChar
|
||||
{
|
||||
impl TableOption<NuRecords, ColoredConfig, CompleteDimension> for SetHorizontalChar {
|
||||
fn change(
|
||||
self,
|
||||
records: &mut R,
|
||||
records: &mut NuRecords,
|
||||
cfg: &mut ColoredConfig,
|
||||
dimension: &mut CompleteDimensionVecRecords<'_>,
|
||||
dimension: &mut CompleteDimension,
|
||||
) {
|
||||
let count_columns = records.count_columns();
|
||||
let count_rows = records.count_rows();
|
||||
@ -360,9 +361,9 @@ 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;
|
||||
}
|
||||
|
||||
@ -370,7 +371,7 @@ mod global_horizontal_char {
|
||||
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));
|
||||
cfg.set_horizontal_char(Position::new(0, col), Offset::Start(o), self.split);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -379,9 +380,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;
|
||||
}
|
||||
|
||||
@ -391,7 +393,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);
|
||||
@ -400,23 +402,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -671,10 +671,10 @@ fn test_expand_big_0() {
|
||||
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/ │ │",
|
||||
@ -852,6 +852,8 @@ fn test_expand_big_0() {
|
||||
"╰──────────────────┴───────────────────────────────────────────────────────────╯",
|
||||
]);
|
||||
|
||||
_print_lines(&actual.out, 80);
|
||||
|
||||
assert_eq!(actual.out, expected);
|
||||
|
||||
let actual = nu!(
|
||||
@ -1045,6 +1047,8 @@ fn test_expand_big_0() {
|
||||
"╰──────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────╯",
|
||||
]);
|
||||
|
||||
_print_lines(&actual.out, 120);
|
||||
|
||||
assert_eq!(actual.out, expected);
|
||||
|
||||
let actual = nu!(
|
||||
@ -1188,19 +1192,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- │ │ │",
|
||||
@ -2624,11 +2628,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 │",
|
||||
"│ │ │ ├───────────┼────────────────────┤",
|
||||
|
Reference in New Issue
Block a user