[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/minibar 9d1a459684 04/17: Don't depend on minibuffer-line
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/minibar 9d1a459684 04/17: Don't depend on minibuffer-line |
Date: |
Sun, 27 Nov 2022 16:01:35 -0500 (EST) |
branch: elpa/minibar
commit 9d1a459684210a96c5206f686aa235a6eac72c07
Author: Akib Azmain Turja <akib@disroot.org>
Commit: Akib Azmain Turja <akib@disroot.org>
Don't depend on minibuffer-line
---
README.org | 5 ---
minibar.el | 111 ++++++++++++++++++++++++++++++++++---------------------------
2 files changed, 62 insertions(+), 54 deletions(-)
diff --git a/README.org b/README.org
index 01b56ed853..918c2ae9d4 100644
--- a/README.org
+++ b/README.org
@@ -32,8 +32,3 @@ First install =minibuffer-line= package from ELPA. Then
download
Enable ~minibar-mode~ to display Minibar. You may want to put
~(minibar-mode +1)~ in your init file. There are several user options you
can customize, use ~customize-group~ to see and possibly customize them.
-
-Minibar renders the status bar and it uses =minibuffer-line= package to
-show the line in echo area. To change the refresh rate, customize the
-~minibuffer-line-refresh-interval~ variable. To change the face, customize
-the ~minibuffer-line~ face.
diff --git a/minibar.el b/minibar.el
index 2ebcea2131..9c1be83056 100644
--- a/minibar.el
+++ b/minibar.el
@@ -4,7 +4,7 @@
;; Author: Akib Azmain Turja <akib@disroot.org>
;; Version: 0.1
-;; Package-Requires: ((emacs "27.2") minibuffer-line)
+;; Package-Requires: ((emacs "27.2"))
;; Keywords: calendar, hardware
;; URL: https://codeberg.org/akib/emacs-minibar
@@ -37,16 +37,9 @@
;; (minibar-mode +1) in your init file. There are several user options
;; you can customize, use `customize-group' to see and possibly customize
;; them.
-;;
-;; Minibar renders the status bar and it uses `minibuffer-line' package
-;; to show the line in echo area. To change the refresh rate, customize
-;; the `minibuffer-line-refresh-interval' variable. To change the face,
-;; customize the `minibuffer-line' face.
;;; Code:
-(require 'minibuffer-line)
-
(defgroup minibar nil
"Modular status bar in echo bar."
:group 'tools
@@ -82,44 +75,59 @@ The value should be a list of functions. Each function
should return a
string to display, or nil in case there is to show."
:type '(repeat function))
+(defcustom minibar-update-interval 1
+ "Update Minibar every this many seconds."
+ :type 'number)
+
+(defface minibar-face
+ '((t :inherit default))
+ "Default face of Minibar.")
+
+(defvar minibar--update-timer nil
+ "Timer to update Minibar.")
+
(defun minibar--render-group (modules)
"Render MODULES."
(mapconcat #'identity (delete nil (mapcar #'funcall modules))
minibar-module-separator))
;;;###autoload
-(defun minibar-render ()
- "Render Minibar."
- (with-temp-buffer
- (let ((bar "")
- (width (frame-width (window-frame (minibuffer-window))))
- (left (minibar--render-group
- minibar-group-left))
- (middle (minibar--render-group
- minibar-group-middle))
- (right (minibar--render-group
- minibar-group-right)))
-
- ;; HACK: Emacs doesn't show the last character on terminal, so
- ;; decrease the width by one in that case.
- (unless (display-graphic-p)
- (setq width (1- width)))
- (unless (zerop (length left))
- (setq bar (concat left minibar-group-separator)))
- (unless (zerop (length middle))
- (setq bar (concat bar (make-list
- (max 0 (- (/ (- width (length middle)) 2)
- (length bar)))
- ? )
- middle minibar-group-separator)))
- (unless (zerop (length right))
- (setq bar (concat bar (make-list
- (max 0 (- width (length right)
- (length bar)))
- ? )
- right)))
- (replace-regexp-in-string
- "%" "%%" (format (format "%%-%i.%is" width width) bar)))))
+(defun minibar--update ()
+ "Update Minibar."
+ (while-no-input
+ (with-temp-buffer
+ (let ((bar "")
+ (width (frame-width (window-frame (minibuffer-window))))
+ (left (minibar--render-group
+ minibar-group-left))
+ (middle (minibar--render-group
+ minibar-group-middle))
+ (right (minibar--render-group
+ minibar-group-right)))
+
+ ;; HACK: Emacs doesn't show the last character on terminal, so
+ ;; decrease the width by one in that case.
+ (unless (display-graphic-p)
+ (setq width (1- width)))
+ (unless (zerop (length left))
+ (setq bar (concat left minibar-group-separator)))
+ (unless (zerop (length middle))
+ (setq bar (concat bar (make-list
+ (max 0 (- (/ (- width (length middle)) 2)
+ (length bar)))
+ ? )
+ middle minibar-group-separator)))
+ (unless (zerop (length right))
+ (setq bar (concat bar (make-list
+ (max 0 (- width (length right)
+ (length bar)))
+ ? )
+ right)))
+ (let ((text (format (format "%%-%i.%is" width width) bar)))
+ (add-face-text-property 0 width 'minibar-face t text)
+ (with-current-buffer (get-buffer-create " *Minibuf-0*")
+ (erase-buffer)
+ (insert text)))))))
;;;###autoload
(define-minor-mode minibar-mode
@@ -130,12 +138,17 @@ string to display, or nil in case there is to show."
:global t
(if minibar-mode
(progn
- (setq minibuffer-line-format '(:eval (minibar-render)))
- (minibuffer-line-mode +1))
- (setq minibuffer-line-format
- (ignore-errors
- (eval (car (get 'minibuffer-line-format 'standard-value)))))
- (minibuffer-line-mode -1)))
+ (minibar--update)
+ (when minibar--update-timer
+ (cancel-timer minibar--update-timer))
+ (setq minibar--update-timer
+ (run-with-timer t minibar-update-interval
+ #'minibar--update)))
+ (when minibar--update-timer
+ (cancel-timer minibar--update-timer)
+ (setq minibar--update-timer nil))
+ (with-current-buffer (get-buffer-create " *Minibuf-0*")
+ (erase-buffer))))
(defcustom minibar-module-time-format "%a %b %d %H:%M"
"Time format for time module."
@@ -187,7 +200,7 @@ it was recorded.")
(alist-get ?m status))
60)))
(concat
- (if (and (< load 30)
+ (if (and (< load minibar-module-battery-low-threshold)
(not charging))
(propertize (format "%i%%" load) 'face
'minibar-module-battery-low-face)
@@ -233,7 +246,7 @@ The value is a cons cell whose car is the temperature and
cdr is the time
when it was recorded.")
(defun minibar-module-temperature ()
- "Module for showing CPU temperature"
+ "Module for showing CPU temperature."
(when (or (not minibar--module-temperature-cache)
(>= (float-time
(time-since (cdr minibar--module-temperature-cache)))
@@ -395,7 +408,7 @@ it was recorded.")
0.0))))
(defun minibar-module-cpu ()
- "Module for showing CPU loads."
+ "Module for showing CPU load."
(when (or (not minibar--module-cpu-cache)
(>= (float-time
(time-since (cdr minibar--module-cpu-cache)))
- [nongnu] elpa/minibar 8ecedf6d6c 02/17: Add COPYING, (continued)
- [nongnu] elpa/minibar 8ecedf6d6c 02/17: Add COPYING, ELPA Syncer, 2022/11/27
- [nongnu] elpa/minibar c995aec574 01/17: Add render and modules for time, CPU, temperature..., ELPA Syncer, 2022/11/27
- [nongnu] elpa/minibar 2bf88ae60a 05/17: While updating, don't exit on input, that doesn't work on Emacs 28, ELPA Syncer, 2022/11/27
- [nongnu] elpa/minibar 2c50c766dd 07/17: Rename minibar--update to minibar-update, ELPA Syncer, 2022/11/27
- [nongnu] elpa/minibar 5e8afde8f7 13/17: Don't run module functions in temp buffer, ELPA Syncer, 2022/11/27
- [nongnu] elpa/minibar 1da37a9286 12/17: Update install instructions, ELPA Syncer, 2022/11/27
- [nongnu] elpa/minibar 46f3307cc9 10/17: Fix wrong argument order, ELPA Syncer, 2022/11/27
- [nongnu] elpa/minibar 8775f1584c 09/17: Use idle timer, ELPA Syncer, 2022/11/27
- [nongnu] elpa/minibar 9d650e3c71 14/17: Fix group positioning in minibuffer, ELPA Syncer, 2022/11/27
- [nongnu] elpa/minibar 3913de72e0 15/17: Try to make all lines less than 75 characters width, ELPA Syncer, 2022/11/27
- [nongnu] elpa/minibar 9d1a459684 04/17: Don't depend on minibuffer-line,
ELPA Syncer <=
- [nongnu] elpa/minibar f228469970 06/17: Use char-displayable-p instead of display-graphic-p, ELPA Syncer, 2022/11/27
- [nongnu] elpa/minibar 0b02619c7f 11/17: Don't stop updating after first update after idle, ELPA Syncer, 2022/11/27
- [nongnu] elpa/minibar 45824cb137 17/17: Simplify character choosing logic in CPU module, ELPA Syncer, 2022/11/27
- [nongnu] elpa/minibar 37699eb25e 08/17: Don't use undocumented data in battery module, ELPA Syncer, 2022/11/27
- [nongnu] elpa/minibar 15896aa33a 16/17: Add .dir-locals.el, ELPA Syncer, 2022/11/27