4

I run a emacs daemon on boot as a OpenRC service without info about terminals. When I plug a different terminal on emacsclient so, I don't have env variables instead that was generated inside of emacs or defined on service config. Beyond that, I got different behaviors on face colors of my theme because on each terminal will have different color support. For instance, running emacsclient through the xfce4-terminal inside of a tmux session I got:

xfce4-terminal

Plugging the same tmux session on uxterm or running without X, I got instead:

xterm

(is the same emacsclient session, so is the same frame for both because tmux)

My wish is: modify the frame face colors only if I don't have a good color support on terminal, which happens on my case with xterm on running without X (console mode C-M-F{1,9}). I want do that because the face background colors for helm-selection and region is just black (I can't see they on xterm and this is pretty bad for usage).

For now I'm just change the face colors on frame creation for non-X sessions to red, like terminal sessions through this function: setup-terminal-session. But this change even the behavior inside of xfce4-terminal (which runs pretty fine because the good color support) and is unecessary.

Maybe I can fix the behavior of xterm forcing a type of color support on config through .Xdefaults or .Xresources file, but and the case of running emacs without X? I don't have full color support on that. So seems a kind of limitation here on a simple thing.

Anyway, my question is (again): there is a way to detect the color support of terminal inside of emacsclient without relying on ENV variables? I just don't understand how termcap and terminfo works reading the docs, would be nice a clarification on that. Thanks.

  • Is tmux a necessary part of this set-up? I don't use it myself or know much about it, but it does seem like an added layer of complication here. Emacs has some terminal-local capabilities, but that tends to be tied to frames, and here you are sharing a single frame amongst multiple terminals. Given that you're using emacsclient anyhow, you might find that not using tmux is better. – phils Oct 25 '17 at 6:31
  • I have the same problem using tmux or not. Using tmux on the example just happened because is pretty integrated on my personal setup. The problem remains not using tmux. I always used emacsclient without tmux and I had that problem before, now is not different. Tmux for me just keep things more easily, actually. Sorry if was confuse to you, but this is pretty unrelated to the problem :/ – Manoel Vilela Oct 25 '17 at 9:29
  • I know if I can fix the local frame variable will change the frame, so I'll change the behavior of the another tmux client which is attached to this same frame. But this not matter if at least I can detect the term color on frame creation (to decide or not change the theme) – Manoel Vilela Oct 25 '17 at 9:31
  • Maybe have a look at the tty-color.el commentary, and the various tty-* functions and variables. – phils Oct 25 '17 at 20:46
  • 1
    The problem was that tmux on my setup are forcing TERM to be xterm-256, so on inside of emacs (tty-display-colors-cells) seems that (again) that function rely on env variables, but at least I have that on terminal session. The mainly problem now is that even with TERM=xterm-256 I cannot see gray colors on xterm... I don't understand that. And don't setting for tmux that, neither xfce4-terminal works too. It's just a giant mess, hard to find someone to blame it. So the problem is on my setup and this question was answered. You should add (tty-display-color-cells) as answer. – Manoel Vilela Oct 26 '17 at 3:07
2

One option for customizing faces on a per-terminal-type basis is supported directly in the customize UI:

  • M-x customize-face RET face RET
  • Using the "State" button, select "For All Kinds of Displays"
  • INSert a new entry
  • Using the "Display" button, select "specific display"
  • Select "Type" and "TTY" and other criteria as appropriate...
  • e.g. "Class" (color, grayscale, or monochrome); and "Minimum number of colors"

To ask Emacs about terminal colour support from elisp, there are a variety of tty-* functions and variables, which you can inspect via:
M-x apropos RET ^tty RET

Of particular note:

  • The tty-display-color-cells function returns the number of colours available in a given terminal (defaulting to the terminal for the current frame).
  • The tty-color-alist function similarly returns data on the individual colours.

When tmux is being used, it sounds like Emacs will see the terminal type that tmux advertises; so establishing the terminal behind tmux may require other techniques.

Manoel Vilela recommends:

  • Verify that the TERM environment variable is set correctly.
  • Run tmux with tmux -2 to force 256 colour support, as described in the tmux manual.
  • Really complete answer. I'm modifying my setup to working tmux as well, but this helped a lot. – Manoel Vilela Oct 26 '17 at 4:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.