File: replace-table_formatter.patch

package info (click to toggle)
rust-tokei 13.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 524 kB
  • sloc: makefile: 10
file content (92 lines) | stat: -rw-r--r-- 3,533 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
Description: Replace unavailable table_formatter with packaged comfy-table.
 Table formatting is only used to show the language table, i.e.
 `tokei --languages`, so this is rather self-contained.
Last-Update: 2024-10-16
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -166,2 +166,2 @@
-[dependencies.table_formatter]
-version = "0.6.1"
+[dependencies.comfy-table]
+version = "7"
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -343,3 +343,4 @@
-        use table_formatter::table::*;
-        use table_formatter::{cell, table};
-        let term_width = term_size::dimensions().map(|(w, _)| w).unwrap_or(75) - 8;
+        use comfy_table::{Cell, ColumnConstraint::UpperBoundary, Table, Width::Fixed};
+        let mut table = Table::new();
+        let term_width = terminal_size::terminal_size().map(|(terminal_size::Width(w), _)| w).unwrap_or(75) - 8;
+
@@ -352,43 +353,9 @@
-        let header = vec![
-            cell!(
-                "Language",
-                align = Align::Left,
-                padding = Padding::NONE,
-                width = Some(lang_w)
-            )
-            .with_formatter(vec![table_formatter::table::FormatterFunc::Normal(
-                Colorize::bold,
-            )]),
-            cell!(
-                "Extensions",
-                align = Align::Left,
-                padding = Padding::new(3, 0),
-                width = Some(suffix_w)
-            )
-            .with_formatter(vec![table_formatter::table::FormatterFunc::Normal(
-                Colorize::bold,
-            )]),
-        ];
-        let content = LanguageType::list()
-            .iter()
-            .map(|(key, ext)| {
-                vec![
-                    // table::TableCell::new(table::Cell::TextCell(key.name().to_string()))
-                    //     .with_width(lang_w),
-                    cell!(key.name()).with_width(Some(lang_w)),
-                    cell!(
-                        if matches!(key, LanguageType::Emojicode) {
-                            ext.join(", ") + "\u{200b}"
-                        } else if ext.is_empty() {
-                            "<None>".to_string()
-                        } else {
-                            ext.join(", ")
-                        },
-                        align = Align::Left,
-                        padding = Padding::new(3, 0),
-                        width = Some(suffix_w)
-                    ),
-                ]
-            })
-            .collect();
-        let t = table!(header - content with Border::ALL);
+        table.set_header(vec!["Language", "Extensions"]);
+        table
+            .column_mut(0)
+            .expect("language table should have 2 columns")
+            .set_constraint(UpperBoundary(Fixed(lang_w)));
+        table
+            .column_mut(1)
+            .expect("language table should have 2 columns")
+            .set_constraint(UpperBoundary(Fixed(suffix_w)));
@@ -396,3 +363,14 @@
-        let mut render_result = Vec::new();
-        t.render(&mut render_result)?;
-        println!("{}", String::from_utf8(render_result)?);
+        for (key, ext) in LanguageType::list() {
+            table.add_row(vec![
+                key.name().to_string(),
+                if matches!(key, LanguageType::Emojicode) {
+                    ext.join(", ") + "\u{200b}"
+                } else if ext.is_empty() {
+                    "<None>".to_string()
+                } else {
+                    ext.join(", ")
+                },
+            ]);
+        }
+
+        println!("{table}");