[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bongo-patches] Extract `bongo-seek-status-string' from `bongo-seek-redi
From: |
Daniel Brockman |
Subject: |
[bongo-patches] Extract `bongo-seek-status-string' from `bongo-seek-redisplay' |
Date: |
Thu, 24 May 2007 13:29:28 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.92 (gnu/linux) |
Extract `bongo-seek-status-string' from `bongo-seek-redisplay'.
diff -rN -u old-bongo/bongo.el new-bongo/bongo.el
--- old-bongo/bongo.el 2007-05-24 13:29:24.000000000 +0200
+++ new-bongo/bongo.el 2007-05-24 13:29:24.000000000 +0200
@@ -7580,6 +7580,64 @@
(defvar bongo-seek-redisplaying nil
"Non-nil in the dynamic scope of `bongo-seek-redisplay'.")
+(defun bongo-seek-status-string (width)
+ "Return string of length WIDTH indicating the current track position."
+ (with-temp-buffer
+ (when (and (bongo-playing-p)
+ (bongo-elapsed-time))
+ (insert (bongo-format-seconds (bongo-elapsed-time)))
+ (insert " "))
+ (let* ((end-string (when (and (bongo-playing-p)
+ (bongo-remaining-time))
+ (concat " -" (bongo-format-seconds
+ (bongo-remaining-time)))))
+ (bar-start (point))
+ (available-width (- width bar-start (length end-string)))
+ (bar-width (if (and (bongo-playing-p)
+ (bongo-elapsed-time)
+ (bongo-total-time))
+ (round
+ (* (min 1 (/ (float (bongo-elapsed-time))
+ (bongo-total-time)))
+ available-width))
+ available-width))
+ (label (if (and (bongo-playing-p)
+ (bongo-elapsed-time)
+ (bongo-total-time))
+ (format " %d%% %s"
+ (/ (* (bongo-elapsed-time) 100.0)
+ (bongo-total-time))
+ (if (bongo-paused-p) "(paused) " ""))
+ (cond ((not (bongo-playing-p))
+ " (no currently playing track) ")
+ ((null (bongo-total-time))
+ " (track length not available) ")
+ ((null (bongo-elapsed-time))
+ " (elapsed time not available) "))))
+ (label-width (length label)))
+ (insert-char ?\ available-width)
+ (goto-char
+ (+ bar-start
+ (if (< bar-width label-width)
+ (1+ bar-width)
+ (/ (1+ (- bar-width label-width)) 2))))
+ (delete-char label-width)
+ (insert label)
+ (put-text-property bar-start (+ bar-start bar-width)
+ 'face (if (and (bongo-playing-p)
+ (bongo-elapsed-time)
+ (bongo-total-time))
+ 'bongo-filled-seek-bar
+ 'bongo-seek-message))
+ (put-text-property (+ bar-start bar-width)
+ (+ bar-start available-width)
+ 'face 'bongo-unfilled-seek-bar)
+ (when end-string
+ (goto-char (point-max))
+ (insert end-string))
+ (goto-char (+ bar-start bar-width)))
+ (buffer-string)))
+
(defun bongo-seek-redisplay ()
"Update the Bongo Seek buffer to reflect the current track position."
(interactive)
@@ -7592,61 +7650,7 @@
(sit-for 2)
(message nil))
(delete-region (point-min) (point-max))
- (when (and (bongo-playing-p)
- (bongo-elapsed-time))
- (insert " ")
- (insert (bongo-format-seconds (bongo-elapsed-time)))
- (insert " "))
- (let* ((end-string (when (and (bongo-playing-p)
- (bongo-remaining-time))
- (concat " -" (bongo-format-seconds
- (bongo-remaining-time)))))
- (bar-start (point))
- (available-width (- (window-width)
- bar-start
- (length end-string)))
- (bar-width (if (and (bongo-playing-p)
- (bongo-elapsed-time)
- (bongo-total-time))
- (round
- (* (min 1 (/ (float (bongo-elapsed-time))
- (bongo-total-time)))
- available-width))
- available-width))
- (label (if (and (bongo-playing-p)
- (bongo-elapsed-time)
- (bongo-total-time))
- (format " %d%% "
- (/ (* (bongo-elapsed-time) 100.0)
- (bongo-total-time)))
- (cond ((not (bongo-playing-p))
- " (no currently playing track) ")
- ((null (bongo-total-time))
- " (track length not available) ")
- ((null (bongo-elapsed-time))
- " (elapsed time not available) "))))
- (label-width (length label)))
- (insert-char ?\ available-width)
- (goto-char
- (+ bar-start
- (if (< bar-width label-width)
- (1+ bar-width)
- (/ (1+ (- bar-width label-width)) 2))))
- (delete-char label-width)
- (insert label)
- (put-text-property bar-start (+ bar-start bar-width)
- 'face (if (and (bongo-playing-p)
- (bongo-elapsed-time)
- (bongo-total-time))
- 'bongo-filled-seek-bar
- 'bongo-seek-message))
- (put-text-property (+ bar-start bar-width)
- (+ bar-start available-width)
- 'face 'bongo-unfilled-seek-bar)
- (when end-string
- (goto-char (point-max))
- (insert end-string))
- (goto-char (+ bar-start bar-width)))))))
+ (insert (bongo-seek-status-string (window-width)))))))
;; This function was based on the function `calculator' from
;; calculator.el, which is copyrighted by the FSF.
--
Daniel Brockman <address@hidden>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [bongo-patches] Extract `bongo-seek-status-string' from `bongo-seek-redisplay',
Daniel Brockman <=