Skip to content

Commit

Permalink
feat: export MakeRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Jan 8, 2024
1 parent 6bdc541 commit bf2f028
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 31 deletions.
9 changes: 9 additions & 0 deletions bubbletea/tea_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ package bubbletea

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

// MakeRenderer returns a new lipgloss.Renderer for the given ssh.Session.
// It will use the pty if one is available, otherwise it will use the session
// writer.
func MakeRenderer(s ssh.Session) *lipgloss.Renderer {
return lipgloss.NewRenderer(s, termenv.WithUnsafe(), termenv.WithColorCache(true))
}

func makeIOOpts(s ssh.Session) []tea.ProgramOption {
return []tea.ProgramOption{
tea.WithInput(s),
Expand Down
16 changes: 16 additions & 0 deletions bubbletea/tea_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,26 @@
package bubbletea

import (
"io"

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

// MakeRenderer returns a new lipgloss.Renderer for the given ssh.Session.
// It will use the pty if one is available, otherwise it will use the session
// writer.
func MakeRenderer(s ssh.Session) *lipgloss.Renderer {
var f io.Writer = s
pty, _, ok := s.Pty()
if ok {
f = pty.Slave
}
return lipgloss.NewRenderer(f, termenv.WithColorCache(true))
}

func makeIOOpts(s ssh.Session) []tea.ProgramOption {
pty, _, ok := s.Pty()
if !ok || s.EmulatedPty() {
Expand Down
2 changes: 1 addition & 1 deletion examples/wish-exec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func main() {
}

func teaHandler(s ssh.Session) (tea.Model, []tea.ProgramOption) {
renderer := newRenderer(s)
renderer := bm.MakeRenderer(s)
m := model{
sess: s,
style: renderer.NewStyle().Foreground(lipgloss.Color("8")),
Expand Down
15 changes: 0 additions & 15 deletions examples/wish-exec/other.go

This file was deleted.

15 changes: 0 additions & 15 deletions examples/wish-exec/unix.go

This file was deleted.

0 comments on commit bf2f028

Please sign in to comment.