Enable inline URLs by default on VTE terminals

This commit is contained in:
Tulir Asokan 2022-04-16 19:59:34 +03:00
parent f1d720e2dc
commit b6fba5230a
7 changed files with 34 additions and 12 deletions

View File

@ -23,6 +23,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strconv"
"strings" "strings"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
@ -58,8 +59,21 @@ type UserPreferences struct {
DisableDownloads bool `yaml:"disable_downloads"` DisableDownloads bool `yaml:"disable_downloads"`
DisableNotifications bool `yaml:"disable_notifications"` DisableNotifications bool `yaml:"disable_notifications"`
DisableShowURLs bool `yaml:"disable_show_urls"` DisableShowURLs bool `yaml:"disable_show_urls"`
InlineURLs bool `yaml:"inline_urls"`
AltEnterToSend bool `yaml:"alt_enter_to_send"` AltEnterToSend bool `yaml:"alt_enter_to_send"`
InlineURLMode string `yaml:"inline_url_mode"`
}
var InlineURLsProbablySupported bool
func init() {
v, _ := strconv.Atoi(os.Getenv("VTE_VERSION"))
// Enable inline URLs by default on VTE 0.50.0+
InlineURLsProbablySupported = v > 5000
}
func (up *UserPreferences) EnableInlineURLs() bool {
return up.InlineURLMode == "enable" || (InlineURLsProbablySupported && up.InlineURLMode != "disable")
} }
type Keybind struct { type Keybind struct {

4
go.mod
View File

@ -17,8 +17,8 @@ require (
github.com/zyedidia/clipboard v1.0.3 github.com/zyedidia/clipboard v1.0.3
go.etcd.io/bbolt v1.3.6 go.etcd.io/bbolt v1.3.6
go.mau.fi/cbind v0.0.0-20220415094356-e1d579b7925e go.mau.fi/cbind v0.0.0-20220415094356-e1d579b7925e
go.mau.fi/mauview v0.1.4-0.20220415192914-be7d4f257167 go.mau.fi/mauview v0.1.4-0.20220416164650-aac1ebd3a472
go.mau.fi/tcell v0.0.0-20220415185117-592f364693a2 go.mau.fi/tcell v0.0.0-20220416164612-f5dbb33f6c9c
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 golang.org/x/net v0.0.0-20220412020605-290c469a71a5
gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2 gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2

8
go.sum
View File

@ -63,11 +63,11 @@ go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU=
go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4= go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4=
go.mau.fi/cbind v0.0.0-20220415094356-e1d579b7925e h1:zY4TZmHAaUhrMFJQfh02dqxDYSfnnXlw/qRoFanxZTw= go.mau.fi/cbind v0.0.0-20220415094356-e1d579b7925e h1:zY4TZmHAaUhrMFJQfh02dqxDYSfnnXlw/qRoFanxZTw=
go.mau.fi/cbind v0.0.0-20220415094356-e1d579b7925e/go.mod h1:9nnzlslhUo/xO+8tsQgkFqG/W+SgD+r0iTYAuglzlmA= go.mau.fi/cbind v0.0.0-20220415094356-e1d579b7925e/go.mod h1:9nnzlslhUo/xO+8tsQgkFqG/W+SgD+r0iTYAuglzlmA=
go.mau.fi/mauview v0.1.4-0.20220415192914-be7d4f257167 h1:WCqpsiR7IuOJ36aDd9pbPxr9AtjnXvPHhPKw9xx9x2Q= go.mau.fi/mauview v0.1.4-0.20220416164650-aac1ebd3a472 h1:1Rx+gZAORRrkevGQuLfDEM8E5cYxNRAA3lx2Rc19H5g=
go.mau.fi/mauview v0.1.4-0.20220415192914-be7d4f257167/go.mod h1:1rzvl7kqQ9lv8EVZeAwUlxR4/Q8LM3y2Xogg0yNx0qU= go.mau.fi/mauview v0.1.4-0.20220416164650-aac1ebd3a472/go.mod h1:3W0lnT2QE0M/HF0d5dgyCG71QEc+pS/+RQf1lGybEzE=
go.mau.fi/tcell v0.0.0-20220415093808-07c67d224693/go.mod h1:HQLPCz9v8YfYewMetOKrg9pe87XEyNcIfCYYq8VxQbU= go.mau.fi/tcell v0.0.0-20220415093808-07c67d224693/go.mod h1:HQLPCz9v8YfYewMetOKrg9pe87XEyNcIfCYYq8VxQbU=
go.mau.fi/tcell v0.0.0-20220415185117-592f364693a2 h1:UocCXayiOk0dzu7GeTyiH6UdpJnp5d645NRDwr6RjLY= go.mau.fi/tcell v0.0.0-20220416164612-f5dbb33f6c9c h1:BdwxPvI30uM9Yhr1t99sHHoEzbK8JLfRntQDpm/QCdg=
go.mau.fi/tcell v0.0.0-20220415185117-592f364693a2/go.mod h1:HQLPCz9v8YfYewMetOKrg9pe87XEyNcIfCYYq8VxQbU= go.mau.fi/tcell v0.0.0-20220416164612-f5dbb33f6c9c/go.mod h1:HQLPCz9v8YfYewMetOKrg9pe87XEyNcIfCYYq8VxQbU=
golang.org/x/crypto v0.0.0-20220408190544-5352b0902921 h1:iU7T1X1J6yxDr0rda54sWGkHgOp5XJrqm79gcNlC2VM= golang.org/x/crypto v0.0.0-20220408190544-5352b0902921 h1:iU7T1X1J6yxDr0rda54sWGkHgOp5XJrqm79gcNlC2VM=
golang.org/x/crypto v0.0.0-20220408190544-5352b0902921/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220408190544-5352b0902921/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=

View File

@ -867,7 +867,15 @@ func cmdToggle(cmd *Command) {
case "showurls": case "showurls":
val = &cmd.Config.Preferences.DisableShowURLs val = &cmd.Config.Preferences.DisableShowURLs
case "inlineurls": case "inlineurls":
val = &cmd.Config.Preferences.InlineURLs switch cmd.Config.Preferences.InlineURLMode {
case "enable":
cmd.Config.Preferences.InlineURLMode = "disable"
cmd.Reply("Force-disabled using fancy terminal features to render URLs inside text. Restart gomuks to apply changes.")
default:
cmd.Config.Preferences.InlineURLMode = "enable"
cmd.Reply("Force-enabled using fancy terminal features to render URLs inside text. Restart gomuks to apply changes.")
}
continue
case "newline": case "newline":
val = &cmd.Config.Preferences.AltEnterToSend val = &cmd.Config.Preferences.AltEnterToSend
default: default:

View File

@ -148,7 +148,7 @@ func (msg *FileMessage) CalculateBuffer(prefs config.UserPreferences, width int,
if prefs.BareMessageView || prefs.DisableImages || len(msg.imageData) == 0 { if prefs.BareMessageView || prefs.DisableImages || len(msg.imageData) == 0 {
url := msg.matrix.GetDownloadURL(msg.URL) url := msg.matrix.GetDownloadURL(msg.URL)
var urlTString tstring.TString var urlTString tstring.TString
if prefs.InlineURLs { if prefs.EnableInlineURLs() {
urlTString = tstring.NewStyleTString(url, tcell.StyleDefault.Hyperlink(url, msg.eventID.String())) urlTString = tstring.NewStyleTString(url, tcell.StyleDefault.Hyperlink(url, msg.eventID.String()))
} else { } else {
urlTString = tstring.NewTString(url) urlTString = tstring.NewTString(url)

View File

@ -234,7 +234,7 @@ func (parser *htmlParser) linkToEntity(node *html.Node) Entity {
} else if matrixURI.Sigil1 == '#' { } else if matrixURI.Sigil1 == '#' {
entity.Children = []Entity{text} entity.Children = []Entity{text}
} }
} else if parser.prefs.InlineURLs { } else if parser.prefs.EnableInlineURLs() {
linkID := fmt.Sprintf("%s-%d", parser.evt.ID, parser.linkIDCounter) linkID := fmt.Sprintf("%s-%d", parser.evt.ID, parser.linkIDCounter)
parser.linkIDCounter++ parser.linkIDCounter++
entity.AdjustStyle(AdjustStyleLink(href, linkID), AdjustStyleReasonNormal) entity.AdjustStyle(AdjustStyleLink(href, linkID), AdjustStyleReasonNormal)
@ -426,7 +426,7 @@ func (parser *htmlParser) singleNodeToEntity(node *html.Node) Entity {
node.Data = strings.ReplaceAll(node.Data, "\n", "") node.Data = strings.ReplaceAll(node.Data, "\n", "")
node.Data = spaces.ReplaceAllLiteralString(node.Data, " ") node.Data = spaces.ReplaceAllLiteralString(node.Data, " ")
} }
return TextToEntity(node.Data, parser.evt.ID, parser.prefs.InlineURLs) return TextToEntity(node.Data, parser.evt.ID, parser.prefs.EnableInlineURLs())
case html.ElementNode: case html.ElementNode:
parsed := parser.tagNodeToEntity(node) parsed := parser.tagNodeToEntity(node)
if parsed != nil && !parsed.IsBlock() && parsed.IsEmpty() { if parsed != nil && !parsed.IsBlock() && parsed.IsEmpty() {

View File

@ -208,7 +208,7 @@ func ParseMessage(matrix ifc.MatrixContainer, room *rooms.Room, evt *muksevt.Eve
return NewHTMLMessage(evt, displayname, html.Parse(matrix.Preferences(), room, content, evt, displayname)) return NewHTMLMessage(evt, displayname, html.Parse(matrix.Preferences(), room, content, evt, displayname))
} }
content.Body = strings.Replace(content.Body, "\t", " ", -1) content.Body = strings.Replace(content.Body, "\t", " ", -1)
return NewHTMLMessage(evt, displayname, html.TextToEntity(content.Body, evt.ID, matrix.Preferences().InlineURLs)) return NewHTMLMessage(evt, displayname, html.TextToEntity(content.Body, evt.ID, matrix.Preferences().EnableInlineURLs()))
case event.MsgImage, event.MsgVideo, event.MsgAudio, event.MsgFile: case event.MsgImage, event.MsgVideo, event.MsgAudio, event.MsgFile:
msg := NewFileMessage(matrix, evt, displayname) msg := NewFileMessage(matrix, evt, displayname)
if !matrix.Preferences().DisableDownloads { if !matrix.Preferences().DisableDownloads {