Skip to content

Commit

Permalink
Remove windowChanges channel and pass tea.WindowSizeMsg to children
Browse files Browse the repository at this point in the history
  • Loading branch information
Toby Padilla committed Aug 20, 2021
1 parent b49194b commit 1e101cf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 30 deletions.
39 changes: 18 additions & 21 deletions tui/bubble.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ type MenuEntry struct {
}

type SessionConfig struct {
Width int
Height int
WindowChanges <-chan ssh.Window
InitialRepo string
Width int
Height int
InitialRepo string
}

type Bubble struct {
Expand All @@ -67,22 +66,21 @@ type Bubble struct {

func NewBubble(cfg *Config, sCfg *SessionConfig) *Bubble {
b := &Bubble{
config: cfg,
styles: style.DefaultStyles(),
width: sCfg.Width,
height: sCfg.Height,
windowChanges: sCfg.WindowChanges,
repoSource: cfg.RepoSource,
repoMenu: make([]MenuEntry, 0),
boxes: make([]tea.Model, 2),
initialRepo: sCfg.InitialRepo,
config: cfg,
styles: style.DefaultStyles(),
width: sCfg.Width,
height: sCfg.Height,
repoSource: cfg.RepoSource,
repoMenu: make([]MenuEntry, 0),
boxes: make([]tea.Model, 2),
initialRepo: sCfg.InitialRepo,
}
b.state = startState
return b
}

func (b *Bubble) Init() tea.Cmd {
return tea.Batch(b.windowChangesCmd, b.setupCmd)
return b.setupCmd
}

func (b *Bubble) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
Expand All @@ -108,19 +106,18 @@ func (b *Bubble) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
b.error = msg.Error()
b.state = errorState
return b, nil
case windowMsg:
cmds = append(cmds, b.windowChangesCmd)
case tea.WindowSizeMsg:
b.width = msg.Width
b.height = msg.Height
if b.state == loadedState {
ab, cmd := b.boxes[b.activeBox].Update(msg)
b.boxes[b.activeBox] = ab
if cmd != nil {
cmds = append(cmds, cmd)
for i, bx := range b.boxes {
m, cmd := bx.Update(msg)
b.boxes[i] = m
if cmd != nil {
cmds = append(cmds, cmd)
}
}
}
// XXX: maybe propagate size changes to child bubbles (particularly height)
case selection.SelectedMsg:
b.activeBox = 1
rb := b.repoMenu[msg.Index].bubble
Expand Down
7 changes: 0 additions & 7 deletions tui/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ func (e errMsg) Error() string {
return e.err.Error()
}

func (b *Bubble) windowChangesCmd() tea.Msg {
w := <-b.windowChanges
b.width = w.Width
b.height = w.Height
return windowMsg{}
}

func (b *Bubble) setupCmd() tea.Msg {
lipgloss.SetColorProfile(termenv.ANSI256)
b.repos = b.repoSource.AllRepos()
Expand Down
3 changes: 1 addition & 2 deletions tui/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,13 @@ func SessionHandler(reposPath string, repoPoll time.Duration) func(ssh.Session)
default:
return nil, nil
}
pty, changes, active := s.Pty()
pty, _, active := s.Pty()
if !active {
fmt.Println("not active")
return nil, nil
}
cfg.Width = pty.Window.Width
cfg.Height = pty.Window.Height
cfg.WindowChanges = changes
return NewBubble(appCfg, cfg), []tea.ProgramOption{tea.WithAltScreen()}
}
}
Expand Down

0 comments on commit 1e101cf

Please sign in to comment.