Cybrkyd's git repositories

gedit-statusbar-wordcount-plugin • commit: 9f9618d

commit 9f9618d6328fc3d5b33e4f158c405109f9f50f09d11b5757d824779a9f9589c2
author cybrkyd <116197215+cybrkyd@users.noreply.github.com> 2025-08-28 09:39:14 +0100
committer cybrkyd <116197215+cybrkyd@users.noreply.github.com> 2025-08-28 09:39:14 +0100

Commit Message

Formatting displayed counts with thousands separators

📊 Diffstat

wordcount.py 9
1 files changed, 8 insertions(+), 1 deletions(-)

Diff

diff --git a/wordcount.py b/wordcount.py
index 3c9d566..4053dbc 100644
--- a/wordcount.py
+++ b/wordcount.py
@@ -11,6 +11,9 @@ def get_text(doc):
except Exception:
return ""
+ def format_with_thousands_separator(number):
+ return f"{number:,}"
+
class WordcountPlugin(GObject.Object, Gedit.WindowActivatable):
__gtype_name__ = "WordcountPlugin"
window = GObject.property(type=Gedit.Window)
@@ -75,6 +78,10 @@ class WordcountPlugin(GObject.Object, Gedit.WindowActivatable):
text = get_text(doc)
word_count = len(WORD_RE.findall(text))
char_count = len(text)
- self._label.set_text(f"words: {word_count} | chars: {char_count}")
+ formatted_words = format_with_thousands_separator(word_count)
+ formatted_chars = format_with_thousands_separator(char_count)
+
+ self._label.set_text(f"words: {formatted_words} | chars: {formatted_chars}")
except Exception as e:
self._label.set_text(f"error: {e}")
+