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

Force nvim to use 16 colors #11974

Closed
nylen opened this issue Mar 3, 2020 · 4 comments
Closed

Force nvim to use 16 colors #11974

nylen opened this issue Mar 3, 2020 · 4 comments
Labels
closed:question issues that are closed as usage questions documentation tui

Comments

@nylen
Copy link

nylen commented Mar 3, 2020

I'd like to force nvim to use only the basic 16 ANSI colors, regardless of what it detects in the TERM or COLORTERM environment variables or wherever else it is looking. The reason is that I plan to use the same config on multiple machines, including various combinations of tmux, SSH, etc, and I will configure the actual color values in my terminal emulator.

The following code is the only place t_colors is set that I can see, and I can't find a way to override it:

neovim/src/nvim/tui/tui.c

Lines 292 to 293 in 96059d7

// Set 't_Co' from the result of unibilium & fix_terminfo.
t_colors = unibi_get_num(data->ut, unibi_max_colors);

In vim you can do this using: set t_Co=16

But in nvim this seems to have no effect (or crashes, see below).

I've also tried TERM= COLORTERM= nvim which doesn't change anything, nvim is still using 256 colors.

I can actually get a segfault by playing with this also, here are the steps:

  1. Launch nvim
  2. Run :set t_Co=16
  3. Press Ctrl+Z to suspend
  4. Type fg to resume
  5. Observe Segmentation fault (without Step 2 this does not happen).
@nylen nylen added the enhancement feature request label Mar 3, 2020
@nylen
Copy link
Author

nylen commented Mar 3, 2020

Some missing info above, though I don't think it'll be super relevant here:

  • nvim --version: NVIM v0.4.3 - Build type: RelWithDebInfo
  • vim -u DEFAULTS (version: 7.x, 8.0) behaves differently? - yes, vim allows setting &t_Co at runtime
  • Operating system/version: Linux 5.3.0 x86_64 (Debian-based)
  • Terminal name/version: xfce4-terminal v0.8.3
  • $TERM: the default value on my system is xterm-256color but multiple values attempted, see first post

@justinmk
Copy link
Member

justinmk commented Mar 3, 2020

The reason is that I plan to use the same config on multiple machines, including various combinations of tmux, SSH, etc,

t_Co=16 isn't needed for that. You can force your N/Vim colorscheme to use ANSI color indexes:

:highlight Comment ctermfg=Red

Then changing ANSI "red" to some other color in your terminal, will color comments as such. Note that this requires :set notermguicolors.

The t_xx inner-platform is not supported. :help t_xx

5. Observe Segmentation fault (without Step 2 this does not happen).

Is set t_Co=16 required to repro that? If that happens with the development version please open a new report including a backtrace.

@justinmk justinmk closed this as completed Mar 3, 2020
@justinmk justinmk added duplicate tui and removed enhancement feature request labels Mar 3, 2020
@nylen
Copy link
Author

nylen commented Mar 4, 2020

Thanks for the info. You tagged this issue as a duplicate, but I wasn't able to find anything that is really the same ("force downscaling to 16 colors") on a quick search.

I do see #5538 and #11883 which also discuss t_Co but not quite in the same way.

I will test this further and report back, including setting a 16-color scheme such as https://github.com/noahfrederick/vim-noctu or https://github.com/jeffkreeftmeijer/vim-dim, and trying to reproduce the segfault in the latest development version.

@justinmk justinmk added closed:question issues that are closed as usage questions and removed usage labels Aug 30, 2020
lifepillar added a commit to lifepillar/vim-colortemplate that referenced this issue Jun 6, 2023
Set s:t_Co in a way that pleases more Neovim when Neovim support is
required.

Neovim has deprecated all `t_xx` options including `t_Co`, which is
currently read-only (but could potentially be removed). According to
Neovim's developers, if a user wants to force the use of 16 colors even
in terminal that supports more colors, it's the colorscheme that must do
so. See in particular this comment:

    neovim/neovim#11974 (comment)

So, this PR defines `s:t_Co` prioritizing the existence of a colorscheme
specific variable call `g:<prefix>_t_Co` or of a global `g:t_Co`
setting, falling back to checking whether `t_Co` exists otherwise.
@emivespa
Copy link

@nylen you can emulate t_Co with ffi: :lua f=require"ffi" f.cdef"int t_colors" f.C.t_colors=16, credit to @ seandewar from #neovim:matrix.org

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:question issues that are closed as usage questions documentation tui
Projects
None yet
Development

No branches or pull requests

3 participants