Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Incorrect Colours in Terminal #18

Open
zmanji opened this Issue · 75 comments
@zmanji

I'm not sure if this is a bug of solarized-emacs or my fault but when I load up emacs in a terminal window this is what i get:

However, my terminal has 256 color support and M-x list-colors-display displays all of the colours correctly. I don't know how to diagnose the issue further to determine where the problem lies.

@bbatsov
Owner

What's the value of your $TERM env variable?

@zmanji

$ echo $TERM
xterm-256color

@pmcao

Hi, is this issue fixed? I have exactly the same issue with same configuration as zmanji.

@bbatsov
Owner

Not yet. I've been very busy lately. @thomasf Can you have a look at this? Seems that we might need to adjust the colors we use in a terminal.

@thomasf
Collaborator

Yeah. I have thought about looking into this before (it affects me too). Since it didnt work in the first place I haven't been able to test it with my extended palette either. I might actually have some free time tomorrow to do it.

@thomasf
Collaborator

I think there has to be some kind of lookup table.

Here's even more alternative palettes:

(defcustom solarized-broken-srgb (if (eq system-type 'darwin) t nil)
  "Emacs bug #8402 results in incorrect color handling on Macs. If this is t
\(the default on Macs), Solarized works around it with alternative colors.
However, these colors are not totally portable, so you may be able to edit
the \"Gen RGB\" column in solarized-definitions.el to improve them further."
  :type 'boolean
  :group 'solarized)

;; FIXME: The Generic RGB colors will actually vary from device to device, but
;;        hopefully these are closer to the intended colors than the sRGB values
;;        that Emacs seems to dislike
(defvar solarized-colors           ; ANSI(Solarized terminal)
  ;; name     sRGB      Gen RGB   256       16              8
  '((base03  "#002b36" "#042028" "#1c1c1c" "brightblack"   "black")
    (base02  "#073642" "#0a2832" "#262626" "black"         "black")
    (base01  "#586e75" "#465a61" "#585858" "brightgreen"   "green")
    (base00  "#657b83" "#52676f" "#626262" "brightyellow"  "yellow")
    (base0   "#839496" "#708183" "#808080" "brightblue"    "blue")
    (base1   "#93a1a1" "#81908f" "#8a8a8a" "brightcyan"    "cyan")
    (base2   "#eee8d5" "#e9e2cb" "#e4e4e4" "white"         "white")
    (base3   "#fdf6e3" "#fcf4dc" "#ffffd7" "brightwhite"   "white")
    (yellow  "#b58900" "#a57705" "#af8700" "yellow"        "yellow")
    (orange  "#cb4b16" "#bd3612" "#d75f00" "brightred"     "red")
    (red     "#dc322f" "#c60007" "#d70000" "red"           "red")
    (magenta "#d33682" "#c61b6e" "#af005f" "magenta"       "magenta")
    (violet  "#6c71c4" "#5859b7" "#5f5faf" "brightmagenta" "magenta")
    (blue    "#268bd2" "#2075c7" "#0087ff" "blue"          "blue")
    (cyan    "#2aa198" "#259185" "#00afaf" "cyan"          "cyan")
    (green   "#859900" "#728a05" "#5f8700" "green"         "green"))
  "This is a table of all the colors used by the Solarized color theme. Each
   column is a different set, one of which will be chosen based on term
   capabilities, etc.")

(defun solarized-color-definitions (mode)
  (flet ((find-color (name)
           (let* ((index (if window-system
                             (if solarized-degrade
                                 3
                               (if solarized-broken-srgb 2 1))
                           (case (display-color-cells)
                             (16 4)
                             (8  5)
                             (otherwise 3)))))
             (nth index (assoc name solarized-colors)))))
    (let ((base03      (find-color 'base03))
          (base02      (find-color 'base02))
          (base01      (find-color 'base01))
          (base00      (find-color 'base00))
          (base0       (find-color 'base0))
          (base1       (find-color 'base1))
          (base2       (find-color 'base2))
          (base3       (find-color 'base3))
          (yellow      (find-color 'yellow))
          (orange      (find-color 'orange))
          (red         (find-color 'red))
          (magenta     (find-color 'magenta))
          (violet      (find-color 'violet))
          (blue        (find-color 'blue))
          (cyan        (find-color 'cyan))
          (green       (find-color 'green))
          (bold        (if solarized-bold 'bold 'normal))
          (bright-bold (if solarized-bold 'normal 'bold))
          (underline   (if solarized-underline t nil))
          (opt-under   nil)
          (italic      (if solarized-italic 'italic 'normal)))
      (when (eq 'light mode)
        (rotatef base03 base3)
        (rotatef base02 base2)
        (rotatef base01 base1)
        (rotatef base00 base0))
      (let ((back base03))
        (cond ((< (display-color-cells) 16)
               (setf back nil))
              ((eq 'high solarized-contrast)
               (let ((orig-base3 base3))
                 (rotatef base01 base00 base0 base1 base2 base3)
                 (setf base3 orig-base3)))
              ((eq 'low solarized-contrast)
               (setf back      base02
                     opt-under t)))
        ;; NOTE: We try to turn an 8-color term into a 10-color term by not
        ;;       using default background and foreground colors, expecting the
        ;;       user to have the right colors set for them.

source: https://github.com/sellout/emacs-color-theme-solarized/blob/master/solarized-definitions.el#L43

@bbatsov
Owner

Hmm, I wasn't aware of the Mac problem. We might need some lookup table as well after all.

@thomasf
Collaborator

Faces with colors for all display capabilities

Another importat feature is to produce faces that contains colors
for 8, 16, 256 and rgb or srgb so the theme works with different
terminal types at once.

Example:

(defvar solarized-colors
  ;; name    sRGB      Gen RGB   degraded  ANSI(Solarized terminal)
  '((base03  "#002b36" "#042028" "#1c1c1c" "#7f7f7f")
    (base02  "#073642" "#0a2832" "#262626" "#000000")
    (base01  "#586e75" "#465a61" "#4e4e4e" "#0a0a00")
    ...
  "This is a table of all the colors used by the solarized color theme. each
   column is a different set, one of which will be chosen based on term
   capabilities, etc.")

(defun solarized-face-for-index (facespec index)
  "Creates a face from facespec where the colors use the names of
  the `solarized-colors'."
  (let ((new-fontspec (copy-list facespec)))
    (dolist (property '(:foreground :background :color))
      (when (plist-get new-fontspec property)
       (plist-put new-fontspec property
                  (nth index (assoc (plist-get new-fontspec property)
                                    solarized-colors)))))
    (when (plist-get new-fontspec :box)
      (plist-put new-fontspec :box (solarized-face-for-index
                                    (plist-get new-fontspec :box) index)))
    new-fontspec))

(defun solarized-flip (facespec)
  "Convert a facespec to its lightened or darkened counterpart"
  (let* ((reversing-alist '((base03 . base3) (base02 . base2) (base01 . base1)
                            (base00 . base0) (base0 . base00) (base1 . base01)
                            (base2 . base02) (base3 . base03))))
    (mapcar (lambda (term) (cond ((listp term) (solarized-flip term)) 
                            ((assoc term reversing-alist)
                             (cdr (assoc term reversing-alist)))
                            (t term))) facespec)))

(defun solarized-faces (facespecs mode)
  (mapcar (lambda (facespec-with-name)
            (let* ((name (car facespec-with-name))
                   (facespec (funcall
                              (if (eq mode 'dark) 'solarized-flip 'identity)
                              (second facespec-with-name)))
                   (flipped-facespec (solarized-flip facespec))
                   (facespec-tty-256 (solarized-face-for-index facespec 3))
                   (facespec-tty-term (solarized-face-for-index facespec 4))
                   (facespec-default (solarized-face-for-index facespec 2)))
              `(,name
                ((((min-colors 257)) ,facespec-default)
                 (((min-colors 256)) ,facespec-tty-256)
                 (((min-colors 16)) ,facespec-tty-term)
                 ;; We should rarely if ever fall to the default.  If
                 ;; so, let's set it to the default light spec and
                 ;; hope for the best.
                 (t ,facespec-default))))) facespecs))

(defun solarized-color-definitions (mode)
  ...
  (let ((bold               (if solarized-bold 'bold 'normal))
        (underline          (if solarized-underline t nil))
        (italic             (if solarized-italic 'italic 'normal)))
    (list
     ;; First list is for faces
     (append
      (solarized-faces
       `( ;; basic
         (default (:foreground base00 :background base3))
         (cursor (:foreground base00 :background base3 :inverse-video t))
         (fringe (:foreground base1 :background base2))
         ...

source: https://github.com/ahyatt/emacs-color-theme-solarized/blob/master/solarized-definitions.el#L72

Adapt faces individually for different color capabilities.

It might come in handy, especially considering that it is likley
to be impossible to use the dark/light accented colors at all without it.

@pmcao

Is there any workaround for Mac user? I am using emacs24, iTerm2 with xterm-256 setting.

@thomasf
Collaborator

well, if you are only using emacs under a terminal you could try to replace all the values in solarized-theme.el with the ones in the 256-color column above.
Since the bright/dark accented colors used here and there are not a part of the solarized theme and I haven't had any time to experiment with them with reduced color capabilites you either have to find acceptable 256-color version of them (might be possible) or remove them from the theme definitions alltogether. The expanded accented colors are not used in many places at all and I plan to try to reduce and/or define their usage even more when taking on this issue.

@pmcao

Thanks. It works perfectly now!

@thomasf thomasf referenced this issue from a commit
@thomasf thomasf Experimental branch for issue #18.
The goal is to fully support different terminal types (amount of colors) at the same time.
Emacsclient can then be used in both a terminal and an window-system at the same time without strageness.

Currently this is mostly a copy and paste from:
https://github.com/ahyatt/emacs-color-theme-solarized/blob/master/solarized-definitions.el#L72

todo:
- organize
- remove old stuff
- child themes
- theme custom vars
- hc/lc colors
- docs
- test, test, test
dbf35d6
@thomasf
Collaborator

Here is some additional stuff that might be interesting:

sellout/emacs-color-theme-solarized#80

(defcustom solarized-terminal-themed t
  "Non-nil when the terminal emulator has been themed with Solarized.
In this scenario, we do not set the background color, in favor of the more
accurate version of the color in the default terminal background."
  :type 'boolean
  :group 'solarized)

(defcustom solarized-contrast 'normal
  "Stick with normal! It's been carefully tested. Setting this option to high or
low does use the same Solarized palette but simply shifts some values up or
down in order to expand or compress the tonal range displayed."
  :type 'symbol
  :options '(high normal low)
  :group 'solarized)

(defcustom solarized-broken-srgb (if (and (eq system-type 'darwin)
                                          (eq window-system 'ns))
                                     t
                                   nil)
  "Emacs bug #8402 results in incorrect color handling on Macs. If this is t
\(the default on Macs), Solarized works around it with alternative colors.
However, these colors are not totally portable, so you may be able to edit
the \"Gen RGB\" column in solarized-definitions.el to improve them further."
  :type 'boolean
  :group 'solarized)

;; FIXME: The Generic RGB colors will actually vary from device to device, but
;;        hopefully these are closer to the intended colors than the sRGB values
;;        that Emacs seems to dislike
(defvar solarized-colors           ; ANSI(Solarized terminal)
  ;; name     sRGB      Gen RGB   256       16              8
  '((base03  "#002b36" "#042028" "#1c1c1c" "brightblack"   "black")
    (base02  "#073642" "#0a2832" "#262626" "black"         "black")
    (base01  "#586e75" "#465a61" "#585858" "brightgreen"   "green")
    (base00  "#657b83" "#52676f" "#626262" "brightyellow"  "yellow")
    (base0   "#839496" "#708183" "#808080" "brightblue"    "blue")
    (base1   "#93a1a1" "#81908f" "#8a8a8a" "brightcyan"    "cyan")
    (base2   "#eee8d5" "#e9e2cb" "#e4e4e4" "white"         "white")
    (base3   "#fdf6e3" "#fcf4dc" "#ffffd7" "brightwhite"   "white")
    (yellow  "#b58900" "#a57705" "#af8700" "yellow"        "yellow")
    (orange  "#cb4b16" "#bd3612" "#d75f00" "brightred"     "red")
    (red     "#dc322f" "#c60007" "#d70000" "red"           "red")
    (magenta "#d33682" "#c61b6e" "#af005f" "magenta"       "magenta")
    (violet  "#6c71c4" "#5859b7" "#5f5faf" "brightmagenta" "magenta")
    (blue    "#268bd2" "#2075c7" "#0087ff" "blue"          "blue")
    (cyan    "#2aa198" "#259185" "#00afaf" "cyan"          "cyan")
    (green   "#859900" "#728a05" "#5f8700" "green"         "green"))
  "This is a table of all the colors used by the Solarized color theme. Each
   column is a different set, one of which will be chosen based on term
   capabilities, etc.")

(defun solarized-face-for-index (facespec index &optional back fg)
  "Creates a face from facespec where the colors use the names of
  the `solarized-colors'."
  (let ((new-fontspec (copy-list facespec)))
    (dolist (property '(:foreground :background :color))
      (let ((color (plist-get new-fontspec property)))
        (when color
          (cond ((and solarized-terminal-themed
                      (eq property :background) (memq color back))
                 (plist-put new-fontspec property "unspecified-bg"))
                ((and solarized-terminal-themed
                      (eq property :foreground) (memq color fg))
                 (plist-put new-fontspec property "unspecified-fg"))
                (t (plist-put new-fontspec property
                              (nth index (assoc color solarized-colors))))))))
    (when (plist-get new-fontspec :box)
      (plist-put new-fontspec :box (solarized-face-for-index
                                    (plist-get new-fontspec :box) index)))
    new-fontspec))

(defun solarized-flip (facespec)
  "Convert a facespec to its lightened or darkened counterpart"
  (let* ((reversing-alist '((base03 . base3) (base02 . base2) (base01 . base1)
                            (base00 . base0) (base0 . base00) (base1 . base01)
                            (base2 . base02) (base3 . base03))))
    (mapcar (lambda (term) (cond ((listp term) (solarized-flip term))
                            ((assoc term reversing-alist)
                             (cdr (assoc term reversing-alist)))
                            (t term))) facespec)))

(defun solarized-faces (back fg facespecs mode)
  (mapcar (lambda (facespec-with-name)
            (let* ((name (car facespec-with-name))
                   (facespec (funcall
                              (if (eq mode 'light) 'solarized-flip 'identity)
                              (second facespec-with-name)))
                   (facespec-tty-256 (solarized-face-for-index facespec 3 back fg))
                   (facespec-tty-term (solarized-face-for-index facespec 4 back fg))
                   (facespec-tty-8 (solarized-face-for-index facespec 5 back fg))
                   (facespec-default (if solarized-broken-srgb
                                         (solarized-face-for-index facespec 2)
                                       (solarized-face-for-index facespec 1))))
              `(,name
                ((((min-colors 257)) ,facespec-default)
                 (((min-colors 256)) ,facespec-tty-256)
                 (((min-colors 16)) ,facespec-tty-term)
                 (((min-colors 8)) ,facespec-tty-8)
                 ;; We should rarely if ever fall to the default.  If so, let's
                 ;; set it to the default spec and hope for the best.
                 (t ,facespec-default))))) facespecs))

(defun solarized-color-definitions (mode)
  "Define colors that make up Solarized."
  ;; We define everything for dark mode, but we generate light mode
  ;; automatically in `solarized-faces.'
  ;;
  ;; See http://ethanschoonover.com/solarized#features for an explanation
  ;; of what the base00/base0 names stand for
  (let* ((bold        (if solarized-bold 'bold 'normal))
         (bright-bold (if solarized-bold 'normal 'bold))
         (underline   (if solarized-underline t nil))
         (opt-under   (eq 'low solarized-contrast))
         (italic      (if solarized-italic 'italic 'normal))
         (back        (if (eq 'low solarized-contrast) 'base02 'base03))

         (bg-back     `(:background ,back))
         (bg-base03   `(:background base03))
         (bg-base02   `(:background base02))
         (bg-base01   `(:background base01))
         (bg-base00   `(:background base00))
         (bg-base0    `(:background base0))
         (bg-base1    `(:background base1))
         (bg-base2    `(:background base2))
         (bg-base3    `(:background base3))
         (bg-green    `(:background green))
         (bg-yellow   `(:background yellow))
         (bg-orange   `(:background orange))
         (bg-red      `(:background red))
         (bg-magenta  `(:background magenta))
         (bg-violet   `(:background violet))
         (bg-blue     `(:background blue))
         (bg-cyan     `(:background cyan))

         (fg-base03   `(:foreground base03))
         (fg-base02   `(:foreground base02))
         (fg-base01   `(:foreground base01))
         (fg-base00   `(:foreground base00))
         (fg-base0    `(:foreground base0))
         (fg-base1    `(:foreground base1))
         (fg-base2    `(:foreground base2))
         (fg-base3    `(:foreground base3))
         (fg-green    `(:foreground green))
         (fg-yellow   `(:foreground yellow))
         (fg-orange   `(:foreground orange))
         (fg-red      `(:foreground red))
         (fg-magenta  `(:foreground magenta))
         (fg-violet   `(:foreground violet))
         (fg-blue     `(:foreground blue))
         (fg-cyan     `(:foreground cyan))
         (fg-none     `(:foreground "unspecified-fg"))
         (fmt-none    `(:weight normal :slant normal  :underline nil        :inverse-video nil))
         (fmt-bold    `(:weight ,bold  :slant normal  :underline nil        :inverse-video nil))
         (fmt-bldi    `(:weight ,bold                 :underline nil        :inverse-video nil))
         (fmt-undr    `(:weight normal :slant normal  :underline ,underline :inverse-video nil))
         (fmt-undb    `(:weight ,bold  :slant normal  :underline ,underline :inverse-video nil))
         (fmt-undi    `(:weight normal                :underline ,underline :inverse-video nil))
         (fmt-uopt    `(:weight normal :slant normal  :underline ,opt-under :inverse-video nil))
         ;; FIXME: not quite the same
         (fmt-curl    `(:weight normal :slant normal  :underline t          :inverse-video nil))
         (fmt-ital    `(:weight normal :slant ,italic :underline nil        :inverse-video nil))
         ;; FIXME: not quite the same
         (fmt-stnd    `(:weight normal :slant normal  :underline nil        :inverse-video t))
         (fmt-revr    `(:weight normal :slant normal  :underline nil        :inverse-video t))
         (fmt-revb    `(:weight ,bold  :slant normal  :underline nil        :inverse-video t))
         (fmt-revbb   `(:weight ,bright-bold :slant normal :underline nil  :inverse-video t))
         (fmt-revbbu  `(:weight ,bright-bold :slant normal  :underline ,underline :inverse-video t)))
    (list
     ;; First list is for faces
     (solarized-faces `(,back) '(base0 base1)
      `(;; basic
        (default (,@fg-base0 ,@bg-back)) ; Normal
        (cursor (,@fg-base03 ,@bg-base0)) ; Cursor
        (error (,@fmt-bold ,@fg-red)) ; Error
        (escape-glyph-face (,@fg-red))
        (fringe (,@fg-base01 ,@bg-base02))
        (linum (,@fg-base01 ,@bg-base02))
        (header-line (,@fg-base0 ,@bg-base02 ,@fmt-revbb)) ; Pmenu
        (highlight (,@fg-none ,@bg-base02))
        (hl-line (:underline ,opt-under ,@bg-base02)) ; CursorLine

        ...
@chalmagean

+1 (I'd also like to see this fixed)

@localredhead

This affects me as well. OSX, Terminal App, 256 Term.

@kzahel

I am also looking for a nice iterm2 xterm-256color solution. Getting the ugly blue background for solarized-dark. Will try some of the above suggestions though

@thomasf
Collaborator

Although it kind of works, for a full solution its a bit more complicated than just replacing palettes . We are also using an extended version of solarized that is only possible with an display manager.. Ive been thinking latley that is might be a better idea to actually maintain separate defs for hi color and other color modes. I would be happy with only two versions. Either full rgb or adapted to when your terminal is configured with the 16 color solarized palette.

The extra acccented colors were introduced because of the many possible combinations of modes that are available and its not certain that other colors are a good fit if the accecnted colors are not used..

(Ive been quietly experimenting with this for a while)

@localredhead

I got the correct colors by modifying solarized.el for the Base 02 and Base 03 colors. I used brightblack for base 03 and black for base 02, which was #7f7f7f and #000000 respectively. In a terminal everything looks correct with these options.

I then had to force byte-compile solarized theme and everything works but GUI mode is now innaccurate.

The part that confuses me is that the colors that worked are part of the 16 color pallet, yet my emacs reports that it has 256 colors and my TERM is set to be 256 colors.

@thomasf
Collaborator

well, it will actually only mostly work but not close enough is not be solid solution.
Also there are some inconsistencies right now in the color defs like how highlights work, sometimes it is impossible to resolve because two concurrent modes will be active and there has to be a way to distinguish between them,
Thats why I have started working on #55 before I dive into anything that will further fragmentize the face defs.

@andschwa

@thomasf How's the visual testing project going, anything we can help with?

@ronert

Would also love to see a solution to this, as I am having the same issue with on OS X with iTerm2.

@roryk

+1 for this.

@Nekroze

I have just installed this on my xubuntu 13.04 using emacs under the command line and i get this problem as well. However it seems to have just disapeared. I am not sure how it happened and cannot reproduce it but now it looks perfect.

Any word on this getting fixed properly, I still have the issue on my other computers.

@Nekroze

I have just been able to reproduce a kind of fix. No idea how it works as i am not that savy on the internals of emacs packages. This is exactly what i have done twice to get the theme looking, i think, the way it is meant to.

  1. Activate solarized-dark theme
  2. Install monokai-theme (i think its from marmalade repo)

As soon as the theme installed there was a change in the way the solarized theme looked. Not sure if it now looks as intended but it is an improvement. Still, no idea why this would change anything anyways and may not even be related to this issue so.

@andschwa
(package-install 'color-theme-solarized)
(load-theme 'solarized-dark)

The above code has been working for me with the Cocoa build of Emacs 24.3.1.

@bbatsov
Owner

@andschwa This is another package. Ours is named just solarized-theme.

@andschwa

@bbatsov Yeah, both used to be broken, the current working Solarized Emacs theme is here: https://github.com/sellout/emacs-color-theme-solarized (color-theme-solarized). What's the status of the repair for solarized-emacs?

@bassu

This is also a problem in Emacs running on rxvt-256 terminal as well as xterm-256 on Linux.
Seems impossible to run solarized on 256 color terminals.

@thomasf
Collaborator

Yeah. sadly it is quite a big job puting all of this together in a coherent and manageable way while supporting all different variations of color schemes.. This solarized theme also has added hi/lo contrast versions of the accent colors which are used rarely but makes it harder to straight up support things like a 16 color terminal.

I want to do it but I have no idea when I have the time available.

@bassu

@thomasf I guess I partially figured out what is happening. There is some configuration dependency in Emacs 24 that needs to be turned on and the Solarized themes start working in 256 color mode (including all of its derivatives like Base16 or Noctilux).

Like it happened with @Nekroze all the way back in September, all I was doing, was to install bunch of new themes via MELPA repository and the problem disappeared on its own.

If you need more information, just tell me what to gather and I will be glad to help in troubleshooting and finding the root cause that has left everyone here clueless for a few years. Thanks!

@antoinelyset

Same problem here. I would love to see a fix :heart:

@brandonw

It's pretty rough transitioning from vim to emacs with evil mode. I now have to choose to use either sellout's emacs solarized theme and have working console colors, but no colors to handle all the current major and minor modes of the day. Or I can use this theme, which is far superior in every way except for the terminal due to the issues in this thread.

The advantage, of course, is that this version is being updated still, while the original has been dormant for years. I'm hoping you guys can muddle through and find a way to make the terminal work. It isn't horrible if you downgrade to 16 color term, at least. 256 color term is pretty unusable, though.

@thomasf
Collaborator

I actually use both, i use the sellout version in the terminal and this version otherwise. I want to stop doing this..
I have renamed the sellout version package to have em both installed at the same time.

(defvar theme-bright 'my-solarized-light "A light theme.")
(defvar theme-dark 'my-solarized-dark "A dark theme.")
(unless window-system
  (setq theme-dark 'sellout-solarized-dark
        theme-bright 'sellout-solarized-dark))

(defun post-change-theme ()
  (set-face-inverse-video-p 'vertical-border nil)
  (set-face-background 'vertical-border (face-background 'default)))
(dont-compile
  (set-display-table-slot standard-display-table
                          'vertical-border
                          (make-glyph-code ?┃)))

(defun dark-theme ()
  "Switch to dark mode (dark color theme)"
  (interactive)
  (if degrade-p-old-emacs
      (load-theme theme-dark)
    (load-theme theme-dark t))
  (setq dark-theme-on t)
  (post-change-theme))


(defun bright-theme ()
  "Switch to light mode (light color theme)"
  (interactive)
  (if degrade-p-old-emacs
      (load-theme theme-bright)
    (load-theme theme-bright t))
  (setq dark-theme-on nil)
  (post-change-theme))

(defun toggle-dark-theme ()
  "Toggle between light and dark modes"
  (interactive)
  (if (bound-and-true-p dark-theme-on)
      (bright-theme)
    (dark-theme))
  (post-change-theme))
@jsakkine

I just use TERM=xterm emacs -nw as a workaround when starting from command-line and for example in mutt I have set editor='TERM=xterm emacsclient -a ""'. Not too much trouble..

@jinpoc

+1 for a working update. Even the sellout colors are wrong in my Terminal.app/xterm-256color.

@PythonNut

I'm still seeing an incorrect background. I'm on gnome-terminal set to xterm-256color (I've also tested it in xterm, gnome, and gnome-256color). Everything is fine, except for the background, which is in the same blue as seen in the OP.

I haven't used the code seem in this thread, I'm using the regular theme.

@jinpoc

fwiw, I just tried out iterm2 and everything is working

@localredhead

I can confirm that the working theme appears to be https://github.com/sellout/emacs-color-theme-solarized (color-theme-solarized) .

This theme only works if I launch emacs using emacsclient -t. If I use emacs -nw the colors are wrong.

This is my .bash_profile

export TERM=xterm-256color                                                                                                                
export ALTERNATE_EDITOR="" EDITOR=emacsclient VISUAL=emacsclient
export CLICOLOR=1
@bassu

Resolved.

Append at the very last of .emacs

(custom-set-faces (if (not window-system) '(default ((t (:background "nil"))))))

In short: Let the terminal decide the background color cause Emacs 24 has several color related bugs.

@andschwa

@bassu I wouldn't say that resolves this... it's a workaround (for the background at least), but the cause of this issue is still unresolved, and other colors still don't seem to be right. If I could I'd re-open this issue.

@bassu

@andschwa This bug has been mainly about the background color. The cause of the issue is logically the same i.e. faces' backgrounds screwing up in terminal. No one talked about it here before! I still want to go through the code to see where you would fix that but this theme originally has been written for X and I probably will (if I get the time). This workaround resolves the aforementioned problem. If you are getting incorrect colors in terminal, check your terminal color profile.

@thomasf
Collaborator

There are several problems related to this, most buyt not all of them will be solved by using a table a for color codes.. I have referenced several of these things in this issue comment thread..

@thomasf
Collaborator

Currently it seems that the unified branch of the other emacs solarized theme has an almost finished solution. I'm tempted to use it all as a new base for this theme. Iv'e just read the code, not tried it out so I'm not aware of any problems with it atm.

https://github.com/sellout/emacs-color-theme-solarized/tree/unified

@bbatsov
Owner

@thomasf Seems like a good option.

@bassu

With Emacs 24 I don't have any issues with this theme except of the two things:
a) default background color and b) font-lock-keyword-face foreground face.

Both of the above fixable by customization, of course!

I find coverage in @bbatsov's version quite extensive than the @sellout's version notably powerline etc., which is why I really like this version :heart_decoration:

Thanks @bbatsov for this among other things like the ruby guidelines :laughing:

@bbatsov
Owner

@bassu, what @thomasf means is that we can reuse code from the unified branch of the other theme to reliably correct our existing shortcoming. There's just one reason why I haven't attended to this problem at all myself - I almost don't use Emacs in a terminal, since I run my terminals inside Emacs :-)

@bassu

@bbatsov ah okay! If unification is the solution, I would love to see that :lollipop:

About terminal in Emacs, that's as intriguing as funny considering the operating system nature of Emacs, hehe :cool: But I guess many people prefer it to be that broad, as it is! I would try Emacs to be so but it cannot properly do dynamic vtc management or multiplexing such as that of dvtm or tmux let alone be a full flight terminal :wink:

@thomasf
Collaborator

So, Ive begun this work, for now in a separate private repository with both themes as submodules..
At the moment I have almost finished an utility for converting facedefs between the formats.
I will work on this in private when time given until I have sorted out the major features.

I will make the work public by creating a v2.0 branch later on,.

@thomasf thomasf was assigned
@thomasf thomasf referenced this issue from a commit
@thomasf thomasf Add newlines in a few places
This is only to silly regexps that migrate tool uses for #18
d012059
@dholm dholm referenced this issue in dimitri/el-get
Closed

add solarized-emacs #1001

@thomasf
Collaborator

An update:
From experiments with porting I have come to the conclusion that I must have tests that hopefully can be automated but more importantly will give me screenshots for maual a/b verification since this will be a large change affecting almost everything. I've started working on that. Learning ert/ecukes, doing it right from the start and so on.

Anyone know of any other emacs theme that has a test suite?

@andschwa

:+1: I really like the work you guys are doing.

@localredhead

There has been really good progress on this. With the most recent Emacs 24.4 / prelude / solarized My terminal colors are now very close to correct IF you install the Solarized theme here https://github.com/tomislav/osx-terminal.app-colors-solarized.

With the combination of Terminal.app solarized theme and this theme the colors are the most usable it has been in a long time.

@andschwa

@localredhead Hm, I'm still having the major issue with the with the background being blue. Have you done anything else to it? I'm using Emacs 24.4, Terminal, and @bbatsov's Solarized theme (I double-checked), and @tomislav's theme.

@andschwa

@localredhead Specifically, what's your $TERM variable? Mine is xterm-256color. However, yes, the colors are pretty getting much closer with xterm-16color (at least, the background isn't blue).

@thomasf
Collaborator

@andschwa @localredhead , yes setting your term to 16colors and having a solarized palette in your terminal makes things look more solarized but the colors are all mixed up and the non standard solarized colors has to degrade into 8/16/256-color-versions. That is what is visually missing.

@andschwa

Yup. It's just off enough that, in terminal, I use the built-in wombat theme. Here's my init.el snippet, it's conditioned on display-graphic-p and uses the awesome use-package repo (my full Emacs configuration).

(if (display-graphic-p)
    (use-package solarized
      :init
      (progn
    (setq solarized-use-variable-pitch nil)
    (setq solarized-high-contrast-mode-line t)
    (load-theme 'solarized-dark t)))
  (load-theme 'wombat t))
@localredhead

@andschwa I am actually running tmux in Terminal.app as well.
localredhead:archer trumaker$ echo $TERM
xterm-256color

in my .tmux.conf:
set -g default-terminal "screen-256color"

I suppose if you are being picky then its not perfect but most colors seem close enough to work. I just really enjoy the blue background and currently all the defaults seem usable in this state for me.

I do hope to see it improve.

screen shot 2014-05-19 at 2 00 02 pm

@PythonNut

I'm also running in tmux on Arch Linux. I have TERM=screen-256color and everything is perfect except the background is the same as the OP. Running in GNOME Terminal.

@syl20bnr

@thomasf any update on this ? Will you create a branch for a 2.0 ? Thank you.

@thomasf
Collaborator

Well, no :(

2.0 branch trials

I have tried to do it a few times, I have at least 5 very experimental 2.0 branches.
Sadly the complexity of the variations of this theme quickly becomes a problem whichever way I have tried.

tests

I haven't even had time to get the tests running yet which I believe is the first step.

The main reason for me wanting tests is to be able to let it take screenshots. I want to be able to do things like generate lets say an picture of a specific test case in 8/16/256/... colors to actually get a grip of whats going on..

@PythonNut

Just another data point: Fedora over SSH to a MinTTY looks fine in light mode, but like the OP in dark mode.

@andersjohansson

@sellout has been doing some work on merging the unified-branch of the other theme (https://github.com/sellout/emacs-color-theme-solarized/) and creating tests recently (in the last 24 hours). I don't know how that relates to your work @thomasf, but I guess it could be useful to unite these efforts. I really like the "unified"-approach, and have been using this theme mostly because it supports more faces. Having the two themes merged in some way would also be quite cool.

@mikefaille

I personnaly have this problem with emacs -nw on X with TERM="term-256color" and tty terminals using Linux.
Note : I think tty can be usefull to recover systems. (no more use case for me)

@thomasf
Collaborator

@andersjohansson The version of solarized is a bit more complex because it's really an extended solarized in it's current high color only theme.

My previous attempt at doing this was unsuccessful because I was not satisfied with the preciseness of the code when doing it with the basic emacs lisp functions and macros.

Next time I will use pattern matching to build the facedefs. The target is to only depend on dash.el. I was actually holding off this work while waiting for dash.el to get support for plists which it now has!

@mikefaille

@thomasf I personally pass a lot of time to find.. Why Wombat OEM for e24 work always with load theme ? !
Emacs OEM theme set is only theme who always work using : kmscons --palette solarized
or just kmscons (without palette)
It's cool because... Wombat for e24 is really simple : http://git.savannah.gnu.org/cgit/emacs.git/tree/etc/themes/wombat-theme.el?h=emacs-24

Why emacs theme can be complicated ? It's because color theme embedded interpolation between desired and current env. palette limitation.
If I understand by experience, emacs seems to interpolate colors very well by default.
I think this is documented too (english isn't my 1st language and I try to don't use Google translate to practice..) : https://www.gnu.org/software/emacs/manual/html_node/efaq/Colors-on-a-TTY.html
In Emacs 21.1 and later, colors and faces are supported in non-windowed mode, i.e., on Unix and GNU/Linux text-only terminals and consoles, and when invoked as ‘emacs -nw’ on X, and MS-Windows. Emacs automatically detects color support at startup and uses it if available.
I think emacs load tty-colors http://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/term/tty-colors.el?h=emacs-24 to dynamically ajust emacs palette from env. and interpolate theme color. (as seen on http://git.savannah.gnu.org/cgit/emacs.git/tree/src/xfaces.c?h=emacs-24 tty_lookup_color() )

My suggestion :
Make simple solarized theme using no color interpolation/adjustment in theme script.

@thomasf
Collaborator

First, wombat is a simple theme just defining the basic faces of emacs. This solarized theme also defines specific faces for many many more modes, without looking I would guess that solarized has more than 10 times as much definitions.

I'm not sure which interpolation you are referring to exactly but there are several kinds of mappings that has to be done in the theme to support things like the terminal solarized palette https://github.com/altercation/solarized#the-values
. especially for 8 and 16 color modes.

Theres always the other solarized theme for people who wants something else: https://github.com/sellout/emacs-color-theme-solarized/

@mikefaille

@thomasf _First, wombat is a simple theme just defining the basic faces of emacs. _
I know. But, for "simple" theme, I talk only about main color correctness. --> I want color "theme" for all modes I use for sure, but basic colors must work first in most conditions. It seems it possible to do it simply.

Interpolate = choosing most correct way to provide correctness with constraint. Like drawing an diagonal line with pixel. So, interpolation for me is mapping for you. I'll use mapping in future.

Tomasf, I tested solaried only on 256 color terminal. Just to be sure, kmscons tty can use 256 color at time but dynamically (the palette is dynamic depending what color you ask ). And, emacs OEM theme always work under all condition. (I talk about base color only like background color for example).

@thomasf
Collaborator

The problem with a regular 256 color display is that it cannot display the correct solarized colors, so the specified 16color palette which has to be configured in the terminal client is preferable to an 256color term. This is one instance where the theme starts to depend on user terminal configuration.

This theme also does some color blending to produce color ranges for cases like vc-annotate and other.. I was not sure if you were referring to that as interpolation.. Now I understand. Mapping would probably be the correct term for what we are talking about (it cannot be interpolated).

The background color is actually specified as #002b36. IIRC, emacs own interpolation/mapping is what is seen in the image at the top of this issue. This happens if TERM is one of the supported 256color terminals that emacs supports.

In the solarized mapping table #002b36 should respond to #1c1c1c in 256 color mode or color number 8 in 16 color mode (if solarized is correctly configured for the terminal).

The full extent of resolving this issue is that all color modes should work. That means that an additional reduction of colors are required to replace the blended color combinations with one of the 0-16 indexed versions. Faces maybe even needs totally different defs in low color modes to avoid collisions there.. This is why this issue does not have an quick fix that actually covers what needs to be done fully.

@thomasf
Collaborator

@mikefaille Trying to answer your initial query:

The reason why this is a non issue for the wombat theme is that it does not have to adapt to an extended set of environmental (color mode) properties.

If this is to be maintainable (in this theme) the facedefs have to be build using some kind of composition while keeping the option to add exceptions for indivudual facedefs so that the lowest color modes can be constructed properly..

The sellout theme has about 100 lines of code to support the "easier" non extended solarized which kind of starts here:

https://github.com/sellout/emacs-color-theme-solarized/blob/master/solarized-definitions.el#L93

@mikefaille

-Wow, thank you for your complete answer ! I'll try to help soon. (~1 week)-
I tried and i'm not sure I have time to resolve this bug...

@PythonNut PythonNut referenced this issue in purcell/color-theme-sanityinc-solarized
Open

Background color incorrect in some terminals #16

@localredhead

I gave up on solarized.... Just use zenburn as it just works and looks great in the terminal.

@andschwa

@localredhead I do both!

;; theme (zenburn in terminal, solarized otherwise)
(use-package solarized
  :if (display-graphic-p)
  :load-path ,(f-expand "site-lisp/solarized-emacs" user-emacs-directory)
  :config
  (progn
    (setq solarized-use-variable-pitch nil
      solarized-scale-org-headlines nil)
    (load-theme 'solarized-dark t)))

(use-package zenburn-theme
  :if (not (display-graphic-p))
  :init (load-theme 'zenburn))
@tuhdo tuhdo referenced this issue in syl20bnr/spacemacs
Closed

Use Zenburn as default theme #895

@thomasf
Collaborator

This is what I do in init.el. I find anti zenburn to be a good choice for 256color light terminals. It's close to what @andschwa is doing.

(defvar theme-bright nil "A light theme.")
(defvar theme-dark nil "A dark theme.")

(use-package solarized-theme
  :ensure t
  :if window-system
  :init
  (progn
    (setq solarized-use-less-bold t
          solarized-use-more-italic t
          solarized-emphasize-indicators nil
          solarized-distinct-fringe-background nil
          solarized-high-contrast-mode-line nil))
  :config
  (progn
    (load "solarized-theme-autoloads" nil t)
    (setq theme-dark 'solarized-dark
          theme-bright 'solarized-light)))

(use-package zenburn-theme
  :ensure t
  :if (not window-system)
  :config
  (progn
    (use-package anti-zenburn-theme
      :ensure t
      :config
      (load "anti-zenburn-theme-autoloads" nil t))
    (load "zenburn-theme-autoloads" nil t)
    (setq theme-dark 'zenburn
          theme-bright 'anti-zenburn)))

(defun post-change-theme ()
  (set-face-inverse-video-p 'vertical-border nil)
  (set-face-background 'vertical-border (face-background 'default)))

(eval
 '(set-display-table-slot standard-display-table
                          'vertical-border
                          (make-glyph-code ?┃)))

(defun dark-theme ()
  "Switch to dark mode (dark color theme)."
  (interactive)
  (when theme-dark
    (load-theme theme-dark t)
    (setq dark-theme-on t)
    (post-change-theme)))

(defun bright-theme ()
  "Switch to light mode (light color theme)."
  (interactive)
  (when theme-bright
    (load-theme theme-bright t)
    (setq dark-theme-on nil)
    (post-change-theme)))

(defun toggle-dark-theme ()
  "Toggle between light and dark modes."
  (interactive)
  (if (bound-and-true-p dark-theme-on)
      (bright-theme)
    (dark-theme))
  (post-change-theme))

(and (not (boundp 'dark-theme-on))
   (not noninteractive)
   (bright-theme))
@andschwa

@thomasf I like your toggle! Totally going to borrow it :smile:

@thomasf
Collaborator

It's not very pretty but it works.. I have a macro that precompiles the load path so that I do not have to require package.el at load time so thats why the (load "solarized-theme-autoloads" nil t) are there since they modify the theme paths which is not in my load-path macro (right now).

@jarandaf

+1, using solarized preset within iTerm2 for the time being

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.