1package terminalcap
2
3import (
4 "testing"
5
6 "github.com/stretchr/testify/require"
7)
8
9func TestDetectTrueColorPreservesKittyEnvironment(t *testing.T) {
10 require.True(t, DetectTrueColor("xterm-kitty", "", []string{"KITTY_WINDOW_ID=1"}))
11}
12
13func TestDetect(t *testing.T) {
14 tests := []struct {
15 name string
16 env []string
17 wantMode ColorMode
18 wantSource Source
19 wantApp Application
20 wantGraphics bool
21 }{
22 {name: "declared truecolor", env: []string{"TERM=xterm-256color", "COLORTERM=truecolor"}, wantMode: TrueColor, wantSource: SourceDeclared},
23 {name: "declared 24bit", env: []string{"TERM=xterm-256color", "COLORTERM=24bit"}, wantMode: TrueColor, wantSource: SourceDeclared},
24 {name: "direct terminfo entry", env: []string{"TERM=foot-direct"}, wantMode: TrueColor, wantSource: SourceDeclared},
25 {name: "kitty signals infer truecolor", env: []string{"TERM=xterm-kitty", "KITTY_WINDOW_ID=1"}, wantMode: TrueColor, wantSource: SourceHeuristic, wantApp: ApplicationKitty},
26 {name: "kitty environment with declared truecolor remains color-only", env: []string{"TERM=xterm-kitty", "COLORTERM=truecolor", "KITTY_WINDOW_ID=1"}, wantMode: TrueColor, wantSource: SourceDeclared, wantApp: ApplicationKitty},
27 {name: "256 color terminal remains a constrained attachment", env: []string{"TERM=xterm-256color"}, wantMode: Indexed256, wantSource: SourceDeclared},
28 {name: "unknown terminal is conservatively indexed", env: []string{"TERM=unknown"}, wantMode: Indexed256, wantSource: SourceUnknown},
29 {name: "kitty environment behind a multiplexer is not graphics evidence", env: []string{"TERM=tmux-256color", "KITTY_WINDOW_ID=1"}, wantMode: Indexed256, wantSource: SourceDeclared, wantApp: ApplicationKitty},
30 }
31
32 for _, tt := range tests {
33 t.Run(tt.name, func(t *testing.T) {
34 got := Detect(tt.env)
35 require.Equal(t, tt.wantMode, got.ColorMode)
36 require.Equal(t, tt.wantSource, got.ColorSource)
37 require.Equal(t, tt.wantApp, got.Application)
38 require.Equal(t, tt.wantGraphics, got.SupportsKittyGraphics())
39 })
40 }
41}