Skip to content

Commit

Permalink
Add Session.Activate & App.SetMenuItem
Browse files Browse the repository at this point in the history
  • Loading branch information
marwan-at-work committed Aug 28, 2020
1 parent 15418cb commit bd994a3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
19 changes: 18 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type App interface {

CreateWindow() (Window, error)
ListWindows() ([]Window, error)
SelectMenuItem(item string) error
}

// NewApp establishes a connection
Expand Down Expand Up @@ -61,7 +62,6 @@ func (a *app) ListWindows() ([]Window, error) {
if err != nil {
return nil, fmt.Errorf("could not list sessions: %w", err)
}
fmt.Println(resp.GetListSessionsResponse().GetBuriedSessions())
for _, w := range resp.GetListSessionsResponse().GetWindows() {
list = append(list, &window{
c: a.c,
Expand All @@ -78,3 +78,20 @@ func (a *app) Close() error {
func str(s string) *string {
return &s
}

func (a *app) SelectMenuItem(item string) error {
resp, err := a.c.Call(&api.ClientOriginatedMessage{
Submessage: &api.ClientOriginatedMessage_MenuItemRequest{
MenuItemRequest: &api.MenuItemRequest{
Identifier: &item,
},
},
})
if err != nil {
return fmt.Errorf("error selecting menu item %q: %w", item, err)
}
if resp.GetMenuItemResponse().GetStatus() != api.MenuItemResponse_OK {
return fmt.Errorf("menu item %q returned unexpected status: %q", item, resp.GetMenuItemResponse().GetStatus().String())
}
return nil
}
22 changes: 22 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
// within a Tab where the terminal is active
type Session interface {
SendText(s string) error
Activate(selectTab, orderWindowFront bool) error
}

type session struct {
Expand All @@ -35,3 +36,24 @@ func (s *session) SendText(t string) error {
}
return nil
}

func (s *session) Activate(selectTab, orderWindowFront bool) error {
resp, err := s.c.Call(&api.ClientOriginatedMessage{
Submessage: &api.ClientOriginatedMessage_ActivateRequest{
ActivateRequest: &api.ActivateRequest{
Identifier: &api.ActivateRequest_SessionId{
SessionId: s.id,
},
SelectTab: &selectTab,
OrderWindowFront: &orderWindowFront,
},
},
})
if err != nil {
return fmt.Errorf("error activating session %q: %w", s.id, err)
}
if status := resp.GetActivateResponse().GetStatus(); status != api.ActivateResponse_OK {
return fmt.Errorf("unexpected status for activate request: %s", status)
}
return nil
}

0 comments on commit bd994a3

Please sign in to comment.