-
Notifications
You must be signed in to change notification settings - Fork 835
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: query window-size in a goroutine (#1059)
We need to run checkResize in a goroutine, otherwise, it will block. Related: #988 (comment) Fixes: 7d70838 (feat: add a cmd to request window size (#988))
- Loading branch information
1 parent
7d70838
commit 7c1bfc0
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main | ||
|
||
// A simple program that queries and displays the window-size. | ||
|
||
import ( | ||
"log" | ||
|
||
tea "github.com/charmbracelet/bubbletea" | ||
) | ||
|
||
func main() { | ||
p := tea.NewProgram(model{}) | ||
if _, err := p.Run(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
type model struct{} | ||
|
||
func (m model) Init() tea.Cmd { | ||
return nil | ||
} | ||
|
||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
switch msg := msg.(type) { | ||
case tea.KeyMsg: | ||
if s := msg.String(); s == "ctrl+c" || s == "q" || s == "esc" { | ||
return m, tea.Quit | ||
} | ||
|
||
return m, tea.WindowSize() | ||
|
||
case tea.WindowSizeMsg: | ||
return m, tea.Printf("%dx%d", msg.Width, msg.Height) | ||
} | ||
|
||
return m, nil | ||
} | ||
|
||
func (m model) View() string { | ||
s := "When you're done press q to quit. Press any other key to query the window-size.\n" | ||
|
||
return s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters