Skip to content

Commit bf2f028

Browse files
committed
feat: export MakeRenderer
1 parent 6bdc541 commit bf2f028

5 files changed

Lines changed: 26 additions & 31 deletions

File tree

‎bubbletea/tea_other.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ package bubbletea
55

66
import (
77
tea "github.com/charmbracelet/bubbletea"
8+
"github.com/charmbracelet/lipgloss"
89
"github.com/charmbracelet/ssh"
10+
"github.com/muesli/termenv"
911
)
1012

13+
// MakeRenderer returns a new lipgloss.Renderer for the given ssh.Session.
14+
// It will use the pty if one is available, otherwise it will use the session
15+
// writer.
16+
func MakeRenderer(s ssh.Session) *lipgloss.Renderer {
17+
return lipgloss.NewRenderer(s, termenv.WithUnsafe(), termenv.WithColorCache(true))
18+
}
19+
1120
func makeIOOpts(s ssh.Session) []tea.ProgramOption {
1221
return []tea.ProgramOption{
1322
tea.WithInput(s),

‎bubbletea/tea_unix.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,26 @@
44
package bubbletea
55

66
import (
7+
"io"
8+
79
tea "github.com/charmbracelet/bubbletea"
10+
"github.com/charmbracelet/lipgloss"
811
"github.com/charmbracelet/ssh"
12+
"github.com/muesli/termenv"
913
)
1014

15+
// MakeRenderer returns a new lipgloss.Renderer for the given ssh.Session.
16+
// It will use the pty if one is available, otherwise it will use the session
17+
// writer.
18+
func MakeRenderer(s ssh.Session) *lipgloss.Renderer {
19+
var f io.Writer = s
20+
pty, _, ok := s.Pty()
21+
if ok {
22+
f = pty.Slave
23+
}
24+
return lipgloss.NewRenderer(f, termenv.WithColorCache(true))
25+
}
26+
1127
func makeIOOpts(s ssh.Session) []tea.ProgramOption {
1228
pty, _, ok := s.Pty()
1329
if !ok || s.EmulatedPty() {

‎examples/wish-exec/main.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func main() {
6060
}
6161

6262
func teaHandler(s ssh.Session) (tea.Model, []tea.ProgramOption) {
63-
renderer := newRenderer(s)
63+
renderer := bm.MakeRenderer(s)
6464
m := model{
6565
sess: s,
6666
style: renderer.NewStyle().Foreground(lipgloss.Color("8")),

‎examples/wish-exec/other.go‎

Lines changed: 0 additions & 15 deletions
This file was deleted.

‎examples/wish-exec/unix.go‎

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)