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
1package main23// A simple program that queries and displays the window-size.45import (6 "log"78 tea "charm.land/bubbletea/v2"9)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) {26 case tea.KeyPressMsg:27 if s := msg.String(); s == "ctrl+c" || s == "q" || s == "esc" {28 return m, tea.Quit29 }30 return m, tea.RequestWindowSize3132 case tea.WindowSizeMsg:33 return m, tea.Printf("The window size is: %dx%d", msg.Width, msg.Height)34 }3536 return m, nil37}3839func (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")41}