Skip to content
Myr

feat: add set-window-title command (#611)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Set the terminal window title using termenv.

authored by Ayman Bagabas · committed by GitHub · parent bc1c475 · Browse files · 5 files+61 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Fixes: https://github.com/charmbracelet/bubbletea/issues/610

Diff stats

5 files+61 added−1 removed

  • other:+61 added−1 removed

5 files+61 added−1 removed

added:examples/set-window-title/main.go+35 added
1package main23// A simple example illustrating how to set a window title.45import (6 "fmt"7 "os"89 tea "github.com/charmbracelet/bubbletea"10)1112type model struct{}1314func (m model) Init() tea.Cmd {15 return tea.SetWindowTitle("Bubble Tea Example")16}1718func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {19 switch msg.(type) {20 case tea.KeyMsg:21 return m, tea.Quit22 }23 return m, nil24}2526func (m model) View() string {27 return "\nPress any key to quit."28}2930func main() {31 if _, err := tea.NewProgram(model{}).Run(); err != nil {32 fmt.Println("Uh oh:", err)33 os.Exit(1)34 }35}
modified:tutorials/basics/main.go+1 added-1 removed
23 unmodified lines
24 }25}2627func (m model) Init() tea.Cmd {28 return nil28 return tea.SetWindowTitle("Grocery List")29}3031func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {32 switch msg := msg.(type) {
54 unmodified lines
modified:commands.go+17 added
168 unmodified lines
169 }170 return nil171 }172}173174// setWindowTitleMsg is an internal message used to set the window title.175type setWindowTitleMsg string176177// SetWindowTitle produces a command that sets the terminal title.178//179// For example:180//181// func (m model) Init() Cmd {182// // Set title.183// return tea.SetWindowTitle("My App")184// }185func SetWindowTitle(title string) Cmd {186 return func() Msg {187 return setWindowTitleMsg(title)188 }189}
modified:screen.go+5 added
165 unmodified lines
166// Deprecated: The mouse will automatically be disabled when the program exits.167func (p *Program) DisableMouseAllMotion() {168 p.renderer.disableMouseAllMotion()169}170171// SetWindowTitle sets the terminal window title.172func (p *Program) SetWindowTitle(title string) {173 p.output.SetWindowTitle(title)174}
modified:tea.go+3 added
386 unmodified lines
387388 p.Send(msg)389 }390 }()391392 case setWindowTitleMsg:393 p.SetWindowTitle(string(msg))394 }395396 // Process internal messages for the renderer.397 if r, ok := p.renderer.(*standardRenderer); ok {
308 unmodified lines