commit 159d0b8

Cowington Post  ·  2023-05-17 05:10:58 +0000 UTC
parent 598fea4
Set terminal window title.

This will change the title of the terminal window to the buffer name
in supported terminals.

Co-authored-by: delthas <delthas@dille.cc>
2 files changed,  +15, -0
M app.go
M app.go
+5, -0
 1@@ -246,6 +246,11 @@ func (app *App) eventLoop() {
 2 				currentMembers = s.Names(buffer)
 3 			}
 4 			app.win.Draw(currentMembers)
 5+			if netID != "" && buffer != "" {
 6+				app.win.SetTitle(fmt.Sprintf("%s — senpai", buffer))
 7+			} else {
 8+				app.win.SetTitle(fmt.Sprintf("senpai"))
 9+			}
10 		}
11 	}
12 	go func() {
+10, -0
 1@@ -40,6 +40,7 @@ type UI struct {
 2 	e      Editor
 3 	prompt StyledString
 4 	status string
 5+	title  string
 6 
 7 	channelOffset int
 8 	memberClicked int
 9@@ -74,6 +75,7 @@ func New(config Config) (ui *UI, err error) {
10 	}
11 	ui.screen.EnablePaste()
12 	ui.screen.SetCursorStyle(tcell.CursorStyleSteadyBar)
13+	ui.screen.SetTitle("senpai")
14 
15 	_, h := ui.screen.Size()
16 	ui.screen.Clear()
17@@ -348,6 +350,14 @@ func (ui *UI) SetPrompt(prompt StyledString) {
18 	ui.prompt = prompt
19 }
20 
21+func (ui *UI) SetTitle(title string) {
22+	if ui.title == title {
23+		return
24+	}
25+	ui.title = title
26+	ui.screen.SetTitle(title)
27+}
28+
29 // InputContent result must not be modified.
30 func (ui *UI) InputContent() []rune {
31 	return ui.e.Content()