Skip to content

Commit

Permalink
feat(vc): add indicators
Browse files Browse the repository at this point in the history
  • Loading branch information
Walheimat committed Dec 26, 2023
1 parent 616e310 commit ba66534
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 32 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- `vc` segment now has different indicators per state that are
propertized with faces instead of the branch name itself.

### Changed

- `whale-line-log` is now either `nil`, `0`, or `1`. The numbers
Expand Down
20 changes: 11 additions & 9 deletions test/whale-line-segments-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -633,12 +633,12 @@
;;; -- VC

(ert-deftest vc--face-for-state ()
(let ((whale-line-segments--vc--states '((test . neutral)
(live . urgent))))
(let ((whale-line-segments--vc--state-specs '((test . (neutral))
(live . (urgent)))))

(should (eq 'neutral (whale-line-segments--vc--face-for-state 'test)))
(should (eq 'urgent (whale-line-segments--vc--face-for-state 'live)))
(should (eq 'whale-line-neutral (whale-line-segments--vc--face-for-state 'unknown)))))
(should (eq 'neutral (car (whale-line-segments--vc--specs-for-state 'test))))
(should (eq 'urgent (car (whale-line-segments--vc--specs-for-state 'live))))
(should (eq 'whale-line-shadow (car (whale-line-segments--vc--specs-for-state 'unknown))))))

(ert-deftest vc ()
(bydi ((:always buffer-file-name)
Expand All @@ -661,9 +661,10 @@
(bydi ((:mock vc-backend :return "none")
(:mock vc-state :return 'testing)
(:mock whale-line-segments--decorate :return "*")
(:mock whale-line-segments--vc--face-for-state :return 'test-face))
(:mock whale-line-segments--vc--specs-for-state :return '(test-face "?")))

(should (equal '(:propertize "tests" mouse-face whale-line-highlight face test-face)
(should (equal '((:propertize "tests" mouse-face whale-line-highlight)
(:propertize "?" face test-face))
(whale-line-segments--vc-registered--info))))))

(ert-deftest vc-unregistered--git-p ()
Expand All @@ -682,12 +683,13 @@
(let ((name nil))
(bydi ((:mock buffer-file-name :return name)
(:sometimes whale-line-segments--vc-unregistered--git-p)
(:mock whale-line-segments--vc--face-for-state :return 'test-face)
(:mock whale-line-segments--vc--specs-for-state :return '(test-face "?"))
(:mock vc-state :return 'testing))

(should-not (whale-line-segments--vc-unregistered--info))
(setq name "/tmp/testing")
(should (equal '(:propertize "Git" face test-face help-echo "File state: testing")
(should (equal '((:propertize "Git" help-echo "File state: testing")
(:propertize "?" face test-face))
(whale-line-segments--vc-unregistered--info)))
(bydi-toggle-sometimes)
(should-not (whale-line-segments--vc-unregistered--info)))))
Expand Down
47 changes: 24 additions & 23 deletions whale-line-segments.el
Original file line number Diff line number Diff line change
Expand Up @@ -746,21 +746,21 @@ This is either an explicit name or its index."

(defvar whale-line-segments--vc--scope-regexp "\\(feature\\|\\(\\w+\\)?fix\\|improvement\\)\\/")

(defvar whale-line-segments--vc--states '((up-to-date . whale-line-neutral)
(edited . whale-line-indicate)
(needs-update . whale-line-contrast)
(needs-merge . whale-line-urgent)
(unlocked-changes . whale-line-urgent)
(added . whale-line-emphasis)
(removed . whale-line-emphasis)
(conflict . whale-line-urgent)
(missing . whale-line-contrast)
(ignored . whale-line-shadow)
(unregistered . whale-line-shadow)))

(defun whale-line-segments--vc--face-for-state (state)
"Get the correct face for the STATE."
(alist-get state whale-line-segments--vc--states 'whale-line-neutral))
(defvar whale-line-segments--vc--state-specs '((up-to-date . (whale-line-shadow "."))
(edited . (whale-line-contrast "*"))
(needs-update . (whale-line-contrast "&"))
(needs-merge . (whale-line-urgent "&"))
(unlocked-changes . (whale-line-urgent "!"))
(added . (whale-line-emphasis "+"))
(removed . (whale-line-emphasis "-"))
(conflict . (whale-line-urgent "!"))
(missing . (whale-line-contrast "?"))
(ignored . (whale-line-shadow "!"))
(unregistered . (whale-line-shadow "?"))))

(defun whale-line-segments--vc--specs-for-state (state)
"Get the correct specs for STATE."
(alist-get state whale-line-segments--vc--state-specs '(whale-line-shadow ".")))

(defun whale-line-segments--vc ()
"Get version control info."
Expand All @@ -779,11 +779,12 @@ This is either an explicit name or its index."
(backend (vc-backend buffer-file-name))
(status (and vc-display-status
(substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))))
(state (vc-state buffer-file-name backend)))
(state (vc-state buffer-file-name backend))
(specs (whale-line-segments--vc--specs-for-state state)))

`(:propertize ,(replace-regexp-in-string whale-line-segments--vc--scope-regexp "" status)
mouse-face whale-line-highlight
face ,(whale-line-segments--vc--face-for-state state))))
`((:propertize ,(replace-regexp-in-string whale-line-segments--vc--scope-regexp "" status)
mouse-face whale-line-highlight)
(:propertize ,(nth 1 specs) face ,(nth 0 specs)))))

;;;; -- Unregistered

Expand All @@ -799,11 +800,11 @@ This is either an explicit name or its index."
(cond
((whale-line-segments--vc-unregistered--git-p file)
(when-let* ((state (vc-state file 'Git))
(help (format "File state: %s" state)))
(help (format "File state: %s" state))
(specs (whale-line-segments--vc--specs-for-state state)))

`(:propertize "Git"
face ,(whale-line-segments--vc--face-for-state state)
help-echo ,help))))))
`((:propertize "Git" help-echo ,help)
(:propertize ,(nth 1 specs) face ,(nth 0 specs))))))))

(whale-line-create-stateful-segment vc
:getter whale-line-segments--vc
Expand Down

0 comments on commit ba66534

Please sign in to comment.