Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Incorrect Colours in Terminal #18

Closed
zmanji opened this issue Apr 14, 2012 · 125 comments
Closed

Incorrect Colours in Terminal #18

zmanji opened this issue Apr 14, 2012 · 125 comments

Comments

@zmanji
Copy link

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.

@bbatsov
Copy link
Owner

bbatsov commented Apr 17, 2012

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

@zmanji
Copy link
Author

zmanji commented Apr 17, 2012

$ echo $TERM xterm-256color

@bbatsov
Copy link
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.

@thomasf
Copy link
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.

@thomasf
Copy link
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

@bbatsov
Copy link
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.

@thomasf
Copy link
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.

@thomasf
Copy link
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
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
@thomasf thomasf mentioned this issue Nov 27, 2012
@thomasf
Copy link
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

        ...

@chalmagean
Copy link

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

@localredhead
Copy link

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

@kzahel
Copy link

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

@thomasf
Copy link
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)

@localredhead
Copy link

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
Copy link
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.

@andyleejordan
Copy link
Contributor

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

@ronert
Copy link

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
Copy link

roryk commented Aug 22, 2013

+1 for this.

@Nekroze
Copy link

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
Copy link

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.

@andyleejordan
Copy link
Contributor

(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
Copy link
Owner

bbatsov commented Sep 1, 2013

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

@andyleejordan
Copy link
Contributor

@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
Copy link

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.

@thomasf
Copy link
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
Copy link

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!

@antoinelyset
Copy link

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

@srustamo
Copy link

srustamo commented Sep 4, 2018

@NightMachinary How did you install the terminfo here?

@NightMachinery
Copy link

NightMachinery commented Sep 4, 2018 via email

@YujiShen
Copy link

YujiShen commented Oct 4, 2018

@srustamo I encounter the same problem and I found a solution.

For all folks have error when set TERM variable on Mac, use system tic instead of tic you installed (maybe from conda or whatever), for example:

/usr/bin/tic  -x -o ~/.terminfo  terminfo-24bit.src

I have a question and answer on Emacs StackExchange about this: Set 24-bit colors terminal (Truecolor) for Solarized theme on Mac.

@srustamo
Copy link

srustamo commented Oct 8, 2018

@YujiShen brilliant!

@thomasf thomasf mentioned this issue Nov 14, 2018
@martinweiss
Copy link

I am using terminal Emacs 25.1.1 on a Raspberry Pi Zero W running Raspbian Stretch. When I set the theme so solarized-dark, I get a blue screen.

I have tried what @krksgbr suggested, and I have also tried to run Emacs using
$TERM=xterm-256color emacs

However, that gives me the same result. Any ideas?

@srustamo
Copy link

srustamo commented Nov 14, 2018 via email

@martinweiss
Copy link

Thanks for your reply. However, all colour schemes look wrong as far as I can see, so I'm not really sure what to do.

Do one of the other solarized packages work?

@srustamo
Copy link

srustamo commented Nov 14, 2018 via email

@martinweiss
Copy link

Hmm. But does that mean it's not possible to get correct colors without 24-bit Emacs and terminal?

@NightMachinery
Copy link

NightMachinery commented Nov 15, 2018 via email

@martinweiss
Copy link

The screenshot in the first post is for Emacs running on macOS. I wasn't sure if it would be the same in Raspbian (sorry for asking I guess).

It seems like Zenburn works OK too, so I'll use that on the machines that don't have GUI Emacs.

@luluman
Copy link

luluman commented Jan 4, 2019

I have tried emacs-color-theme-solarized, and it works fine in terminal. But I prefer solarized-emacs better because solarized-emacs is more active and have fine tuning for other modes. But the time comes to 2019, and I hope this issue can be fixed. I work on the terminal and need this feature very much. Thanks.

@kilowu
Copy link

kilowu commented Jan 4, 2019

There is an on-going pull request #283 addressing this issue. The fix is using the same approach as emacs-color-theme-solarized does. It requires you pre-set a terminal with the solarized 16-color palette which is already builtin included in gnome-terminal and iterm2.

@luluman
Copy link

luluman commented Jan 4, 2019

Ok, I will try. Thanks, @kilowu.

isker added a commit to isker/.emacs.d that referenced this issue Jun 16, 2019
The former is newer and has much better mode-specific support, but lacks a bunch
of workarounds for running in the terminal, which I need.  However instructions
at bbatsov/solarized-emacs#18 (comment)
saved me both on macos and centos.

For posterity:

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

 # Use colon separators.
xterm-24bit|xterm with 24-bit direct color mode,
   use=xterm-256color,
   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,
 # Use semicolon separators.
xterm-24bits|xterm with 24-bit direct color mode,
   use=xterm-256color,
   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,

3. compile the terminfo source: tic -x -o ~/.terminfo terminfo-24bit.src
@jimmysjolund
Copy link

jimmysjolund commented Aug 30, 2019

I got this problem in my urxvt terminal. I "solved" it by running tmux and changing:

(s-base03 "#002b36")

to #1c1c1c in the solarized.el.

I suppose at least for my terminal I should use the Xterm hex values:
SOLARIZED HEX 16/8 TERMCOL XTERM/HEX LAB RGB HSB


base03 #002b36 8/4 brblack 234 #1c1c1c 15 -12 -12 0 43 54 193 100 21

@thomasf thomasf added this to the version FUTURE milestone Nov 20, 2019
@RafalLukawiecki
Copy link

RafalLukawiecki commented Feb 7, 2020

The workaround mentioned above by @NightMachinary of creating a terminfo xterm-24bit works nicely in Emacs 26.3 with and without tmux. Thank you! However, I now have a new problem: anything that uses the "less" pager, like git, man etc, now complains with "WARNING: terminal is not fully functional".

I am using iTerm 3.3.8 on macOS 10.14.6 and zsh. Many thanks for any pointers, anyone.

UPDATE: I found the solution. The issue was caused by the less pager, which expects the old-style termcap database to exist, rather than uses the newer terminfo (see lines 1111 onwards in screen.c of less sources). You need to set TERMCAP to point to the file (or directory/database) that has the source for xterm-24bit. In other words, as per comment above place this into a file like ~/termcap/terminfo-24bit.src:

# Use colon separators.
xterm-24bit|xterm with 24-bit direct color mode,
   use=xterm-256color,
   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,
# Use semicolon separators.
xterm-24bits|xterm with 24-bit direct color mode,
   use=xterm-256color,
   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,

then add something like export TERMCAP=~/.termcap/terminfo-24bit.src into one of your rc files. You still need to compile the above using tic -x -o ~/.terminfo ~/.termcap/terminfo-24bit.src as per previous comments. In the end, you have 24 bit colour in terminal, emacs, tmux, and less, and all are happy now—but only on macOS.

Things do not work well when ssh into a remote session on FreeBSD, which uses termcap over terminfo. I have worked around that issue, too, but then tmux is unhappy, as it looks for the string "256" in the name of the termcap to use colour. That fails. You can launch it with option "-2" to force color, but the color is a little wrong...

All in all, I am coming to realise that defining the new xterm-24bit is the wrong way round, as there are too many dependencies on the good-old xterm-256color in the wild. Perhaps the solarized theme should be updated rather than requiring the terminal to be changed to deal with all of these 24bit terminal issues. Hoping for an update @bbatsov...many thanks for your hard work.

@RafalLukawiecki
Copy link

For what it is worth, there is a further workaround for those who use this theme on FreeBSD in a remote shell session. It involves recompiling ncurses with --disable-termcap and then recompiling emacs to make use of that—see this StackExchange post. It works, but it is all much too much of a workaround—it would be better to have the theme fixed.

@andyleejordan
Copy link
Contributor

andyleejordan commented Dec 24, 2020

This is bizzare. So I’m using Emacs on an Ubuntu 20.04 instance over SSH with the Blink iPad app...and surprisingly I’ve gotten this to work. I followed the instructions in the latest Emacs FAQ (after building Emacs from the 27.1 source branch) Colors on a TTY, which several comments above mention and reproduce in its various versions.

But I had to change the \: (backslash colons) in the xterm-emacs entry to just ; (semicolons) to make things work (I also joined the lines to get rid of the backslash-newline but I don’t think that’s it). That’s it, that’s the only change. With the documented entry, tic compiles fine but then Emacs has no colors. Replace the custom entry with semicolons instead and Emacs suddenly works with full 24 bit color support (and the Solarized background is correct). The only reference to this difference in syntax I’ve found is here: https://invisible-island.net/ncurses/ncurses.faq.html

The original commit emacs-mirror/emacs@e463e57 to the FAQ referenced this “use colons” and “use semicolons” entries like in the above comments, but then it was removed without documented reason in emacs-mirror/emacs@7f6153d. I only a little bit about termcap/terminfo; can anyone here shed light on why I needed to use semicolons instead of backslash-colons, and does it hint at something deeper?

For reference, I did this:

$ cat terminfo-custom.src 
# See Emacs FAQ "Colors on a TTY" but sub ; for ;
xterm-emacs|xterm with 24-bit direct color mode for Emacs,
  use=xterm-256color,
  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,
$ tic -x -o ~/.terminfo terminfo-custom.src
$ TERM=xterm-emacs emacs

@done-with-fish
Copy link

This is still an issue for me (arch linux with st+solarized patch). Has anyone managed to cobble together a solution?

@analyticd
Copy link

On macOS with alacritty terminal and emacs -nw you can get true color both within tmux and without tmux. Never did get 24bit in iTerm2 though with emacs.

@thomasf
Copy link
Collaborator

thomasf commented Jul 24, 2021

Yeah I have got it working in 24bit mode in Alacritty under Linux, MacOS and IIIRC Windows as well and with some other terminals. You might have to fiddle around with termcap files though.

@thomasf
Copy link
Collaborator

thomasf commented Jul 24, 2021

This is likely never going to be "fixed" for anything below true color. We use too many non standard solarized colors so we can't fit it all into 16 colors even if we tried and it's a huge job mapping and maintaining all those colors into something that actually displays properly on low color displays. It's probably just not worth it.

At this point more and more terminals are getting 24bit color support and I think only focusing on that and non GUI toolkit environments is the right choice for this theme.

@thomasf thomasf closed this as completed Jul 24, 2021
@done-with-fish
Copy link

This issue has plagued me forever. I used to get around it by changing base03 to #7f7f7f and base02 to #000000.

However, to my pleasant surprise, the colors started to work after upgrading to emacs 29.1! Thought I'd post here in case anyone else has had this issue as long as I have!

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

No branches or pull requests