feat: add a cmd to request window size (#988)
* feat: add a cmd to request window size Fixes: https://github.com/charmbracelet/bubbletea/issues/987#issuecomment-2068452658 * Update commands.go Co-authored-by: Christian Rocha <christian@rocha.is> --------- Co-authored-by: Christian Rocha <christian@rocha.is>
This commit is contained in:
parent
4497aa9eef
commit
7d708384a1
2 changed files with 16 additions and 0 deletions
13
commands.go
13
commands.go
|
|
@ -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
tea.go
3
tea.go
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue