lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Truecolors not working inside tmux

Open karamanliev opened this issue 1 year ago • 7 comments
trafficstars

Describe the bug This is driving me nuts, I can't really find someone else mention this problem. Inside tmux lazygit colors are looking like this:

image

What is interesting is that if I enter neovim (in tmux as well) and launch lazygit from its terminal colors are fine:

image

It works OK if i set screen-256color in tmux, but then I can't have italics and underlines in SSH. I am using kitty terminal, but tested with wezterm and alacritty and the result is the same. Also when diffing outside lazygit with delta colors are fine. Here are relevant configs:

tmux:

set -g default-terminal "tmux-256color"
set -as terminal-features ",${TERM}:RGB"
set -as terminal-overrides ',*:Smulx=\E[4::%p1%dm'
set -as terminal-overrides ',*:Setulc=\E[58::2::%p1%{65536}%/%d::%p1%{256}%/%{255}%&%d::%p1%{255}%&%d%;m'

delta:

[core]
editor = nvim
pager = delta --features=interactive

[interactive]
  diffFilter = delta

[delta]
  navigate = true
  line-numbers = true
  true-color = always
  syntax-theme = tokyonight_night
  minus-style = "syntax #3b263a"
  minus-emph-style = "syntax #5e355c"
  zero-style = "syntax auto"
  plus-style = "syntax #263949"
  plus-emph-style = "syntax #394b70"
  line-numbers-minus-style = "#f7768e auto"
  line-numbers-zero-style = "#565f89 auto"
  line-numbers-left-style = "#565f89 auto"
  line-numbers-plus-style = "#41a6b5 auto"
  hunk-header-decoration-style = "blue box"

[delta "interactive"]
  side-by-side = true

lazygit:

git:
  paging:
    colorArg: always
    pager: delta --dark --paging=never

To Reproduce Steps to reproduce the behavior:

  1. Start tmux session
  2. Launch lazygit
  3. Truecolors are not working

Expected behavior Colors should be fine inside tmux

Screenshots Truecolors are working fine inside my terminal: image

Version info: commit=v0.42.0, build date=2024-05-19T10:54:29Z, build source=binaryRelease, version=0.42.0, os=linux, arch=amd64, git version=2.45.2

karamanliev avatar Jun 16 '24 00:06 karamanliev

I'm having the same problem, as mentioned in #3362

Susensio avatar Jun 17 '24 09:06 Susensio

Just for the record I have COLORTERM=truecolor setup inside tmux.

karamanliev avatar Jun 17 '24 11:06 karamanliev

I think I have the exact same problem...

A weird-ish yellow background for both additions and deletions when inside Tmux > lazygit. The regular git-delta diff colors work when lazygit runs outside of Tmux. Or when just using git diff (using delta) inside of Tmux.

Somehow that 3rd layer (Tmux > lazygit > delta) messes up the background colors from my theme.

jessevdp avatar Jun 26 '24 13:06 jessevdp

I don't know why I didn't think of this until now, but the solution I've found is to alias lazygit to use screen-256color env in my .zshrc / .bashrc:

alias lazygit='env TERM=screen-256color lazygit'
alias lg='lazygit'

karamanliev avatar Jul 03 '24 11:07 karamanliev

Thanks for the workaround 😁

I guess that also sheds some more light on the underlying issue.

Inside of Tmux $TERM is usually set to tmux-256color.

Delta works fine when run standalone inside of Tmux. At least when also setting a :Tc "terminal override in Tmux like so:

set-option -ga terminal-overrides ",*-256color:Tc"

What could be going on inside of lazygit here that messes with this?

jessevdp avatar Jul 03 '24 11:07 jessevdp

I don't know why I didn't think of this until now, but the solution I've found is to alias lazygit to use screen-256color env in my .zshrc / .bashrc:

alias lazygit='env TERM=screen-256color lazygit'
alias lg='lazygit'

I don't know if lazygit uses italics but screen-256color does not support italics

Susensio avatar Jul 16 '24 07:07 Susensio

It seems this was introduced by https://github.com/jesseduffield/lazygit/commit/ad0394aebebddc5fc17043bbeb72894b8d670abb because of https://github.com/gdamore/tcell/commit/216e30afd7d0329c44490546d6ef7e628ac8f74c removing tmux-256color terminfo.

sg1fan avatar Sep 29 '24 09:09 sg1fan

Following, as I'm running into exact same issue. Colors output correctly outside of TMUX, Truecolor working flawlessly for everything else except lazygit with delta for pager. Delta on it's own in TMUX outputs as anticipated. TERM = xterm-kitty in my instance.

chris4prez avatar Dec 19 '24 02:12 chris4prez

Can you test this again with current master? I don't understand the problem well enough to tell for sure, but I have the suspicion that it might be fixed by #4166 which was merged today.

stefanhaller avatar Jan 12 '25 12:01 stefanhaller

I built from last commit and can confirm that it is working now, thank you @stefanhaller!

karamanliev avatar Jan 12 '25 14:01 karamanliev

Maybe it's different problem but using alacritty lazygit works fine except I run it on a tmux session:

2025/02/09 15:40:57 An error occurred! Please create an issue at: https://github.com/jesseduffield/lazygit/issues

*exec.Error exec: "infocmp": executable file not found in $PATH
github.com/jesseduffield/lazygit/pkg/app/app.go:55 (0x558e74a75bbd)
github.com/jesseduffield/lazygit/pkg/app/entry_point.go:167 (0x558e74a77cdc)
github.com/jesseduffield/lazygit/main.go:23 (0x558e74a78e78)
internal/runtime/atomic/types.go:194 (0x558e742a4b1d)
runtime/asm_amd64.s:1700 (0x558e742e3bc1)

(infocmp comes from ncurses packages which I prefer to avoid install if not needed)

Running '$ TERM=alacritty lazygit' works fine.

donob4n avatar Feb 09 '25 14:02 donob4n

Maybe it's different problem but using alacritty lazygit works fine except I run it on a tmux session:

2025/02/09 15:40:57 An error occurred! Please create an issue at: https://github.com/jesseduffield/lazygit/issues

*exec.Error exec: "infocmp": executable file not found in $PATH
github.com/jesseduffield/lazygit/pkg/app/app.go:55 (0x558e74a75bbd)
github.com/jesseduffield/lazygit/pkg/app/entry_point.go:167 (0x558e74a77cdc)
github.com/jesseduffield/lazygit/main.go:23 (0x558e74a78e78)
internal/runtime/atomic/types.go:194 (0x558e742a4b1d)
runtime/asm_amd64.s:1700 (0x558e742e3bc1)

(infocmp comes from ncurses packages which I prefer to avoid install if not needed)

Running '$ TERM=alacritty lazygit' works fine.

Are you seeing TERM within tmux?

set -g default-terminal "${TERM}"

Otherwise it’ll use the tmux default which does not play nicely with proper colours.

Note that you might need to completely restart the tmux server to see TERM changes propagate properly.

nianiam avatar Feb 09 '25 15:02 nianiam

I have this:

COLORTERM=truecolor
TERM=tmux-256color
TERM_PROGRAM=tmux
TERM_PROGRAM_VERSION=3.5a

I thought about just change it but don't sure if it's the ideal solution.

donob4n avatar Feb 09 '25 19:02 donob4n

have anyone tested with tmux-direct ?

For me in,

TERM_PROGRAM_VERSION=3.5a
COLORTERM=truecolor
TERM_PROGRAM=tmux
TERM=tmux-direct

the colors are like this.

Image

But if run it with env term=screen-256color lazygit (or tmux-256color or tmux) the colors are normal.

Image

arpangreat avatar Sep 03 '25 07:09 arpangreat