Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: several example improvements #47

Merged
merged 3 commits into from May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -27,6 +27,13 @@ and should be easy to integrate into any existing projects.

## Middleware

Wish middlewares are analogous to those in several HTTP frameworks.
They are essentially SSH handlers that you can use to do specific tasks,
and then call the next middleware.

Notice that middlewares are composed from first to last,
which means the last one is executed first.

### Bubble Tea

The [`bubbletea`](bubbletea) middleware makes it easy to serve any
Expand Down
8 changes: 5 additions & 3 deletions examples/bubbletea/main.go
Expand Up @@ -19,8 +19,10 @@ import (
"github.com/gliderlabs/ssh"
)

const host = "localhost"
const port = 23234
const (
host = "localhost"
port = 23234
)

func main() {
s, err := wish.NewServer(
Expand Down Expand Up @@ -56,7 +58,7 @@ func main() {
// You can wire any Bubble Tea model up to the middleware with a function that
// handles the incoming ssh.Session. Here we just grab the terminal info and
// pass it to the new model. You can also return tea.ProgramOptions (such as
// teaw.WithAltScreen) on a session by session basis
// tea.WithAltScreen) on a session by session basis.
func teaHandler(s ssh.Session) (tea.Model, []tea.ProgramOption) {
pty, _, active := s.Pty()
if !active {
Expand Down
14 changes: 7 additions & 7 deletions examples/bubbleteaprogram/main.go
Expand Up @@ -20,8 +20,10 @@ import (
"github.com/muesli/termenv"
)

const host = "localhost"
const port = 23234
const (
host = "localhost"
port = 23234
)

func main() {
s, err := wish.NewServer(
Expand Down Expand Up @@ -61,10 +63,8 @@ func myCustomBubbleteaMiddleware() wish.Middleware {
p := tea.NewProgram(m, opts...)
go func() {
for {
select {
case <-time.After(1 * time.Second):
p.Send(timeMsg(time.Now()))
}
<-time.After(1 * time.Second)
p.Send(timeMsg(time.Now()))
}
}()
return p
Expand All @@ -73,7 +73,7 @@ func myCustomBubbleteaMiddleware() wish.Middleware {
pty, _, active := s.Pty()
if !active {
fmt.Println("no active terminal, skipping")
s.Exit(1)
_ = s.Exit(1)
return nil
}
m := model{
Expand Down
8 changes: 5 additions & 3 deletions examples/git/main.go
Expand Up @@ -19,9 +19,11 @@ import (
"github.com/gliderlabs/ssh"
)

const port = 23233
const host = "localhost"
const repoDir = ".repos"
const (
port = 23233
host = "localhost"
repoDir = ".repos"
)

type app struct {
access gm.AccessLevel
Expand Down
1 change: 1 addition & 0 deletions options.go
Expand Up @@ -35,6 +35,7 @@ func WithVersion(version string) ssh.Option {
// WithMiddleware composes the provided Middleware and return a ssh.Option.
// This useful if you manually create an ssh.Server and want to set the
// Server.Handler.
//
// Notice that middlewares are composed from first to last, which means the last one is executed first.
func WithMiddleware(mw ...Middleware) ssh.Option {
return func(s *ssh.Server) error {
Expand Down