Skip to content

Commit

Permalink
feat: add set-window-title command
Browse files Browse the repository at this point in the history
Set the terminal window title using termenv.

Fixes: #610
  • Loading branch information
aymanbagabas committed Nov 21, 2022
1 parent 79c76c6 commit cabec50
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,21 @@ func Sequentially(cmds ...Cmd) Cmd {
return nil
}
}

// setWindowTitleMsg is an internal message used to set the window title.
type setWindowTitleMsg string

// SetWindowTitle produces a command that sets the terminal title.
// The message returned contains the title that was set.
//
// For example:
//
// func (m model) Init() Cmd {
// // Set title.
// return tea.SetWindowTitle("My App")
// }
func SetWindowTitle(title string) Cmd {
return func() Msg {
return setWindowTitleMsg(title)
}
}
5 changes: 5 additions & 0 deletions screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,8 @@ func (p *Program) EnableMouseAllMotion() {
func (p *Program) DisableMouseAllMotion() {
p.renderer.disableMouseAllMotion()
}

// SetWindowTitle sets the terminal window title.
func (p *Program) SetWindowTitle(title string) {
p.output.SetWindowTitle(title)
}
3 changes: 3 additions & 0 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) {
p.Send(cmd())
}
}()

case setWindowTitleMsg:
p.SetWindowTitle(string(msg))
}

// Process internal messages for the renderer.
Expand Down

0 comments on commit cabec50

Please sign in to comment.