summaryrefslogtreecommitdiff
path: root/aerc.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-02-20 10:32:38 +0100
committerRobin Jarry <robin@jarry.cc>2022-02-20 21:29:20 +0100
commit726969833bc95fc97f5ee38b435d4ba23b5613d4 (patch)
treeb74a1bd8cf8685ee5ea01473b317c92843c56f05 /aerc.go
parent6c460493efafb065822a9bb4454599f5c6522c61 (diff)
downloadaerc-726969833bc95fc97f5ee38b435d4ba23b5613d4.zip
main: use terminfo to set window title
Parse the terminal capabilities from the TERM environment variable instead of using a hard coded list of terminals. tcell does not expose the status line capabilities. Use another library for this: github.com/xo/terminfo Signed-off-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'aerc.go')
-rw-r--r--aerc.go26
1 files changed, 15 insertions, 11 deletions
diff --git a/aerc.go b/aerc.go
index 555b3a3..65c31ec 100644
--- a/aerc.go
+++ b/aerc.go
@@ -1,6 +1,7 @@
package main
import (
+ "bytes"
"fmt"
"io"
"io/ioutil"
@@ -8,11 +9,11 @@ import (
"os"
"runtime/debug"
"sort"
- "strings"
"time"
"git.sr.ht/~sircmpwn/getopt"
"github.com/mattn/go-isatty"
+ "github.com/xo/terminfo"
"git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/commands/account"
@@ -93,18 +94,21 @@ func usage() {
log.Fatal("Usage: aerc [-v] [mailto:...]")
}
-var termsWithStatusLine = []string{"xterm", "tmux", "screen"}
-
func setWindowTitle() {
- term := strings.ToLower(os.Getenv("TERM"))
- for _, t := range termsWithStatusLine {
- if strings.Contains(term, t) {
- // TODO: avoid hard coding the list of terminals that
- // have status line support.
- os.Stderr.Write([]byte("\x1b]0;aerc\a"))
- return
- }
+ ti, err := terminfo.LoadFromEnv()
+ if err != nil {
+ return
}
+
+ if !ti.Has(terminfo.HasStatusLine) {
+ return
+ }
+
+ buf := new(bytes.Buffer)
+ ti.Fprintf(buf, terminfo.ToStatusLine)
+ fmt.Fprint(buf, "aerc")
+ ti.Fprintf(buf, terminfo.FromStatusLine)
+ os.Stderr.Write(buf.Bytes())
}
func main() {