Skip to content

Commit

Permalink
Add Session.SplitPane
Browse files Browse the repository at this point in the history
  • Loading branch information
marwan-at-work committed Aug 28, 2020
1 parent bd994a3 commit 57bed70
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ import (
type Session interface {
SendText(s string) error
Activate(selectTab, orderWindowFront bool) error
SplitPane(opts SplitPaneOptions) (Session, error)
}

// SplitPaneOptions for customizing the new pane session.
// More options can be added here as needed
type SplitPaneOptions struct {
Vertical bool
}

type session struct {
Expand Down Expand Up @@ -57,3 +64,29 @@ func (s *session) Activate(selectTab, orderWindowFront bool) error {
}
return nil
}

func (s *session) SplitPane(opts SplitPaneOptions) (Session, error) {
direction := api.SplitPaneRequest_HORIZONTAL.Enum()
if opts.Vertical {
direction = api.SplitPaneRequest_VERTICAL.Enum()
}
resp, err := s.c.Call(&api.ClientOriginatedMessage{
Submessage: &api.ClientOriginatedMessage_SplitPaneRequest{
SplitPaneRequest: &api.SplitPaneRequest{
Session: &s.id,
SplitDirection: direction,
},
},
})
if err != nil {
return nil, fmt.Errorf("error splitting pane: %w", err)
}
spResp := resp.GetSplitPaneResponse()
if len(spResp.GetSessionId()) < 1 {
return nil, fmt.Errorf("expected at least one new session in split pane")
}
return &session{
c: s.c,
id: spResp.GetSessionId()[0],
}, nil
}

0 comments on commit 57bed70

Please sign in to comment.