Skip to content

Commit

Permalink
fix: reset api
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Jan 8, 2024
1 parent b3f3747 commit 7ca8c0c
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 25 deletions.
25 changes: 3 additions & 22 deletions bubbletea/tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import (
"context"

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

// BubbleTeaHandler is the function Bubble Tea apps implement to hook into the
Expand All @@ -22,7 +20,7 @@ type BubbleTeaHandler = Handler // nolint: revive
// Handler is the function Bubble Tea apps implement to hook into the
// SSH Middleware. This will create a new tea.Program for every connection and
// start it with the tea.ProgramOptions returned.
type Handler func(ssh.Session, *lipgloss.Renderer) (tea.Model, []tea.ProgramOption)
type Handler func(ssh.Session) (tea.Model, []tea.ProgramOption)

// Middleware takes a Handler and hooks the input and output for the
// ssh.Session into the tea.Program.
Expand All @@ -32,15 +30,13 @@ type Handler func(ssh.Session, *lipgloss.Renderer) (tea.Model, []tea.ProgramOpti
func Middleware(bth Handler) wish.Middleware {
return func(sh ssh.Handler) ssh.Handler {
return func(s ssh.Session) {
tty, windowChanges, ok := s.Pty()
_, windowChanges, ok := s.Pty()
if !ok {
wish.Fatalln(s, "no active terminal, skipping")
return
}

renderer := lipgloss.NewRenderer(tty.Slave, termenv.WithColorCache(true))

m, hopts := bth(s, renderer)
m, hopts := bth(s)
if m == nil {
log.Error("no model returned by the handler")
return
Expand Down Expand Up @@ -78,18 +74,3 @@ func Middleware(bth Handler) wish.Middleware {
}
}
}

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

return []tea.ProgramOption{
tea.WithInput(pty.Slave),
tea.WithOutput(pty.Slave),
}
}
16 changes: 16 additions & 0 deletions bubbletea/tea_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build !linux && !darwin && !freebsd && !dragonfly && !netbsd && !openbsd && !solaris
// +build !linux,!darwin,!freebsd,!dragonfly,!netbsd,!openbsd,!solaris

package bubbletea

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

func makeIOOpts(s ssh.Session) []tea.ProgramOption {
return []tea.ProgramOption{
tea.WithInput(s),
tea.WithOutput(s),
}
}
24 changes: 24 additions & 0 deletions bubbletea/tea_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
// +build darwin dragonfly freebsd linux netbsd openbsd solaris

package bubbletea

import (
tea "github.com/charmbracelet/bubbletea"

Check failure on line 7 in bubbletea/tea_unix.go

View workflow job for this annotation

GitHub Actions / lint

import 'github.com/charmbracelet/bubbletea' is not allowed from list 'Main' (depguard)
"github.com/charmbracelet/ssh"

Check failure on line 8 in bubbletea/tea_unix.go

View workflow job for this annotation

GitHub Actions / lint

import 'github.com/charmbracelet/ssh' is not allowed from list 'Main' (depguard)
)

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

return []tea.ProgramOption{
tea.WithInput(pty.Slave),
tea.WithOutput(pty.Slave),
}
}
2 changes: 1 addition & 1 deletion examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/charmbracelet/bubbletea v0.25.0
github.com/charmbracelet/lipgloss v0.9.1
github.com/charmbracelet/log v0.3.1
github.com/charmbracelet/ssh v0.0.0-20240108173924-d928369dd254
github.com/charmbracelet/ssh v0.0.0-20240108193150-97a8c4d0f968
github.com/charmbracelet/wish v0.5.0
github.com/muesli/termenv v0.15.2
github.com/spf13/cobra v1.7.0
Expand Down
8 changes: 8 additions & 0 deletions examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ github.com/charmbracelet/log v0.3.1 h1:TjuY4OBNbxmHWSwO3tosgqs5I3biyY8sQPny/eCMT
github.com/charmbracelet/log v0.3.1/go.mod h1:OR4E1hutLsax3ZKpXbgUqPtTjQfrh1pG3zwHGWuuq8g=
github.com/charmbracelet/ssh v0.0.0-20240108173924-d928369dd254 h1:LQEx1n2MuC2Kzgetq8TW7v2JDXN/+o3BsqloJmKgoiY=
github.com/charmbracelet/ssh v0.0.0-20240108173924-d928369dd254/go.mod h1:H/cBXf4vsbGUlCLiR8cNGP7lpv8wuHbgD3GnWJ8quHA=
github.com/charmbracelet/ssh v0.0.0-20240108184918-e75da4447a78 h1:OPhgZLveCrbwJqVyPj0+bFMi7ncEdXtvhiq+m8y9kVs=
github.com/charmbracelet/ssh v0.0.0-20240108184918-e75da4447a78/go.mod h1:H/cBXf4vsbGUlCLiR8cNGP7lpv8wuHbgD3GnWJ8quHA=
github.com/charmbracelet/ssh v0.0.0-20240108190445-72503be29e9d h1:ykEOWspdc2kLCGF10gTJ015n5Q1VZZ5Q59oU+/RBm2s=
github.com/charmbracelet/ssh v0.0.0-20240108190445-72503be29e9d/go.mod h1:H/cBXf4vsbGUlCLiR8cNGP7lpv8wuHbgD3GnWJ8quHA=
github.com/charmbracelet/ssh v0.0.0-20240108191434-0c40f63bb0ce h1:JnzZdHKxn6p4m2o/VGV/GifrxHWmzN7pQwlPJEMDYAg=
github.com/charmbracelet/ssh v0.0.0-20240108191434-0c40f63bb0ce/go.mod h1:H/cBXf4vsbGUlCLiR8cNGP7lpv8wuHbgD3GnWJ8quHA=
github.com/charmbracelet/ssh v0.0.0-20240108193150-97a8c4d0f968 h1:J64ERdPQ3kaV2p8y+Lm28SGWOO6o5fEriUJQt3FLTY4=
github.com/charmbracelet/ssh v0.0.0-20240108193150-97a8c4d0f968/go.mod h1:H/cBXf4vsbGUlCLiR8cNGP7lpv8wuHbgD3GnWJ8quHA=
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY=
Expand Down
3 changes: 2 additions & 1 deletion examples/wish-exec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func main() {
}
}

func teaHandler(s ssh.Session, renderer *lipgloss.Renderer) (tea.Model, []tea.ProgramOption) {
func teaHandler(s ssh.Session) (tea.Model, []tea.ProgramOption) {
renderer := newRenderer(s)
m := model{
sess: s,
style: renderer.NewStyle().Foreground(lipgloss.Color("8")),
Expand Down
15 changes: 15 additions & 0 deletions examples/wish-exec/other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build !linux && !darwin && !freebsd && !dragonfly && !netbsd && !openbsd && !solaris
// +build !linux,!darwin,!freebsd,!dragonfly,!netbsd,!openbsd,!solaris

// TODO: support Windows
package main

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

func newRenderer(s ssh.Session) *lipgloss.Renderer {
return lipgloss.NewRenderer(s, termenv.WithColorCache(true))
}
15 changes: 15 additions & 0 deletions examples/wish-exec/unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
// +build darwin dragonfly freebsd linux netbsd openbsd solaris

package main

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

func newRenderer(s ssh.Session) *lipgloss.Renderer {
pty, _, _ := s.Pty()
return lipgloss.NewRenderer(pty.Slave, termenv.WithColorCache(true))
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/charmbracelet/keygen v0.5.0
github.com/charmbracelet/lipgloss v0.9.1
github.com/charmbracelet/log v0.3.1
github.com/charmbracelet/ssh v0.0.0-20240108173924-d928369dd254
github.com/charmbracelet/ssh v0.0.0-20240108193150-97a8c4d0f968
github.com/go-git/go-git/v5 v5.11.0
github.com/google/go-cmp v0.6.0
github.com/hashicorp/golang-lru/v2 v2.0.7
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ github.com/charmbracelet/log v0.3.1 h1:TjuY4OBNbxmHWSwO3tosgqs5I3biyY8sQPny/eCMT
github.com/charmbracelet/log v0.3.1/go.mod h1:OR4E1hutLsax3ZKpXbgUqPtTjQfrh1pG3zwHGWuuq8g=
github.com/charmbracelet/ssh v0.0.0-20240108173924-d928369dd254 h1:LQEx1n2MuC2Kzgetq8TW7v2JDXN/+o3BsqloJmKgoiY=
github.com/charmbracelet/ssh v0.0.0-20240108173924-d928369dd254/go.mod h1:H/cBXf4vsbGUlCLiR8cNGP7lpv8wuHbgD3GnWJ8quHA=
github.com/charmbracelet/ssh v0.0.0-20240108184918-e75da4447a78 h1:OPhgZLveCrbwJqVyPj0+bFMi7ncEdXtvhiq+m8y9kVs=
github.com/charmbracelet/ssh v0.0.0-20240108184918-e75da4447a78/go.mod h1:H/cBXf4vsbGUlCLiR8cNGP7lpv8wuHbgD3GnWJ8quHA=
github.com/charmbracelet/ssh v0.0.0-20240108190445-72503be29e9d h1:ykEOWspdc2kLCGF10gTJ015n5Q1VZZ5Q59oU+/RBm2s=
github.com/charmbracelet/ssh v0.0.0-20240108190445-72503be29e9d/go.mod h1:H/cBXf4vsbGUlCLiR8cNGP7lpv8wuHbgD3GnWJ8quHA=
github.com/charmbracelet/ssh v0.0.0-20240108191434-0c40f63bb0ce h1:JnzZdHKxn6p4m2o/VGV/GifrxHWmzN7pQwlPJEMDYAg=
github.com/charmbracelet/ssh v0.0.0-20240108191434-0c40f63bb0ce/go.mod h1:H/cBXf4vsbGUlCLiR8cNGP7lpv8wuHbgD3GnWJ8quHA=
github.com/charmbracelet/ssh v0.0.0-20240108193150-97a8c4d0f968 h1:J64ERdPQ3kaV2p8y+Lm28SGWOO6o5fEriUJQt3FLTY4=
github.com/charmbracelet/ssh v0.0.0-20240108193150-97a8c4d0f968/go.mod h1:H/cBXf4vsbGUlCLiR8cNGP7lpv8wuHbgD3GnWJ8quHA=
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY=
Expand Down

0 comments on commit 7ca8c0c

Please sign in to comment.