Skip to content

Commit

Permalink
Use display-color-cells to enable 24-bit color terminal support (#88)
Browse files Browse the repository at this point in the history
In order to fix "unable to load color x" errors when running Emacs in
daemon-mode, the defined theme colors are now tested against the
`display-color-cells` "display feature testing" function [1] to support
24-bit color terminals with a fallback to the `display-graphic-p`
function.

This is a first step to fix the problems described in GH-59.

Related to GH-59
  • Loading branch information
arcticicestudio authored Jan 5, 2020
1 parent 2fc8fe4 commit a66c120
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions nord-theme.el
Original file line number Diff line number Diff line change
Expand Up @@ -93,39 +93,43 @@
Please see https://github.com/arcticicestudio/nord-emacs/issues/73 for more details."
"0.4.0")

(defun nord-display-truecolor-or-graphic-p ()
"Returns whether the display can display nord colors"
(or (= (display-color-cells) 16777216) (display-graphic-p)))

;;;; Color Constants
(let ((class '((class color) (min-colors 89)))
(nord0 (if (display-graphic-p) "#2E3440" nil))
(nord1 (if (display-graphic-p) "#3B4252" "black"))
(nord2 (if (display-graphic-p) "#434C5E" "#434C5E"))
(nord3 (if (display-graphic-p) "#4C566A" "brightblack"))
(nord4 (if (display-graphic-p) "#D8DEE9" "#D8DEE9"))
(nord5 (if (display-graphic-p) "#E5E9F0" "white"))
(nord6 (if (display-graphic-p) "#ECEFF4" "brightwhite"))
(nord7 (if (display-graphic-p) "#8FBCBB" "cyan"))
(nord8 (if (display-graphic-p) "#88C0D0" "brightcyan"))
(nord9 (if (display-graphic-p) "#81A1C1" "blue"))
(nord10 (if (display-graphic-p) "#5E81AC" "brightblue"))
(nord11 (if (display-graphic-p) "#BF616A" "red"))
(nord12 (if (display-graphic-p) "#D08770" "brightyellow"))
(nord13 (if (display-graphic-p) "#EBCB8B" "yellow"))
(nord14 (if (display-graphic-p) "#A3BE8C" "green"))
(nord15 (if (display-graphic-p) "#B48EAD" "magenta"))
(nord-annotation (if (display-graphic-p) "#D08770" "brightyellow"))
(nord-attribute (if (display-graphic-p) "#8FBCBB" "cyan"))
(nord-class (if (display-graphic-p) "#8FBCBB" "cyan"))
(nord-comment (if (display-graphic-p) (nord-theme--brightened-comment-color nord-comment-brightness) "brightblack"))
(nord-escape (if (display-graphic-p) "#D08770" "brightyellow"))
(nord-method (if (display-graphic-p) "#88C0D0" "brightcyan"))
(nord-keyword (if (display-graphic-p) "#81A1C1" "blue"))
(nord-numeric (if (display-graphic-p) "#B48EAD" "magenta"))
(nord-operator (if (display-graphic-p) "#81A1C1" "blue"))
(nord-preprocessor (if (display-graphic-p) "#5E81AC" "brightblue"))
(nord-punctuation (if (display-graphic-p) "#D8DEE9" "#D8DEE9"))
(nord-regexp (if (display-graphic-p) "#EBCB8B" "yellow"))
(nord-string (if (display-graphic-p) "#A3BE8C" "green"))
(nord-tag (if (display-graphic-p) "#81A1C1" "blue"))
(nord-variable (if (display-graphic-p) "#D8DEE9" "#D8DEE9"))
(nord0 (if (nord-display-truecolor-or-graphic-p) "#2E3440" nil))
(nord1 (if (nord-display-truecolor-or-graphic-p) "#3B4252" "black"))
(nord2 (if (nord-display-truecolor-or-graphic-p) "#434C5E" "#434C5E"))
(nord3 (if (nord-display-truecolor-or-graphic-p) "#4C566A" "brightblack"))
(nord4 (if (nord-display-truecolor-or-graphic-p) "#D8DEE9" "#D8DEE9"))
(nord5 (if (nord-display-truecolor-or-graphic-p) "#E5E9F0" "white"))
(nord6 (if (nord-display-truecolor-or-graphic-p) "#ECEFF4" "brightwhite"))
(nord7 (if (nord-display-truecolor-or-graphic-p) "#8FBCBB" "cyan"))
(nord8 (if (nord-display-truecolor-or-graphic-p) "#88C0D0" "brightcyan"))
(nord9 (if (nord-display-truecolor-or-graphic-p) "#81A1C1" "blue"))
(nord10 (if (nord-display-truecolor-or-graphic-p) "#5E81AC" "brightblue"))
(nord11 (if (nord-display-truecolor-or-graphic-p) "#BF616A" "red"))
(nord12 (if (nord-display-truecolor-or-graphic-p) "#D08770" "brightyellow"))
(nord13 (if (nord-display-truecolor-or-graphic-p) "#EBCB8B" "yellow"))
(nord14 (if (nord-display-truecolor-or-graphic-p) "#A3BE8C" "green"))
(nord15 (if (nord-display-truecolor-or-graphic-p) "#B48EAD" "magenta"))
(nord-annotation (if (nord-display-truecolor-or-graphic-p) "#D08770" "brightyellow"))
(nord-attribute (if (nord-display-truecolor-or-graphic-p) "#8FBCBB" "cyan"))
(nord-class (if (nord-display-truecolor-or-graphic-p) "#8FBCBB" "cyan"))
(nord-comment (if (nord-display-truecolor-or-graphic-p) (nord-theme--brightened-comment-color nord-comment-brightness) "brightblack"))
(nord-escape (if (nord-display-truecolor-or-graphic-p) "#D08770" "brightyellow"))
(nord-method (if (nord-display-truecolor-or-graphic-p) "#88C0D0" "brightcyan"))
(nord-keyword (if (nord-display-truecolor-or-graphic-p) "#81A1C1" "blue"))
(nord-numeric (if (nord-display-truecolor-or-graphic-p) "#B48EAD" "magenta"))
(nord-operator (if (nord-display-truecolor-or-graphic-p) "#81A1C1" "blue"))
(nord-preprocessor (if (nord-display-truecolor-or-graphic-p) "#5E81AC" "brightblue"))
(nord-punctuation (if (nord-display-truecolor-or-graphic-p) "#D8DEE9" "#D8DEE9"))
(nord-regexp (if (nord-display-truecolor-or-graphic-p) "#EBCB8B" "yellow"))
(nord-string (if (nord-display-truecolor-or-graphic-p) "#A3BE8C" "green"))
(nord-tag (if (nord-display-truecolor-or-graphic-p) "#81A1C1" "blue"))
(nord-variable (if (nord-display-truecolor-or-graphic-p) "#D8DEE9" "#D8DEE9"))
(nord-region-highlight-foreground (if (or
(string= nord-region-highlight "frost")
(string= nord-region-highlight "snowstorm")) "#2E3440" nil))
Expand Down

0 comments on commit a66c120

Please sign in to comment.