Incorrect Colours in Terminal #18

Open
zmanji opened this Issue Apr 14, 2012 · 98 comments

Comments

Projects
None yet

zmanji commented Apr 14, 2012

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.

Owner

bbatsov commented Apr 17, 2012

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

zmanji commented Apr 17, 2012

$ echo $TERM xterm-256color

Owner

bbatsov commented May 14, 2012

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.

Collaborator

thomasf commented May 14, 2012

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.

Collaborator

thomasf commented May 17, 2012

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

Owner

bbatsov commented May 17, 2012

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

Collaborator

thomasf commented Jun 15, 2012

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.

Collaborator

thomasf commented Jun 29, 2012

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.

thomasf added a commit that referenced this issue Nov 5, 2012

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
Collaborator

thomasf commented Mar 7, 2013

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

        ...

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

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

kzahel commented May 15, 2013

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

Collaborator

thomasf commented May 15, 2013

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)

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.

Collaborator

thomasf commented May 17, 2013

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.

Contributor

andschwa commented Jul 1, 2013

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

ronert commented Aug 10, 2013

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

roryk commented Aug 22, 2013

+1 for this.

Nekroze commented Aug 29, 2013

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 commented Sep 1, 2013

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.

Contributor

andschwa commented Sep 1, 2013

(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.

Owner

bbatsov commented Sep 1, 2013

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

Contributor

andschwa commented Sep 1, 2013

@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 commented Nov 9, 2013

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.

Collaborator

thomasf commented Nov 10, 2013

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 commented Nov 10, 2013

@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!

Same problem here. I would love to see a fix ❤️

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.

Collaborator

thomasf commented Nov 28, 2013

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))

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 commented Dec 8, 2013

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

Contributor

PythonNut commented Dec 14, 2013

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 commented Dec 14, 2013

fwiw, I just tried out iterm2 and everything is working

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 commented Jan 2, 2014

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.

Contributor

andschwa commented Jan 3, 2014

@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 commented Jan 4, 2014

@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.

Contributor

andschwa commented Feb 12, 2015

@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 Mar 21, 2015

Closed

Use Zenburn as default theme #895

Collaborator

thomasf commented Apr 12, 2015

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))
Contributor

andschwa commented Apr 14, 2015

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

Collaborator

thomasf commented Apr 14, 2015

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).

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

I still have this issue. Has anyone figured out how to fix this?

bassu commented Jul 14, 2015

People, please stop complaining because at this point, we literally want you to switch to the GUI 😈

@bassu, not willing to be rude, but I you should the question better =]. I never complained. Just asked if anyone managed to fix it.
I am using the GUI. Just curious to know about Term :).

Cheers!

Oh and btw, the work you guys are doing is great.

Personnally, I use the gui, but my shell work better than tramp sometimes under remote conditions; then, actually I switch to vim... for shell. (my normal usage is emacs as possible)

bassu commented Jul 14, 2015

@ephexeve Yeah, I was just being cynical, LOL. For the easiest and simplest workaround: see my last year's comment in this very bug report. Make sure to set solarized dark theme in whatever terminal you are using.

@bbatsov Will do that, I barely use Emacs on the Terminal anyway, but when I use it, I will just work with the ugly blue theme :p. Like they say, YOLO.

bassu commented Jul 14, 2015

@ephexeve LOL, okay. The workaround is pretty simple; is just one line though. But you replied to @bbatsov, and I think he'll not be happy to find this bug's email the very first thing he sees when he wakes up this morning. Haha. 🍻

Contributor

PythonNut commented Sep 14, 2015

An alternative solution that may interest y'all is implementing 24 bit terminal colors in Emacs. It's already supported in most of the major terminals.

Sadly, I don't know enough C and Emacs guts to implement this myself. I know there were some patches flying around that added it, but I think the person working on them went MIA.

Of course, this would be even better than trying to fix 256color support, although the two solutions are not mutually exclusive.

@cpaulik cpaulik referenced this issue in syl20bnr/spacemacs Nov 18, 2015

Closed

Customize spacemacs for terminal usage. #3780

@PythonNut Here's an article that lists the patches that exist for adding 24 bit color support to emacs 24.3 and 24.4. There's also a more recent patch for emacs 24.5 here.

@bricewge bricewge referenced this issue in Malabarba/beacon Dec 5, 2015

Closed

emacs --daemon don't start anymore #39

chumakd commented Feb 9, 2016

as a workaround for iTerm2 with solarized palette and tmux with 256 colors I use this trick in my .bashrc, which makes emacs think it's running on a 16 color terminal and use correct solarized colors:

alias emacs='TERM=screen-16color emacs -nw'

For what it is worth, I am using GNU emacs 25.1.1 and I am affected by this issue in iTerm2 on OS X 10.12. I have scanned through this thread, but I cannot see what is the recommended fix. The https://github.com/sellout/emacs-color-theme-solarized theme does not have this issue, but it has other ones that I am hoping to avoid by using this one.

Should I open a new issue about this? Or is there is a fix? Many thanks indeed and my regards from Ireland.

Looking for the fix as well...

krksgbr commented Apr 16, 2017

here's how i went around the problem.
code supporting 24bit colors is already in emacs' development version: e463e57
on osx this can easily be installed via the emacs-plus brew formula, using the --HEAD option.

this version of emacs requires a custom terminfo description xterm-24bit, which needs to be compiled manually:

1 . create a terminfo entry source file: touch terminfo-24bit.src.
2. add the following code to the file:

xterm-24bits|xterm with 24-bit direct color mode,
        use=xterm-256color,
        Tc,
        setb24=\E[48;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%dm,
        setf24=\E[38;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%dm,
  1. compile the terminfo source: tic -x -o ~/.terminfo terminfo-24bit.src

this will also work for tmux, provided that true color is also setup tmux side.
source: http://lists.gnu.org/archive/html/emacs-devel/2017-02/msg00635.html
more on how to setup tmux true color here.

TERM=xterm-24bits emacs -nw and the theme works flawlessly. 👌

this version of emacs requires a custom terminfo description xterm-24bit, which needs to be compiled manually

@krksgbr can you please elaborate how to compile manually?

krksgbr commented Apr 21, 2017

@srustamo I've edited my comment to make the steps more clear.

@krksgbr

Let me know if I understand correctly:

  1. Need to use emacs-plus (nothing else needs to be config'ed on emacs side)
  2. Need to compile terminfo with tic -x -o ~/.terminfo terminfo-24bit.src

tic man says "The results are normally placed in the system terminfo directory /usr/share/terminfo."

Is this correct?

krksgbr commented Apr 21, 2017

@srustamo
yeah that's correct. the only thing is that contrary to what the tic manual says, it will always output the results to ~/.terminfo even when run as root, so I just added that to the command to make it explicit.

s-kostyaev commented Jul 6, 2017

I use this workaround for emacs & emacsclient:

(defun my-solarized-dark-workaround (frame)
  "Fix solarized-dark theme for terminal FRAME."
  (with-selected-frame frame
    (if (and (featurep 'color-theme)
             (not window-system))
        (set-face-background 'default "none" frame))))

;; first created emacsclient frame not fixed so use focus-in-hook
(add-hook 'after-make-frame-functions #'my-solarized-dark-workaround)

(defun my-solarized-dark-on-focus ()
  "Fix solarized-dark theme for terminal on focus."
  (my-solarized-dark-workaround (selected-frame)))

(add-hook 'focus-in-hook #'my-solarized-dark-on-focus)

I also add

(seq-doseq (frame (frame-list)) (my-solarized-dark-workaround frame))

to my-set-themes.

srustamo commented Jul 8, 2017

my-set-themes it's function for after-init-hook and some other hooks. For example it executes after update and reload updated packages.

chuan-su commented Oct 2, 2017

really looking forward to have this fixed. +1

This is still broken. :/

mikefaille commented Jan 22, 2018

@bhamiltoncx The commit from @beauby should fix it.

@mikefaille : Do you mean PR #283 ? It looks like that just adds a configuration option to bypass the color setting.

If users change that setting, I assume the colors will be correct for Terminal, but incorrect for the Emacs GUI, right?

­> If users change that setting, I assume the colors will be correct for Terminal, but incorrect for the Emacs GUI, right?
@bhamiltoncx For current et futur users, it shouldn't change anything if solarized-termcolors isn't set. For others, this hack should be consider not as a solution by itself but like a helper to enable terminal detection like end "user" want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment