diff options
author | Alex <alex@adnab.me> | 2023-05-17 12:33:45 +0000 |
---|---|---|
committer | Alex <alex@adnab.me> | 2023-05-17 12:33:45 +0000 |
commit | c26a4308b4454e2f36e2824280b9f587a6918fa9 (patch) | |
tree | 3086149203b8cf9f0280c9b8e784eb893b0d7465 /src/util/formater.rs | |
parent | b66f247580dcfb733718949c35240500903a0802 (diff) | |
parent | 217d4299379b70d1b081cb88e208ab5f2d1808a7 (diff) | |
download | garage-c26a4308b4454e2f36e2824280b9f587a6918fa9.tar.gz garage-c26a4308b4454e2f36e2824280b9f587a6918fa9.zip |
Merge pull request 'Split format_table into separate crate and reduce k2v-client dependencies' (#572) from split-format-table into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/572
Diffstat (limited to 'src/util/formater.rs')
-rw-r--r-- | src/util/formater.rs | 32 |
1 files changed, 0 insertions, 32 deletions
diff --git a/src/util/formater.rs b/src/util/formater.rs deleted file mode 100644 index 2ea53ebb..00000000 --- a/src/util/formater.rs +++ /dev/null @@ -1,32 +0,0 @@ -pub fn format_table_to_string(data: Vec<String>) -> String { - let data = data - .iter() - .map(|s| s.split('\t').collect::<Vec<_>>()) - .collect::<Vec<_>>(); - - let columns = data.iter().map(|row| row.len()).fold(0, std::cmp::max); - let mut column_size = vec![0; columns]; - - let mut out = String::new(); - - for row in data.iter() { - for (i, col) in row.iter().enumerate() { - column_size[i] = std::cmp::max(column_size[i], col.chars().count()); - } - } - - for row in data.iter() { - for (col, col_len) in row[..row.len() - 1].iter().zip(column_size.iter()) { - out.push_str(col); - (0..col_len - col.chars().count() + 2).for_each(|_| out.push(' ')); - } - out.push_str(row[row.len() - 1]); - out.push('\n'); - } - - out -} - -pub fn format_table(data: Vec<String>) { - print!("{}", format_table_to_string(data)); -} |