Skip to content

Commit d4e4729

Browse files
committed
feat: scale the UI with the window width
1 parent 394a52f commit d4e4729

1 file changed

Lines changed: 42 additions & 14 deletions

File tree

pomidor.el

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,13 @@ TIME may be nil."
369369

370370
(defun pomidor--format-time-string (time face)
371371
"Format graph string for TIME with FACE."
372-
(pomidor--with-face (make-string (round (/ (time-to-seconds time)
373-
(/ (float pomidor-seconds) (/ (pomidor--window-width) 2))))
374-
pomidor-graph-char)
375-
face))
372+
(pomidor--with-face
373+
(make-string (round (/ (time-to-seconds time)
374+
(/ (+ (float pomidor-seconds)
375+
(float pomidor-long-break-seconds))
376+
(- (pomidor--window-width) 12))))
377+
pomidor-graph-char)
378+
face))
376379

377380
(defun pomidor--graph (work overwork break)
378381
"Format graph based on WORK, OVERWORK and BREAK time."
@@ -444,21 +447,46 @@ TIME may be nil."
444447
(setq sum-break (time-add sum-break break)))
445448
(insert
446449
"\n "
447-
(make-string 79 ?-)
450+
(make-string (- (pomidor--window-width) 12) ?-)
448451
"\n"
449-
(format "%3d) [%s] | [%s] | [%s] | [%s]\t\t %s%s"
450-
i
451-
(pomidor--with-face (pomidor--format-duration work) 'pomidor-work-face)
452-
(pomidor--with-face (pomidor--format-duration overwork) 'pomidor-overwork-face)
453-
(pomidor--with-face (pomidor--format-duration break) 'pomidor-break-face)
454-
(pomidor--format-duration total)
455-
(pomidor--format-time (pomidor--started state))
456-
(pomidor--format-time (pomidor--ended state)))
452+
;; We have to store the pre-formatted values here to
453+
;; calculate how much space they take up. This is due to
454+
;; the variable time format, see `pomidor-time-format'.
455+
(let ((formatted-time-work
456+
(pomidor--with-face (pomidor--format-duration work) 'pomidor-work-face))
457+
(formatted-time-overwork
458+
(pomidor--with-face (pomidor--format-duration overwork) 'pomidor-overwork-face))
459+
(formatted-time-break
460+
(pomidor--with-face (pomidor--format-duration break) 'pomidor-break-face))
461+
(formatted-time-total (pomidor--format-duration total))
462+
(formatted-time-start (pomidor--format-time (pomidor--started state)))
463+
(formatted-time-end (pomidor--format-time (pomidor--ended state))))
464+
(format "%3d) [%s] | [%s] | [%s] | [%s]%s%s%s"
465+
i
466+
formatted-time-work
467+
formatted-time-overwork
468+
formatted-time-break
469+
formatted-time-total
470+
(make-string (max (- (pomidor--window-width)
471+
12 ; margin
472+
9 ; | separators
473+
3 ; → separator
474+
8 ; brackets
475+
(length formatted-time-work)
476+
(length formatted-time-overwork)
477+
(length formatted-time-break)
478+
(length formatted-time-total)
479+
(length formatted-time-start)
480+
(length formatted-time-end))
481+
1)
482+
32)
483+
formatted-time-start
484+
formatted-time-end))
457485
"\n "
458486
(pomidor--graph work overwork break)))
459487
finally
460488
(insert "\n "
461-
(make-string 79 ?-)
489+
(make-string (- (pomidor--window-width) 12) ?-)
462490
"\n\n"
463491
(format " Work\t[%s]\n"
464492
(pomidor--with-face (pomidor--format-duration sum-work) 'pomidor-work-face))

0 commit comments

Comments
 (0)