Skip to content

View() called before WindowSizeMsg #283

Discussion options

You must be logged in to vote

Hi! The query for the initial window size runs asynchronously so that it doesn't hold up the program startup (since many programs don't need the window size). As a result, it's very possible that the initial view can be called before the window size is queried. If your program does depend on knowing the window size the general pattern is to set a flag on your model when the window size comes in and manage output in your view accordingly.

Here’s a contrived example of how it's commonly done with a notion of application state:

package main

import (
	"fmt"
	"os"

	tea "github.com/charmbracelet/bubbletea"
)

type state int

const (
	initializing state = iota
	ready
)

type model struct {
	state

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by meowgorithm
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@meowgorithm
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #282 on April 10, 2022 16:48.