main.go
This file
Path
examples/window-size/main.go
41 lines · 801 bytes · Go
Last changed by
Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
History of this fileTake it
The walk stopped after 200 commits: lines older than 3dfbcd9 point at it.
feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 1–7why, one step back1package main23// A simple program that queries and displays the window-size.45import (6 "log"7Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
line 8why, one step back8 tea "charm.land/bubbletea/v2"feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 9–25why, one step back9)1011func main() {12 p := tea.NewProgram(model{})13 if _, err := p.Run(); err != nil {14 log.Fatal(err)15 }16}1718type model struct{}1920func (m model) Init() tea.Cmd {21 return nil22}2324func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {25 switch msg := msg.(type) {Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
line 26why, one step back26 case tea.KeyPressMsg:feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 27–29why, one step back27 if s := msg.String(); s == "ctrl+c" || s == "q" || s == "esc" {28 return m, tea.Quit29 }Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
line 30why, one step back30 return m, tea.RequestWindowSizefeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 31–32why, one step back3132 case tea.WindowSizeMsg:Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
line 33why, one step back33 return m, tea.Printf("The window size is: %dx%d", msg.Width, msg.Height)feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 34–38why, one step back34 }3536 return m, nil37}38Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 39–40why, one step back39func (m model) View() tea.View {40 return tea.NewView("\nWhen you're done press q to quit.\nPress any other key to query the window-size.\n")feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 41why, one step back41}