Skip to content

Commit

Permalink
fix: param changes should cause immediate rerender
Browse files Browse the repository at this point in the history
  • Loading branch information
cfoust committed Oct 19, 2024
1 parent 04a4b89 commit efd2cf6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkg/cy/api/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Server interface {
SocketName() string
ExecuteJanet(path string) error
Log(level zerolog.Level, message string)
RerenderClients()
}

func getClient(context interface{}) (Client, error) {
Expand Down
14 changes: 12 additions & 2 deletions pkg/cy/api/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
)

type ParamModule struct {
Tree *tree.Tree
Tree *tree.Tree
Server Server
}

// haha
Expand Down Expand Up @@ -89,5 +90,14 @@ func (p *ParamModule) Set(
params = node.Params()
}

return params.Set(string(keyword), value)
err = params.Set(string(keyword), value)
if err != nil {
return err
}

// Many params affect rendering; we need to cause a rerender right
// away to ensure all client screens remain accurate.
// TODO(cfoust): 10/20/24 maybe this should be under the layout engine so it's throttled?
p.Server.RerenderClients()
return nil
}
9 changes: 6 additions & 3 deletions pkg/cy/janet.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ func (c *Cy) initJanet(ctx context.Context) (*janet.VM, error) {
TimeBinds: c.timeBinds,
CopyBinds: c.copyBinds,
},
"pane": &api.PaneModule{Tree: c.tree},
"param": &api.ParamModule{Tree: c.tree},
"path": &api.PathModule{},
"pane": &api.PaneModule{Tree: c.tree},
"param": &api.ParamModule{
Server: c,
Tree: c.tree,
},
"path": &api.PathModule{},
"replay": &api.ReplayModule{
Lifetime: util.NewLifetime(c.Ctx()),
Tree: c.tree,
Expand Down
11 changes: 11 additions & 0 deletions pkg/cy/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ func (c *Cy) reloadConfig() error {
return c.loadConfig()
}

// RerenderClients triggers a rerender of all clients.
func (c *Cy) RerenderClients() {
c.RLock()
defer c.RUnlock()

clients := c.clients
for _, client := range clients {
client.layoutEngine.Notify()
}
}

// Get the first pane that another client is attached to or return nil if there
// are no other clients.
func (c *Cy) getFirstClientPane(except *Client) tree.Node {
Expand Down

0 comments on commit efd2cf6

Please sign in to comment.