Skip to content

Commit

Permalink
fix color level error on Terminus
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Apr 6, 2021
1 parent aaee2b3 commit 402971f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions detect_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ func detectColorLevelFromEnv(termVal string) (terminfo.ColorLevel, error) {
return terminfo.ColorLevelBasic, nil
case termProg == "Apple_Terminal":
return terminfo.ColorLevelHundreds, nil
case termProg == "Terminus":
if termVal == "screen" { // on TERM=screen: not support true-color
return terminfo.ColorLevelHundreds, nil
}
return terminfo.ColorLevelMillions, nil
case termProg == "iTerm.app":
if termVal == "screen" { // on TERM=screen: not support true-color
return terminfo.ColorLevelHundreds, nil
Expand Down
28 changes: 28 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ ZSH_TMUX_TERM=screen-256color
func TestIsDetectColorLevel_unix(t *testing.T) {
is := assert.New(t)

// TERM_PROGRAM=Terminus
mockOsEnvByText(`
TERMINUS_PLUGINS=
TERM=xterm-256color
TERM_PROGRAM=Terminus
ZSH_TMUX_TERM=screen-256color
`, func() {
is.Equal(LevelRgb, DetectColorLevel())
is.True(IsSupportRGBColor())
is.True(IsSupport16Color())
is.True(IsSupportColor())
})

// -------- tests on macOS ---------

// TERM_PROGRAM=Apple_Terminal
Expand Down Expand Up @@ -148,6 +161,21 @@ ZSH_TMUX_TERM=screen
is.True(IsSupportColor())
})

// TERM_PROGRAM=Terminus use screen
mockOsEnvByText(`
TERM=screen
TERMCAP=SC|screen|VT 100/ANSI X3.64 virtual terminal:\
TERMINUS_PLUGINS=
TERM_PROGRAM=Terminus
ZSH_TMUX_TERM=screen
`, func() {
is.Equal(Level256, DetectColorLevel())
is.False(IsSupportTrueColor())
is.True(IsSupport256Color())
is.True(IsSupport16Color())
is.True(IsSupportColor())
})

// TERMINAL_EMULATOR=JetBrains-JediTerm use screen
mockOsEnvByText(`
TERM=screen
Expand Down

0 comments on commit 402971f

Please sign in to comment.