[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 7914c48 10/76: (enwc-format-mode-line-string, enwc-update-
From: |
Ian Dunn |
Subject: |
[elpa] master 7914c48 10/76: (enwc-format-mode-line-string, enwc-update-mode-line): Added the option to customize the information displayed in the mode line. |
Date: |
Thu, 23 Feb 2017 19:42:44 -0500 (EST) |
branch: master
commit 7914c4861156f2c90a42cd6c739f84bc0a317d8c
Author: Ian D <address@hidden>
Commit: Ian D <address@hidden>
(enwc-format-mode-line-string, enwc-update-mode-line): Added the option to
customize the information displayed in the mode line.
---
lisp/enwc.el | 176 +++++++++++++++++++++++++++++++++++------------------------
1 file changed, 106 insertions(+), 70 deletions(-)
diff --git a/lisp/enwc.el b/lisp/enwc.el
index aba6027..6097957 100644
--- a/lisp/enwc.el
+++ b/lisp/enwc.el
@@ -90,6 +90,22 @@ networks every `enwc-auto-scan-interval' seconds."
:group 'enwc
:type 'integer)
+(defcustom enwc-mode-line-format "[%s%%]"
+ "The format for displaying the mode line.
+
+%s = The current signal strength. If wired, then this is set to
+100.
+
+%e = The essid of the current network. If wired, then this set to
+'Wired'
+
+%b = The bssid of the current network. If using a wired connection,
+then this is set to 'Wired'.
+
+%% = A Normal '%'"
+ :group 'enwc
+ :type 'string)
+
;;; The function variables for the abstract layer.
(defvar enwc-scan-func nil
@@ -264,16 +280,7 @@ This is only used internally.")
"The timer for automatic scanning.")
(make-local-variable 'enwc-edit-id)
-;; The Fonts
-
-;; (defface enwc-header-face
-;; '((((class color) (background light))
-;; (:foreground "Blue"))
-;; (((class color) (background dark))
-;; (:foreground "Blue"))
-;; (t (:background "Blue")))
-;; "The face for the headers."
-;; :group 'enwc)
+;; The Faces
(defface enwc-connected-face
'((((class color) (background dark))
@@ -288,7 +295,9 @@ This is only used internally.")
;; Small helper function.
(defun enwc-detail-to-ident (detail)
- "Converts detail DETAIL to a constant identifier."
+ "Converts network detail DETAIL to a constant identifier.
+This function is used to synchronize the different backends
+to display consistent results."
(case (intern detail)
((essid Ssid) "essid")
((bssid HwAddress) "bssid")
@@ -434,29 +443,51 @@ WIRED indicates whether or not this is a wired
connection."
(enwc-get-wired-nw-prop id prop)
(enwc-get-wireless-nw-prop id prop)))
+(defun enwc-format-mode-line-string ()
+ "Formats the mode line string.
+This is derived from `enwc-mode-line-format'.
+See the documentation for it for more details."
+ (if (enwc-check-connecting-p)
+ "[*]"
+ (let* ((f enwc-mode-line-format)
+ (p 0)
+ (l (length f))
+ (cur-id (enwc-get-current-nw-id))
+ c fin-str)
+ (while (< p l)
+ (setq c (elt f p))
+ (setq p (1+ p))
+ (setq fin-str
+ (concat
+ fin-str
+ (if (not (eq c ?%))
+ (char-to-string c)
+ (setq p (1+ p))
+ (cond
+ ((eq (elt f (1- p)) ?s)
+ (if (enwc-is-wired-p)
+ "100"
+ (number-to-string
+ (cdr (assoc "quality" (nth cur-id enwc-last-scan))))))
+ ((eq (elt f (1- p)) ?e)
+ (if (enwc-is-wired-p)
+ "Wired"
+ (cdr (assoc "essid" (nth cur-id enwc-last-scan)))))
+ ((eq (elt f (1- p)) ?b)
+ (if (enwc-is-wired-p)
+ "wired"
+ (cdr (assoc "bssid" (nth cur-id enwc-last-scan)))))
+ ((eq (elt f (1- p)) ?%) "%"))))))
+ fin-str)))
+
(defun enwc-update-mode-line ()
- "Updates the mode line with the current network strength.
-If no network is connected, then prints 0%.
-If wired is active, then prints 100%.
-If ENWC is in the process of connecting, then prints *%.
+ "Updates the mode line display.
+This uses the format specified by `enwc-mode-line-format'.
This is initiated during setup, and runs once every second."
(let ((cur-id (enwc-get-current-nw-id))
- (conn (enwc-check-connecting-p))
- str)
- (setq str
- (if (enwc-is-wired-p)
- 100
- (if (and
- (enwc-is-valid-nw-id cur-id)
- enwc-last-scan)
- (cdr (assoc "quality" (nth cur-id enwc-last-scan)))
- 0)))
- (setq enwc-display-string (concat " ["
- (if conn
- "*"
- (number-to-string str))
- "%] "))
- (force-mode-line-update)))
+ (conn (enwc-check-connecting-p)))
+ (setq enwc-display-string (enwc-format-mode-line-string))
+ (force-mode-line-update)))
(defun enwc-enable-display-mode-line ()
"Enables the mode line display."
@@ -618,44 +649,45 @@ ENT is the entry, and WIDTH is the column width."
"Displays the networks in the list NETWORKS in the current buffer.
NETWORKS must be in the format returned by
`enwc-scan-internal-wireless'."
- (if (not (eq major-mode 'enwc-mode))
- (enwc-setup-buffer))
+ (if (not (get-buffer "*ENWC*"))
+ (enwc-setup-buffer t))
(if (not (listp networks))
(error "NETWORKS must be a list of association lists."))
- (let ((cur-id (enwc-get-current-nw-id))
- entries)
- (let ((header enwc-wireless-headers)
- (pos 0))
-
- (setq tabulated-list-format
- (vector '("ID" 2)
- '("STR" 4)
- `("ESSID" ,enwc-essid-width)
- '("ENCRYPT" 9)
- '("BSSID" 17)
- '("MODE" 15)
- '("CHNL" 2))))
-
- (dolist (nw networks)
- (let ((id (cdr (assoc "id" nw)))
- entry)
- (setq entry (list nil
- (vector
- (enwc-maybe-pretty-entry (number-to-string (cdr
(assoc "id" nw))))
- (enwc-maybe-pretty-entry
- (concat (number-to-string (cdr (assoc "quality"
nw)))
- "%"))
- (enwc-maybe-pretty-entry (cdr (assoc "essid" nw)))
- (enwc-maybe-pretty-entry (cdr (assoc "encryption"
nw)))
- (enwc-maybe-pretty-entry (cdr (assoc "bssid" nw)))
- (enwc-maybe-pretty-entry (cdr (assoc "mode" nw)))
- (enwc-maybe-pretty-entry (cdr (assoc "channel"
nw))))))
- (setq entries (cons entry entries))))
-
- (setq tabulated-list-entries (nreverse entries))
- (tabulated-list-init-header)
-
- (tabulated-list-print)))
+ (with-current-buffer (get-buffer "*ENWC*")
+ (let ((cur-id (enwc-get-current-nw-id))
+ entries)
+ (let ((header enwc-wireless-headers)
+ (pos 0))
+
+ (setq tabulated-list-format
+ (vector '("ID" 2)
+ '("STR" 4)
+ `("ESSID" ,enwc-essid-width)
+ '("ENCRYPT" 9)
+ '("BSSID" 17)
+ '("MODE" 15)
+ '("CHNL" 2))))
+
+ (dolist (nw networks)
+ (let ((id (cdr (assoc "id" nw)))
+ entry)
+ (setq entry (list nil
+ (vector
+ (enwc-maybe-pretty-entry (number-to-string (cdr
(assoc "id" nw))))
+ (enwc-maybe-pretty-entry
+ (concat (number-to-string (cdr (assoc "quality"
nw)))
+ "%"))
+ (enwc-maybe-pretty-entry (cdr (assoc "essid" nw)))
+ (enwc-maybe-pretty-entry (cdr (assoc "encryption"
nw)))
+ (enwc-maybe-pretty-entry (cdr (assoc "bssid" nw)))
+ (enwc-maybe-pretty-entry (cdr (assoc "mode" nw)))
+ (enwc-maybe-pretty-entry (cdr (assoc "channel"
nw))))))
+ (setq entries (cons entry entries))))
+
+ (setq tabulated-list-entries (nreverse entries))
+ (tabulated-list-init-header)
+
+ (tabulated-list-print))))
(defun enwc-display-networks (networks)
"Displays the network in NETWORKS. This is an entry to the display
@@ -1025,14 +1057,18 @@ and redisplays the settings from the network profile
\\{enwc-mode-map}"
(add-hook 'tabulated-list-revert-hook 'enwc-scan nil t))
-(defun enwc-setup-buffer ()
+(defun enwc-setup-buffer (&optional nomove)
"Sets up the ENWC buffer.
This first checks to see that it exists,
-and if it doesn't, then create it."
+and if it doesn't, then create it.
+
+If NOMOVE is non-nil, then do not move to the
+newly created buffer."
(if (not (get-buffer "*ENWC*"))
(with-current-buffer (get-buffer-create "*ENWC*")
(enwc-mode)))
- (switch-to-buffer "*ENWC*"))
+ (if (not nomove)
+ (switch-to-buffer "*ENWC*")))
(provide 'enwc)
- [elpa] master 218aa82 25/76: Fixed prefix of customization group., (continued)
- [elpa] master 218aa82 25/76: Fixed prefix of customization group., Ian Dunn, 2017/02/23
- [elpa] master c9a94c8 44/76: Added tag 2.0 for changeset 3e2cab525cbc, Ian Dunn, 2017/02/23
- [elpa] master c4ac6fc 60/76: Fixed bug in 'enwc-load-default-backend', Ian Dunn, 2017/02/23
- [elpa] master b8697fd 62/76: Added force parameter to `enwc-load-backend'., Ian Dunn, 2017/02/23
- [elpa] master 2ebc214 01/76: Changed timeout on enwc-wicd-get-wireless-network-property., Ian Dunn, 2017/02/23
- [elpa] master 18e4a3a 06/76: Updated copyright notices., Ian Dunn, 2017/02/23
- [elpa] master 0d92006 09/76: (enwc-update-mode-line): Forces the mode line to update when ENWC updates its current signal., Ian Dunn, 2017/02/23
- [elpa] master 742b67a 19/76: Removed several network manager functions., Ian Dunn, 2017/02/23
- [elpa] master 773cef6 24/76: (enwc-backend-symbol-list): New variable., Ian Dunn, 2017/02/23
- [elpa] master b5686da 17/76: (enwc-wicd-get-sec-types): Removed., Ian Dunn, 2017/02/23
- [elpa] master 7914c48 10/76: (enwc-format-mode-line-string, enwc-update-mode-line): Added the option to customize the information displayed in the mode line.,
Ian Dunn <=
- [elpa] master 59ca546 20/76: (enwc--str-to-sym): Fixed., Ian Dunn, 2017/02/23
- [elpa] master 1722c02 33/76: enwc-cm.el: Fixed up header and footer., Ian Dunn, 2017/02/23
- [elpa] master c8a0397 29/76: Fixed some compilation errors in enwc.el., Ian Dunn, 2017/02/23
- [elpa] master bb68ed5 37/76: Added ignore rules for byte compiled files., Ian Dunn, 2017/02/23
- [elpa] master 6ed7137 43/76: Fix adding to global-mode-string., Ian Dunn, 2017/02/23
- [elpa] master 968e6f0 46/76: Added tag 2.0 for changeset cc2f7aa4ed36, Ian Dunn, 2017/02/23
- [elpa] master 2d5def6 36/76: (*-function): Removed., Ian Dunn, 2017/02/23
- [elpa] master d9cbdb9 39/76: Added some section headers., Ian Dunn, 2017/02/23
- [elpa] master 03a5464 57/76: Changed channel to an integer., Ian Dunn, 2017/02/23
- [elpa] master a6b2b03 61/76: Removed tag 2.0, Ian Dunn, 2017/02/23