Skip to content

Commit

Permalink
feat: add a cmd to request window size (#988)
Browse files Browse the repository at this point in the history
* feat: add a cmd to request window size

Fixes: #987 (comment)

* Update commands.go

Co-authored-by: Christian Rocha <[email protected]>

---------

Co-authored-by: Christian Rocha <[email protected]>
  • Loading branch information
aymanbagabas and meowgorithm authored Jul 16, 2024
1 parent 4497aa9 commit 7d70838
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,16 @@ func SetWindowTitle(title string) Cmd {
return setWindowTitleMsg(title)
}
}

type windowSizeMsg struct{}

// WindowSize is a command that queries the terminal for its current size. It
// delivers the results to Update via a [WindowSizeMsg]. Keep in mind that
// WindowSizeMsgs will automatically be delivered to Update when the [Program]
// starts and when the window dimensions change so in many cases you will not
// need to explicitly invoke this command.
func WindowSize() Cmd {
return func() Msg {
return windowSizeMsg{}
}
}
3 changes: 3 additions & 0 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) {

case setWindowTitleMsg:
p.SetWindowTitle(string(msg))

case windowSizeMsg:
p.checkResize()
}

// Process internal messages for the renderer.
Expand Down

0 comments on commit 7d70838

Please sign in to comment.