[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/telephone-line 2fd44a2811 144/195: Add hud segment
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/telephone-line 2fd44a2811 144/195: Add hud segment |
Date: |
Wed, 5 Jan 2022 02:59:41 -0500 (EST) |
branch: elpa/telephone-line
commit 2fd44a28113996378b7fc683549bb27169eb958f
Author: Daniel Bordak <dbordak@fastmail.fm>
Commit: Daniel Bordak <dbordak@fastmail.fm>
Add hud segment
---
telephone-line-segments.el | 38 ++++++++++++++++++++++++++++++++++++++
telephone-line-utils.el | 10 ++++++++--
2 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/telephone-line-segments.el b/telephone-line-segments.el
index 1622cfe342..1091b56088 100644
--- a/telephone-line-segments.el
+++ b/telephone-line-segments.el
@@ -94,6 +94,44 @@ mouse-3: Toggle minor modes"
'mouse-2 #'mode-line-widen)
face ,face)))
+(defun telephone-line--hud-axis-func (y)
+ (let* ((height (or telephone-line-height (frame-char-height)))
+ (start (floor (* height (float (window-start))) (point-max)))
+ (end (ceiling (* height (float (window-end))) (point-max))))
+ (if (<= start y end) 1 0)))
+
+(defclass telephone-line--hud (telephone-line-separator)
+ ((axis-func :initarg :axis-func :initform #'telephone-line--hud-axis-func)
+ (axis-init :initarg :axis-init
+ :initform (lambda (height) (number-sequence 0 (- height 1))))
+ (pattern-func :initarg :pattern-func :initform
#'telephone-line-row-pattern-binary)
+ (image-cache :initform (make-hash-table :test 'equal :size 100))))
+
+(cl-defmethod telephone-line-separator-render-image ((obj telephone-line--hud)
foreground background)
+ "Find cached pbm of OBJ in FOREGROUND and BACKGROUND.
+If it doesn't exist, create and cache it."
+ (let* ((height (or telephone-line-height (frame-char-height)))
+ (start (floor (* height (float (window-start))) (point-max)))
+ (end (ceiling (* height (float (window-end))) (point-max)))
+ (hash-key (format "%s_%s_%d_%d" background foreground start end)))
+ ;; Return cached image if we have it.
+ (or (gethash hash-key (oref obj image-cache))
+ (puthash hash-key
+ (telephone-line-propertize-image
+ (telephone-line--create-pbm-image
+ (telephone-line-separator-create-body obj)
+ background foreground))
+ (oref obj image-cache)))))
+
+(defvar telephone-line-hud (make-instance 'telephone-line--hud))
+
+(telephone-line-defsegment telephone-line-hud-segment ()
+ (let ((fg (face-attribute face :foreground)))
+ (telephone-line-separator-render telephone-line-hud
+ (if (eq fg 'unspecified)
+ (face-attribute 'default :foreground))
+ face)))
+
(telephone-line-defsegment telephone-line-erc-modified-channels-segment ()
(when (boundp 'erc-modified-channels-object)
(string-trim erc-modified-channels-object)))
diff --git a/telephone-line-utils.el b/telephone-line-utils.el
index 2422b1b6dc..f7fed7c5db 100644
--- a/telephone-line-utils.el
+++ b/telephone-line-utils.el
@@ -114,7 +114,7 @@ color1 and color2."
(defun telephone-line-propertize-image (image)
"Return a propertized string of IMAGE."
- (propertize (make-string (ceiling (car (image-size image))) ? )
+ (propertize (make-string (ceiling (car (image-size image))) ?|)
'display image))
(defun telephone-line-row-pattern (fill total)
@@ -137,6 +137,11 @@ color1 and color2."
(cons (- 1 rem) ;Right AA pixel
(make-list (- total intpadding 2) 1)))))) ;Right gap
+(defun telephone-line-row-pattern-binary (fill total)
+ (if (= fill 0)
+ (make-list total 0)
+ (make-list total 1)))
+
(defmacro telephone-line-complement (func)
"Return a function which is the complement of FUNC."
`(lambda (x)
@@ -148,6 +153,7 @@ color1 and color2."
(defclass telephone-line-separator ()
((axis-func :initarg :axis-func)
+ (axis-init :initarg :axis-init :initform #'telephone-line-create-trig-axis)
(pattern-func :initarg :pattern-func :initform #'telephone-line-row-pattern)
(forced-width :initarg :forced-width :initform nil)
(alt-separator :initarg :alt-separator)
@@ -178,7 +184,7 @@ color1 and color2."
(width (telephone-line-separator-width obj))
(normalized-axis (telephone-line--normalize-axis
(mapcar (oref obj axis-func)
- (telephone-line-create-trig-axis height))))
+ (funcall (oref obj axis-init) height))))
(range (seq-max normalized-axis))
(scaling-factor (/ (1- width)(float range))))
(mapcar (lambda (x)
- [nongnu] elpa/telephone-line c73b2c210d 027/195: Fix face definitions, (continued)
- [nongnu] elpa/telephone-line c73b2c210d 027/195: Fix face definitions, ELPA Syncer, 2022/01/05
- [nongnu] elpa/telephone-line 5c0af25f19 073/195: Explain config ordering, ELPA Syncer, 2022/01/05
- [nongnu] elpa/telephone-line 74cd7ea3ee 082/195: Fix telephone-line-nil, ELPA Syncer, 2022/01/05
- [nongnu] elpa/telephone-line b2439795a4 078/195: Improve default colors., ELPA Syncer, 2022/01/05
- [nongnu] elpa/telephone-line 07858899cc 052/195: Readme update, ELPA Syncer, 2022/01/05
- [nongnu] elpa/telephone-line bfd9c8b431 067/195: New string trimmer fixes appearance of paradox line number segment, ELPA Syncer, 2022/01/05
- [nongnu] elpa/telephone-line 778d435ad2 109/195: Fix support for Emacs<25, ELPA Syncer, 2022/01/05
- [nongnu] elpa/telephone-line 36a6583157 156/195: Add a bunch of docstrings to segments, ELPA Syncer, 2022/01/05
- [nongnu] elpa/telephone-line 0d23081c68 148/195: Add a couple faces for segments, ELPA Syncer, 2022/01/05
- [nongnu] elpa/telephone-line 8372f7d37c 133/195: Add centered segment support, ELPA Syncer, 2022/01/05
- [nongnu] elpa/telephone-line 2fd44a2811 144/195: Add hud segment,
ELPA Syncer <=
- [nongnu] elpa/telephone-line e0eeb057ca 160/195: Actually check if the projectile stuff will work, ELPA Syncer, 2022/01/05
- [nongnu] elpa/telephone-line 305b5dbfec 163/195: Added minions-mode-segment, compatible with https://github.com/tarsius/minions., ELPA Syncer, 2022/01/05
- [nongnu] elpa/telephone-line 74068cd04a 167/195: Added segments "plain" buffer name and modified-state-only. (#93), ELPA Syncer, 2022/01/05
- [nongnu] elpa/telephone-line 17901f3911 170/195: Merge pull request #96 from MikeTheGreat/filename_segments, ELPA Syncer, 2022/01/05
- [nongnu] elpa/telephone-line 81ec9e3137 171/195: Respect 0/1-indexing setting, ELPA Syncer, 2022/01/05
- [nongnu] elpa/telephone-line 706cedb353 174/195: Merge pull request #109 from endoffile78/circe, ELPA Syncer, 2022/01/05
- [nongnu] elpa/telephone-line c0363af166 176/195: Add height to the hash key to automatically handle font size changes, ELPA Syncer, 2022/01/05
- [nongnu] elpa/telephone-line bc6075462f 185/195: Fix examples for telephone-line-defsegment, ELPA Syncer, 2022/01/05
- [nongnu] elpa/telephone-line baf17f6f1c 186/195: Fixed parentheses in atom-eol-segment, ELPA Syncer, 2022/01/05
- [nongnu] elpa/telephone-line 2fbcdb44a9 189/195: Merge pull request #115 from SahilKang/master, ELPA Syncer, 2022/01/05