~delthas/senpai-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH v1] Set terminal window title.

Details
Message ID
<20230517051058.40493-1-cowingtonpost@gmail.com>
DKIM signature
missing
Download raw message
Patch: +22 -0
This will change the title of the terminal window to senpai when running
on a supported terminal.
---
 cmd/senpai/main.go | 17 +++++++++++++++++
 go.mod             |  1 +
 go.sum             |  4 ++++
 3 files changed, 22 insertions(+)

diff --git a/cmd/senpai/main.go b/cmd/senpai/main.go
index 6434182..9a7e85e 100644
--- a/cmd/senpai/main.go
+++ b/cmd/senpai/main.go
@@ -1,6 +1,7 @@
package main

import (
	"bytes"
	"flag"
	"fmt"
	"io/ioutil"
@@ -14,6 +15,7 @@ import (

	"git.sr.ht/~taiite/senpai"
	"github.com/gdamore/tcell/v2"
	"github.com/xo/terminfo"
)

func main() {
@@ -60,12 +62,27 @@ func main() {
		app.Close()
	}()

	setWindowTitle()

	app.Run()
	app.Close()
	writeLastBuffer(app)
	writeLastStamp(app)
}

func setWindowTitle() {
	ti, err := terminfo.LoadFromEnv()
	if err != nil || !ti.Has(terminfo.HasStatusLine) {
		return
	}

	buf := new(bytes.Buffer)
	ti.Fprintf(buf, terminfo.ToStatusLine)
	fmt.Fprint(buf, "senpai")
	ti.Fprintf(buf, terminfo.FromStatusLine)
	os.Stderr.Write(buf.Bytes())
}

func cachePath() string {
	cacheDir, err := os.UserCacheDir()
	if err != nil {
diff --git a/go.mod b/go.mod
index 2ce6a89..90a068d 100644
--- a/go.mod
+++ b/go.mod
@@ -8,6 +8,7 @@ require (
	github.com/delthas/go-localeinfo v0.0.0-20221116001557-686a1e185118
	github.com/gdamore/tcell/v2 v2.5.4-0.20221017224006-ede1dd5ee680
	github.com/mattn/go-runewidth v0.0.14
	github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
	golang.org/x/net v0.0.0-20220722155237-a158d28d115b
	golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
	golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6
diff --git a/go.sum b/go.sum
index f087e56..34589b8 100644
--- a/go.sum
+++ b/go.sum
@@ -12,6 +12,7 @@ github.com/gdamore/tcell/v2 v2.5.4-0.20221017224006-ede1dd5ee680 h1:bCjGvZsZNvhz
github.com/gdamore/tcell/v2 v2.5.4-0.20221017224006-ede1dd5ee680/go.mod h1:XmCynGHvvGG7UFI6az9zzoEHBvZB1PGf5APwOJMFUyE=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@@ -25,9 +26,12 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=

base-commit: 1318e784bd2bba3765aee97811a3f0053d3a6723
-- 
2.40.1
Details
Message ID
<CSOHNRXB4Y76.1FO2D0GYSZFVW@spunky>
In-Reply-To
<20230517051058.40493-1-cowingtonpost@gmail.com> (view parent)
DKIM signature
missing
Download raw message
On Wed May 17, 2023 at 12:10 AM CDT, Cowington Post wrote:
> This will change the title of the terminal window to senpai when running
> on a supported terminal.
> ---

Hey Cowington -

This is the exact way aerc is using to set the window title, too.
I looked through tcell's prebuilt terminfo database to see if they are
providing this sequence already, without having to pull in another
dependency. Unfortunately it's not provided there, so this seems like a
sane alternative.

-- 
Tim

>  cmd/senpai/main.go | 17 +++++++++++++++++
>  go.mod             |  1 +
>  go.sum             |  4 ++++
>  3 files changed, 22 insertions(+)
>
> diff --git a/cmd/senpai/main.go b/cmd/senpai/main.go
> index 6434182..9a7e85e 100644
> --- a/cmd/senpai/main.go
> +++ b/cmd/senpai/main.go
> @@ -1,6 +1,7 @@
>  package main
>  
>  import (
> +	"bytes"
>  	"flag"
>  	"fmt"
>  	"io/ioutil"
> @@ -14,6 +15,7 @@ import (
>  
>  	"git.sr.ht/~taiite/senpai"
>  	"github.com/gdamore/tcell/v2"
> +	"github.com/xo/terminfo"
>  )
>  
>  func main() {
> @@ -60,12 +62,27 @@ func main() {
>  		app.Close()
>  	}()
>  
> +	setWindowTitle()
> +
>  	app.Run()
>  	app.Close()
>  	writeLastBuffer(app)
>  	writeLastStamp(app)
>  }
>  
> +func setWindowTitle() {
> +	ti, err := terminfo.LoadFromEnv()
> +	if err != nil || !ti.Has(terminfo.HasStatusLine) {
> +		return
> +	}
> +
> +	buf := new(bytes.Buffer)
> +	ti.Fprintf(buf, terminfo.ToStatusLine)
> +	fmt.Fprint(buf, "senpai")
> +	ti.Fprintf(buf, terminfo.FromStatusLine)
> +	os.Stderr.Write(buf.Bytes())
> +}
> +
>  func cachePath() string {
>  	cacheDir, err := os.UserCacheDir()
>  	if err != nil {
> diff --git a/go.mod b/go.mod
> index 2ce6a89..90a068d 100644
> --- a/go.mod
> +++ b/go.mod
> @@ -8,6 +8,7 @@ require (
>  	github.com/delthas/go-localeinfo v0.0.0-20221116001557-686a1e185118
>  	github.com/gdamore/tcell/v2 v2.5.4-0.20221017224006-ede1dd5ee680
>  	github.com/mattn/go-runewidth v0.0.14
> +	github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
>  	golang.org/x/net v0.0.0-20220722155237-a158d28d115b
>  	golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
>  	golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6
> diff --git a/go.sum b/go.sum
> index f087e56..34589b8 100644
> --- a/go.sum
> +++ b/go.sum
> @@ -12,6 +12,7 @@ github.com/gdamore/tcell/v2 v2.5.4-0.20221017224006-ede1dd5ee680 h1:bCjGvZsZNvhz
>  github.com/gdamore/tcell/v2 v2.5.4-0.20221017224006-ede1dd5ee680/go.mod h1:XmCynGHvvGG7UFI6az9zzoEHBvZB1PGf5APwOJMFUyE=
>  github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
>  github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
> +github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
>  github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
>  github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
>  github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
> @@ -25,9 +26,12 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK
>  github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
>  github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
>  github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
> +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
> +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
>  github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
>  golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
>  golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
> +golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
>  golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
>  golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
>  golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
>
> base-commit: 1318e784bd2bba3765aee97811a3f0053d3a6723



-- 
Tim
Details
Message ID
<33f1e28b-21fd-e188-6b3b-08db3fbcaccd@dille.cc>
In-Reply-To
<CSOHNRXB4Y76.1FO2D0GYSZFVW@spunky> (view parent)
DKIM signature
missing
Download raw message
Hi,

Thanks for the patch!

That's a cool feature.

Largely modified to use a tcell fork with support for setting the title. 
Also to set the title based on the buffer name. Pushed.

Thanks!

-- 

delthas
Reply to thread Export thread (mbox)