Skip to content

Commit

Permalink
fix: respect $TERM and force colors
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed May 24, 2024
1 parent 1a7ac6b commit 39391bc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
22 changes: 14 additions & 8 deletions bubbletea/tea_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@ package bubbletea

import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/ssh"
"github.com/muesli/termenv"
)

func makeOpts(s ssh.Session) []tea.ProgramOption {
pty, _, ok := s.Pty()
if !ok {
return []tea.ProgramOption{
tea.WithInput(s),
tea.WithOutput(s),
}
}

environ := s.Environ()
if pty.Term != "" {
environ = append(environ, "TERM="+pty.Term)
}

return []tea.ProgramOption{
tea.WithInput(s),
tea.WithOutput(s),
tea.WithEnvironment(append(environ, "CLICOLOR_FORCE=1")),
}
}

func newRenderer(s ssh.Session) *lipgloss.Renderer {
pty, _, _ := s.Pty()
env := sshEnviron(append(s.Environ(), "TERM="+pty.Term))
return lipgloss.NewRenderer(s, termenv.WithEnvironment(env), termenv.WithUnsafe(), termenv.WithColorCache(true))
}
24 changes: 17 additions & 7 deletions bubbletea/tea_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,27 @@ import (

func makeOpts(s ssh.Session) []tea.ProgramOption {
pty, _, ok := s.Pty()
if !ok || s.EmulatedPty() {
return []tea.ProgramOption{
tea.WithInput(s),
tea.WithOutput(s),
tea.WithEnvironment(append(s.Environ(), "CLICOLOR_FORCE=1")),
}
opts := []tea.ProgramOption{
tea.WithInput(s),
tea.WithOutput(s),
}

if !ok {
return opts
}

environ := s.Environ()
if pty.Term != "" {
environ = append(environ, "TERM="+pty.Term)
}

if s.EmulatedPty() {
return append(opts, tea.WithEnvironment(append(environ, "CLICOLOR_FORCE=1")))
}

return []tea.ProgramOption{
tea.WithInput(pty.Slave),
tea.WithOutput(pty.Slave),
tea.WithEnvironment(s.Environ()),
tea.WithEnvironment(environ),
}
}

0 comments on commit 39391bc

Please sign in to comment.