mirror of
https://github.com/nushell/nushell.git
synced 2025-08-18 12:29:46 +02:00
Revert "Heuristic table view"
This commit is contained in:
@@ -14,7 +14,7 @@ impl RenderView for GenericView<'value> {
|
||||
match self.value {
|
||||
Value::Primitive(p) => Ok(host.stdout(&p.format(None))),
|
||||
Value::List(l) => {
|
||||
let view = TableView::from_list(l, false);
|
||||
let view = TableView::from_list(l);
|
||||
|
||||
if let Some(view) = view {
|
||||
view.render_view(host)?;
|
||||
|
@@ -26,13 +26,11 @@ impl TableView {
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn from_list(values: &[Tagged<Value>], full: bool) -> Option<TableView> {
|
||||
pub fn from_list(values: &[Tagged<Value>]) -> Option<TableView> {
|
||||
if values.len() == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let max_row: usize = termsize::get().map(|x| x.cols).unwrap() as usize;
|
||||
|
||||
let mut headers = TableView::merge_descriptors(values);
|
||||
|
||||
if headers.len() == 0 {
|
||||
@@ -63,75 +61,6 @@ impl TableView {
|
||||
if values.len() > 1 {
|
||||
headers.insert(0, format!("#"));
|
||||
}
|
||||
|
||||
// Trim if the row is too long
|
||||
let mut max_up_to_now = 0;
|
||||
|
||||
let num_headers = headers.len();
|
||||
let mut had_to_trim_off_rows = false;
|
||||
|
||||
for i in 0..num_headers {
|
||||
let mut max_entry = 0;
|
||||
|
||||
if (max_up_to_now + 8) >= max_row && !full {
|
||||
had_to_trim_off_rows = true;
|
||||
headers.pop();
|
||||
for j in 0..entries.len() {
|
||||
entries[j].pop();
|
||||
}
|
||||
} else {
|
||||
if i == (num_headers - 1) {
|
||||
let amount = max_row - std::cmp::min(max_row, max_up_to_now);
|
||||
if headers[i].len() > amount && !full {
|
||||
headers[i] = headers[i].chars().take(amount).collect::<String>();
|
||||
headers[i].push_str("...");
|
||||
}
|
||||
} else {
|
||||
if headers[i].len() > (max_row / num_headers) && !full {
|
||||
headers[i] = headers[i]
|
||||
.chars()
|
||||
.take(std::cmp::max(max_row / headers.len(), 5))
|
||||
.collect::<String>();
|
||||
headers[i].push_str("...");
|
||||
}
|
||||
}
|
||||
|
||||
if headers[i].len() > max_entry {
|
||||
max_entry = headers[i].len();
|
||||
}
|
||||
|
||||
for j in 0..entries.len() {
|
||||
if i == (num_headers - 1) {
|
||||
let amount = max_row - std::cmp::min(max_row, max_up_to_now);
|
||||
if entries[j][i].len() > amount && !full {
|
||||
entries[j][i] = entries[j][i].chars().take(amount).collect::<String>();
|
||||
entries[j][i].push_str("...");
|
||||
}
|
||||
} else {
|
||||
if entries[j][i].len() > (max_row / num_headers) && !full {
|
||||
entries[j][i] = entries[j][i]
|
||||
.chars()
|
||||
.take(std::cmp::max(max_row / headers.len(), 5))
|
||||
.collect::<String>();
|
||||
entries[j][i].push_str("...");
|
||||
}
|
||||
}
|
||||
if entries[j][i].len() > max_entry {
|
||||
max_entry = entries[j][i].len();
|
||||
}
|
||||
}
|
||||
|
||||
max_up_to_now += max_entry + 3;
|
||||
}
|
||||
}
|
||||
|
||||
if had_to_trim_off_rows {
|
||||
headers.push("...".to_string());
|
||||
for j in 0..entries.len() {
|
||||
entries[j].push("...".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
Some(TableView { headers, entries })
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user