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

Consider Windows Terminal as non-dumb terminal #706

Merged
merged 2 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/tui/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ func getActionModal() *primitive.ActionModal {
SetTextColor(tcell.ColorDefault)
}

// IsDumbTerminal checks TERM environment variable and returns true if it is set to dumb.
// IsDumbTerminal checks TERM/WT_SESSION environment variable and returns true if they indicate a dumb terminal.
//
// Dumb terminal indicates terminal with limited capability. It may not provide support
// for special character sequences, e.g., no handling of ANSI escape sequences.
func IsDumbTerminal() bool {
term := strings.ToLower(os.Getenv("TERM"))
return term == "" || term == "dumb"
_, wtSession := os.LookupEnv("WT_SESSION")
return !wtSession && (term == "" || term == "dumb")
}

// IsNotTTY returns true if the stdout file descriptor is not a TTY.
Expand Down
34 changes: 34 additions & 0 deletions pkg/tui/helper_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tui

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -46,6 +47,39 @@ func TestColumnPadding(t *testing.T) {
}
}

func TestIsDumbTerminal(t *testing.T) {
// Store initial values & cleanup
t.Setenv("TERM", "")
t.Setenv("WT_SESSION", "")

empty := ""
foo := "foo"
setTermEnv(&empty, nil)
assert.True(t, IsDumbTerminal())

setTermEnv(nil, nil)
assert.True(t, IsDumbTerminal())

setTermEnv(&foo, nil)
assert.False(t, IsDumbTerminal())

setTermEnv(nil, &foo)
assert.False(t, IsDumbTerminal())
}

func setTermEnv(term *string, wtSession *string) {
if term != nil {
_ = os.Setenv("TERM", *term)
} else {
_ = os.Unsetenv("TERM")
}
if wtSession != nil {
_ = os.Setenv("WT_SESSION", *wtSession)
} else {
_ = os.Unsetenv("WT_SESSION")
}
}

func TestSplitText(t *testing.T) {
t.Parallel()

Expand Down