summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2022-05-18 11:41:37 +0200
committerCanop <cano.petrole@gmail.com>2022-05-18 11:44:19 +0200
commit83be8c6d67df64a902717ddbd3d8ef78648aa992 (patch)
treef0f1b87552145bc93568be72e99bbfab1f420ac3
parent70f4d09aab75c7610e34bde855f4cd28ce691954 (diff)
Format counts of files with thousands separator
Fix #549
-rw-r--r--CHANGELOG.md1
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--bacon.toml7
-rw-r--r--src/display/displayable_tree.rs7
-rw-r--r--src/display/mod.rs1
-rw-r--r--src/display/num_format.rs25
7 files changed, 40 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8cdc4e4..79bae8d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,6 @@
### next
- close the staging area when it's emptied with a verb (e.g. on `:rm`)
+- format files counts with thousands separator - Fix #549
### v1.12.0 - 2022-05-05
<a name="v1.12.0"></a>
diff --git a/Cargo.lock b/Cargo.lock
index 3dea51c..22050aa 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -140,7 +140,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "broot"
-version = "1.12.0"
+version = "1.13.0-dev"
dependencies = [
"ahash 0.7.6",
"ansi_colours",
diff --git a/Cargo.toml b/Cargo.toml
index 126bd66..578fe08 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "broot"
-version = "1.12.0"
+version = "1.13.0-dev"
authors = ["dystroy <denys.seguret@gmail.com>"]
repository = "https://github.com/Canop/broot"
documentation = "https://dystroy.org/broot"
diff --git a/bacon.toml b/bacon.toml
index 3eaaf7a..edd22ae 100644
--- a/bacon.toml
+++ b/bacon.toml
@@ -46,3 +46,10 @@ need_stdout = false
command = ["cargo", "test", "--color", "always"]
need_stdout = true
+[keybindings]
+a = "job:check-all"
+i = "job:initial"
+c = "job:clippy"
+d = "job:doc-open"
+t = "job:test"
+r = "job:run"
diff --git a/src/display/displayable_tree.rs b/src/display/displayable_tree.rs
index f1a827c..9b6ad5e 100644
--- a/src/display/displayable_tree.rs
+++ b/src/display/displayable_tree.rs
@@ -4,8 +4,9 @@ use {
Col,
CropWriter,
GitStatusDisplay,
- SPACE_FILLING, BRANCH_FILLING,
MatchedString,
+ num_format::format_count,
+ SPACE_FILLING, BRANCH_FILLING,
},
crate::{
app::AppState,
@@ -106,7 +107,7 @@ impl<'a, 's, 't> DisplayableTree<'a, 's, 't> {
) -> Result<usize, termimad::Error> {
Ok(if let Some(s) = line.sum {
cond_bg!(count_style, self, selected, self.skin.count);
- let s = s.to_count();
+ let s = format_count(s.to_count());
cw.queue_g_string(count_style, format!("{s:>count_len$}"))?;
1
} else {
@@ -483,7 +484,7 @@ impl<'a, 's, 't> DisplayableTree<'a, 's, 't> {
.skip(1) // we don't show the counts of the root
.map(|l| l.sum.map_or(0, |s| s.to_count()))
.max()
- .map(|c| format!("{}", c).len())
+ .map(|c| format_count(c).len())
.unwrap_or(0)
} else {
0
diff --git a/src/display/mod.rs b/src/display/mod.rs
index 0f8f3c1..702aa90 100644
--- a/src/display/mod.rs
+++ b/src/display/mod.rs
@@ -28,6 +28,7 @@ mod git_status_display;
pub mod flags_display;
pub mod status_line;
mod matched_string;
+mod num_format;
mod screen;
mod cell_size;
diff --git a/src/display/num_format.rs b/src/display/num_format.rs
new file mode 100644
index 0000000..d8f5bc5
--- /dev/null
+++ b/src/display/num_format.rs
@@ -0,0 +1,25 @@
+
+/// Format a number with commas as thousands separators
+pub fn format_count(count: usize) -> String {
+ let mut s = count.to_string();
+ let l = s.len();
+ for i in 1..l {
+ if i % 3 == 0 {
+ s.insert(l-i, ',');
+ }
+ }
+ s
+}
+
+#[test]
+fn test_format_count() {
+ assert_eq!(&format_count(1), "1");
+ assert_eq!(&format_count(12), "12");
+ assert_eq!(&format_count(123), "123");
+ assert_eq!(&format_count(1234), "1,234");
+ assert_eq!(&format_count(12345), "12,345");
+ assert_eq!(&format_count(123456), "123,456");
+ assert_eq!(&format_count(1234567), "1,234,567");
+ assert_eq!(&format_count(12345678), "12,345,678");
+ assert_eq!(&format_count(1234567890), "1,234,567,890");
+}