emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/minibar 45824cb137 17/17: Simplify character choosing logi


From: ELPA Syncer
Subject: [nongnu] elpa/minibar 45824cb137 17/17: Simplify character choosing logic in CPU module
Date: Sun, 27 Nov 2022 16:01:38 -0500 (EST)

branch: elpa/minibar
commit 45824cb137816b50a63f5653096af6ef04ad51a3
Author: Akib Azmain Turja <akib@disroot.org>
Commit: Akib Azmain Turja <akib@disroot.org>

    Simplify character choosing logic in CPU module
---
 minibar.el | 64 +++++++++++++++++++++++---------------------------------------
 1 file changed, 24 insertions(+), 40 deletions(-)

diff --git a/minibar.el b/minibar.el
index 983b3ff58b..fc78ddb07c 100644
--- a/minibar.el
+++ b/minibar.el
@@ -137,9 +137,7 @@ a string to display, or nil in case there is to show."
 ;;;###autoload
 (define-minor-mode minibar-mode
   "Toggle Minibar display."
-  :init-value nil
   :lighter " Minibar"
-  :keymap nil
   :global t
   (if minibar-mode
       (progn
@@ -436,50 +434,36 @@ when it was recorded.")
         (format
          "%3i%%%s"
          (minibar--module-cpu-calculate-load "cpu")
-         (if (or (char-displayable-p ?█)  ; #x2588
-                 (char-displayable-p ?▇)  ; #x2587
-                 (char-displayable-p ?▆)  ; #x2586
-                 (char-displayable-p ?▅)  ; #x2585
-                 (char-displayable-p ?▄)  ; #x2584
-                 (char-displayable-p ?▃)  ; #x2583
-                 (char-displayable-p ?▂)  ; #x2582
-                 (char-displayable-p ?▁)) ; #x2581
+         (if (seq-some #'char-displayable-p
+                       ;; Characters ▁▂▃▄▅▆▇█
+                       (number-sequence #x2581 #x2588))
              (concat
               " "
               (mapconcat
                (lambda (i)
                  (let ((load (minibar--module-cpu-calculate-load
                               (format "cpu%i" i))))
-                   (cond
-                    ((and (char-displayable-p ?█)  ; #x2588
-                          (>= load 87.5))
-                     (propertize "█" 'face 'bold))
-                    ((and (char-displayable-p ?▇)  ; #x2587
-                          (>= load 75))
-                     (propertize "▇" 'face 'bold))
-                    ((and (char-displayable-p ?▆)  ; #x2586
-                          (>= load 62.5))
-                     (propertize "▆" 'face 'bold))
-                    ((and (char-displayable-p ?▅)  ; #x2585
-                          (>= load 50))
-                     (propertize "▅" 'face 'bold))
-                    ((and (char-displayable-p ?▄)  ; #x2584
-                          (>= load 37.5))
-                     (propertize "▄" 'face 'bold))
-                    ((and (char-displayable-p ?▃)  ; #x2583
-                          (>= load 25))
-                     (propertize "▃" 'face 'bold))
-                    ((and (char-displayable-p ?▂)  ; #x2582
-                          (>= load 12.5))
-                     (propertize "▂" 'face 'bold))
-                    (t ; (char-displayable-p ?▁) => t
-                     (propertize
-                      (if (char-displayable-p ?▁)  ;  #x2581
-                          "▁"
-                        " ")
-                      'face
-                      '( :weight bold
-                         :inherit font-lock-comment-face))))))
+                   (let ((char (seq-some
+                                (lambda (e)
+                                  (and (>= load (car e))
+                                       (char-displayable-p (cdr e))
+                                       (cdr e)))
+                                '((87.5 . ?█)     ; #x2588
+                                  (75 . ?▇)       ; #x2587
+                                  (62.5 . ?▆)     ; #x2586
+                                  (50 . ?▅)       ; #x2585
+                                  (37.5 . ?▄)     ; #x2584
+                                  (25  . ?▃)      ; #x2583
+                                  (12.5 . ?▂))))) ; #x2582
+                     (if char
+                         (propertize (string char) 'face 'bold)
+                       (propertize
+                        (if (char-displayable-p ?▁)  ;  #x2581
+                            "▁"
+                          " ")
+                        'face
+                        '( :weight bold
+                           :inherit font-lock-comment-face))))))
                (number-sequence 0 (1- minibar--module-cpu-count)) ""))
            "")))
       (current-time))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]