mirror of
https://gitlab.com/arnekeller/ascii-table.git
synced 2024-12-04 21:49:08 +00:00
save game
This commit is contained in:
parent
cc8b6b5223
commit
d3c20f6ff9
25
src/lib.rs
25
src/lib.rs
@ -171,7 +171,7 @@ impl AsciiTable {
|
|||||||
let header = self.stringify_header(num_cols);
|
let header = self.stringify_header(num_cols);
|
||||||
let data = self.square_data(data, num_cols);
|
let data = self.square_data(data, num_cols);
|
||||||
let has_header = header.iter().any(|text| !text.is_empty());
|
let has_header = header.iter().any(|text| !text.is_empty());
|
||||||
let widths = self.column_widths(&data, num_cols);
|
let widths = self.column_widths(&header, &data, num_cols);
|
||||||
|
|
||||||
let mut result = String::new();
|
let mut result = String::new();
|
||||||
result.push_str(&self.format_first(&widths));
|
result.push_str(&self.format_first(&widths));
|
||||||
@ -225,12 +225,12 @@ impl AsciiTable {
|
|||||||
data
|
data
|
||||||
}
|
}
|
||||||
|
|
||||||
fn column_widths(&self, data: &[Vec<SmartString>], num_cols: usize) -> Vec<usize> {
|
fn column_widths(&self, header: &[SmartString], data: &[Vec<SmartString>], num_cols: usize) -> Vec<usize> {
|
||||||
let result: Vec<_> = (0..num_cols).map(|a| {
|
let result: Vec<_> = (0..num_cols).map(|a| {
|
||||||
let default_conf = &DEFAULT_COLUMN;
|
let default_conf = &DEFAULT_COLUMN;
|
||||||
let conf = self.columns.get(&a).unwrap_or(default_conf);
|
let conf = self.columns.get(&a).unwrap_or(default_conf);
|
||||||
let column_width = data.iter().map(|row| row[a].char_len()).max().unwrap();
|
let column_width = data.iter().map(|row| row[a].char_len()).max().unwrap();
|
||||||
let header_width = conf.header.chars().count();
|
let header_width = header[a].char_len();
|
||||||
column_width.max(header_width).min(conf.max_width)
|
column_width.max(header_width).min(conf.max_width)
|
||||||
}).collect();
|
}).collect();
|
||||||
self.truncate_widths(result)
|
self.truncate_widths(result)
|
||||||
@ -345,25 +345,6 @@ impl SmartString {
|
|||||||
|
|
||||||
fn from<T>(string: T) -> Self
|
fn from<T>(string: T) -> Self
|
||||||
where T: Display {
|
where T: Display {
|
||||||
// TODO:
|
|
||||||
// let mut count = 0;
|
|
||||||
// let mut block = false;
|
|
||||||
// let mut iter = cell.chars().peekable();
|
|
||||||
// while let Some(ch) = iter.next() {
|
|
||||||
// if block {
|
|
||||||
// if ch != '\u{1b}' && ch != '[' && ch != ';' && ch != 'm' && !('0'..'9').contains(&ch) {
|
|
||||||
// block = false;
|
|
||||||
// count += 1;
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// if ch == '\u{1b}' && Some(&'[') == iter.peek() {
|
|
||||||
// block = true;
|
|
||||||
// } else {
|
|
||||||
// count += 1;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// count
|
|
||||||
let string = string.to_string();
|
let string = string.to_string();
|
||||||
let mut fragments = Vec::new();
|
let mut fragments = Vec::new();
|
||||||
let mut visible = true;
|
let mut visible = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user