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 fileTake it
1package main23// A simple example illustrating how to set a window title.45import (6 "fmt"7 "os"89 tea "charm.land/bubbletea/v2"10 "charm.land/lipgloss/v2"11)1213const windowTitle = "Hello, Bubble Tea"1415type model struct{}1617func (m model) Init() tea.Cmd {18 return nil19}2021func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {22 switch msg.(type) {23 case tea.KeyPressMsg:24 return m, tea.Quit25 }26 return m, nil27}2829func (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 v35}3637func main() {38 if _, err := tea.NewProgram(model{}).Run(); err != nil {39 fmt.Println("Uh oh:", err)40 os.Exit(1)41 }42}