diff --git a/bubbletea/tea_other.go b/bubbletea/tea_other.go index e5f796d..12788b3 100644 --- a/bubbletea/tea_other.go +++ b/bubbletea/tea_other.go @@ -5,20 +5,27 @@ 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() + environ := s.Environ() + if !ok { + return []tea.ProgramOption{ + tea.WithInput(s), + tea.WithOutput(s), + tea.WithEnvironment(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)) -} diff --git a/bubbletea/tea_unix.go b/bubbletea/tea_unix.go index fc168cd..9d429d3 100644 --- a/bubbletea/tea_unix.go +++ b/bubbletea/tea_unix.go @@ -10,17 +10,32 @@ import ( func makeOpts(s ssh.Session) []tea.ProgramOption { pty, _, ok := s.Pty() - if !ok || s.EmulatedPty() { + environ := s.Environ() + if !ok { return []tea.ProgramOption{ tea.WithInput(s), tea.WithOutput(s), - tea.WithEnvironment(append(s.Environ(), "CLICOLOR_FORCE=1")), + tea.WithEnvironment(environ), + } + } + + if pty.Term != "" { + environ = append(environ, "TERM="+pty.Term) + } + + // XXX: This is a hack to make the output colorized in PTY sessions. + environ = append(environ, "CLICOLOR_FORCE=1") + if s.EmulatedPty() { + return []tea.ProgramOption{ + tea.WithInput(s), + tea.WithOutput(s), + tea.WithEnvironment(environ), } } return []tea.ProgramOption{ tea.WithInput(pty.Slave), tea.WithOutput(pty.Slave), - tea.WithEnvironment(s.Environ()), + tea.WithEnvironment(environ), } }