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

24-bit true color support #9

Merged
merged 8 commits into from
Oct 8, 2017
Merged

24-bit true color support #9

merged 8 commits into from
Oct 8, 2017

Conversation

wookayin
Copy link
Owner

@wookayin wookayin commented Oct 6, 2017

References: https://gist.github.com/XVilka/8346728

iTerm2 >= 3.0
Tmux >= 2.1
Vim >= 7.4.1799 or neovim

Recent versions of tmux works well with ncurses (for 256 or richer
colors) with TERM="xterm-256color". We do not find any reason
to use 'screen-256color'; the new TERM configuration is required
to enable 24-bit true color feature.
This enables 24-bit true color support in true-color compatible
environments. Mainly, highlights will follow gui colors.
Popup menu was in a gray-ish color with GUI or 24-bit terminals,
which should be yellow-ish as in normal terminals (256 color).
Detects the current shell (running inside tmux, or not) is through
a mosh channel. This tool is necessary for auto-configuring
true color mode in several applications including vim.
Whenever possible, use termguicolors features to enable 24-bit
true color, even in the terminals like GUI.

There is a subtle challenge as some shell or terminal emulators
may not support 24-bit colors. We assume that modern terminal
emulators we would use will support it, or even fall-back to
256 colors nicely, but otherwise it may look broken as in mosh.

For mosh, to workaround this issue until mosh supports true color,
we detect whether the vim is running in a mosh environment.
This detection should be robust even when it is running under a
tmux session; to this end, the 'is_mosh' script is introduced.
Whenever the vim is initialized or asked to redraw the screen,
we detect mosh under which the feature shall be disabled.
In some nvim environments, &term is set to be 'nvim' instead of
the TERM value inherited from the shell.
When 24-bit colors are enabled (termguicolors), use a
slightly different appearance and color themes.
Use better color, respecting syntax highlight, when viewing diff
under GUI mode or true color.

Previously, foreground color for diff texts had to set black
in which syntax highlights are ignored, because 256-color doesn't
have dark green/red color of similar brightness to the background.
In 24-bit color mode, we adopt dark but chromatic colors for
diff background.
@wookayin
Copy link
Owner Author

wookayin commented Oct 8, 2017

Summary: Detects mosh using is_mosh and enable 24-bit color for vim unless it's under a mosh env (2669be4). Vim colors are also adjusted (77d7d0d, 1c7b48d).

@wookayin wookayin merged commit e44dcff into master Oct 8, 2017
@wookayin
Copy link
Owner Author

wookayin commented Oct 8, 2017

Screenshot:

Before

After (syntax highlights are preserved)

Note: If color looks awful in mosh: try refresh screen (,r).

wookayin added a commit that referenced this pull request Oct 8, 2017
wookayin added a commit that referenced this pull request Oct 10, 2017
@wookayin wookayin deleted the true-color branch October 11, 2017 04:47
@wookayin
Copy link
Owner Author

wookayin commented Dec 28, 2017

In the case where termguicolor (24-bit true color) is enabled but the terminal emulator doesn't support it and the color look weird, you can either use a terminal emulator that supports 24-bit color (e.g. iTerm2) or work around the issue by disabling the feature, e.g.:

# Add the following line to ~/.vimrc.local
set notermguicolor

@wookayin
Copy link
Owner Author

wookayin commented Jan 4, 2018

To test whether your terminal emulator supports 24-bit color (see also this):

printf "\x1b[38;2;255;100;0mTRUECOLOR: IT SHOULD READ RED\x1b[0m\n"

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

Successfully merging this pull request may close these issues.

1 participant