From 1b7ccc31aa6e169c4b2a8819564595f90c09d509 Mon Sep 17 00:00:00 2001 From: Gerrit Viljoen Date: Sun, 17 May 2020 11:23:38 +0200 Subject: [PATCH] save game --- src/lib.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 94d4afa..f99e911 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -168,7 +168,7 @@ impl AsciiTable { return self.format_empty() } - let header = self.stringify_header(); + let header = self.stringify_header(num_cols); let data = self.square_data(data, num_cols); let has_header = header.iter().any(|text| !text.is_empty()); let widths = self.column_widths(&data, num_cols); @@ -209,12 +209,11 @@ impl AsciiTable { data.into_iter().map(|row| row.into_iter().map(|cell| SmartString::from(cell)).collect()).collect() } - fn stringify_header(&self) -> Vec { -// let default_conf = &DEFAULT_COLUMN; -// let header: Vec<_> = (0..num_cols).map(|a| -// &self.columns.get(&a).unwrap_or(default_conf).header -// ).collect(); - todo!() + fn stringify_header(&self, num_cols: usize) -> Vec { + let default_conf = &DEFAULT_COLUMN; + (0..num_cols).map(|a| + SmartString::from(&self.columns.get(&a).unwrap_or(default_conf).header) + ).collect() } fn square_data(&self, mut data: Vec>, num_cols: usize) -> Vec> { @@ -326,7 +325,6 @@ impl AsciiTable { fn format_cell(&self, text: &SmartString, len: usize, pad: char, align: Align) -> SmartString { if text.char_len() > len { -// let mut result: String = text.chars().take(len).collect(); let mut result = text.clone(); while result.char_len() > len { result.pop();