Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: scale the UI with the window width #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 42 additions & 14 deletions pomidor.el
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,13 @@ TIME may be nil."

(defun pomidor--format-time-string (time face)
"Format graph string for TIME with FACE."
(pomidor--with-face (make-string (round (/ (time-to-seconds time)
(/ (float pomidor-seconds) (/ (pomidor--window-width) 2))))
pomidor-graph-char)
face))
(pomidor--with-face
(make-string (round (/ (time-to-seconds time)
(/ (+ (float pomidor-seconds)
(float pomidor-long-break-seconds))
(- (pomidor--window-width) 12))))
pomidor-graph-char)
face))

(defun pomidor--graph (work overwork break)
"Format graph based on WORK, OVERWORK and BREAK time."
Expand Down Expand Up @@ -444,21 +447,46 @@ TIME may be nil."
(setq sum-break (time-add sum-break break)))
(insert
"\n "
(make-string 79 ?-)
(make-string (- (pomidor--window-width) 12) ?-)
"\n"
(format "%3d) [%s] | [%s] | [%s] | [%s]\t\t %s → %s"
i
(pomidor--with-face (pomidor--format-duration work) 'pomidor-work-face)
(pomidor--with-face (pomidor--format-duration overwork) 'pomidor-overwork-face)
(pomidor--with-face (pomidor--format-duration break) 'pomidor-break-face)
(pomidor--format-duration total)
(pomidor--format-time (pomidor--started state))
(pomidor--format-time (pomidor--ended state)))
;; We have to store the pre-formatted values here to
;; calculate how much space they take up. This is due to
;; the variable time format, see `pomidor-time-format'.
(let ((formatted-time-work
(pomidor--with-face (pomidor--format-duration work) 'pomidor-work-face))
(formatted-time-overwork
(pomidor--with-face (pomidor--format-duration overwork) 'pomidor-overwork-face))
(formatted-time-break
(pomidor--with-face (pomidor--format-duration break) 'pomidor-break-face))
(formatted-time-total (pomidor--format-duration total))
(formatted-time-start (pomidor--format-time (pomidor--started state)))
(formatted-time-end (pomidor--format-time (pomidor--ended state))))
(format "%3d) [%s] | [%s] | [%s] | [%s]%s%s → %s"
i
formatted-time-work
formatted-time-overwork
formatted-time-break
formatted-time-total
(make-string (max (- (pomidor--window-width)
12 ; margin
9 ; | separators
3 ; → separator
8 ; brackets
(length formatted-time-work)
(length formatted-time-overwork)
(length formatted-time-break)
(length formatted-time-total)
(length formatted-time-start)
(length formatted-time-end))
1)
32)
formatted-time-start
formatted-time-end))
"\n "
(pomidor--graph work overwork break)))
finally
(insert "\n "
(make-string 79 ?-)
(make-string (- (pomidor--window-width) 12) ?-)
"\n\n"
(format " Work\t[%s]\n"
(pomidor--with-face (pomidor--format-duration sum-work) 'pomidor-work-face))
Expand Down