Skip to content
Myr

main.go

This file

Path

examples/set-window-title/main.go

42 lines · 791 bytes · Go

Last changed by

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

History of this file

Take 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–8why, one step back
1package main
23// A simple example illustrating how to set a window title.45import (6 "fmt"7 "os"8

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 9–10why, one step back
9 tea "charm.land/bubbletea/v2"
10 "charm.land/lipgloss/v2"

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 11–12why, one step back
11)
12

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 13–14why, one step back
13const windowTitle = "Hello, Bubble Tea"
14

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 15–17why, one step back
15type model struct{}
1617func (m model) Init() tea.Cmd {

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 18why, one step back
18 return nil

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 19–22why, one step back
19}
2021func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {22 switch msg.(type) {

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 23why, one step back
23 case tea.KeyPressMsg:

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 24–28why, one step back
24 return m, tea.Quit
25 }26 return m, nil27}28

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 29–34why, one step back
29func (m model) View() tea.View {
30 wrap := lipgloss.NewStyle().Width(78).Render31 v := tea.NewView(wrap("The window title has been set to '"+windowTitle+"'. It will be cleared on exit.") +32 "\n\nPress any key to quit.")33 v.WindowTitle = windowTitle34 return v

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 35–42why, one step back
35}
3637func main() {38 if _, err := tea.NewProgram(model{}).Run(); err != nil {39 fmt.Println("Uh oh:", err)40 os.Exit(1)41 }42}