From 5098f125a1cd249fa83e24aa9d968b2e29c8196c Mon Sep 17 00:00:00 2001 From: makeworld Date: Fri, 3 Dec 2021 11:45:36 -0500 Subject: [PATCH] Underline non-gemini links for color blind users Fixes #189 --- CHANGELOG.md | 9 ++++-- config/config.go | 1 + config/default.go | 15 ++++++++++ default-config.toml | 15 ++++++++++ display/thanks.go | 1 + renderer/renderer.go | 70 +++++++++++++++++++++++++++++--------------- 6 files changed, 85 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 984a96e..7261bd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,18 +15,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Display gemtext from stdin (#205, #242) - Specifying `default` in the theme config uses the terminal's default background color, including transparency (#244, #245) - Redirects occur automatically if it only adds a trailing slash (#271) +- Non-gemini links are underlined by default to help color blind users (#189) ### Changed -- Favicon support removed (#199) - Bookmarks are stored using XML in the XBEL format, old bookmarks are transferred (#68) -- Text no longer disappears under the left margin when scrolling (regression from v1.8.0) (#197) +- Text no longer disappears under the left margin when scrolling (regression in v1.8.0) (#197) - Default search engine changed to geminispace.info from gus.guru +## Removed +- Favicon support removed (#199) + ### Fixed - Help text is now the same color as `regular_text` in the theme config - Non-ASCII (multibyte) characters can now be used as keybindings (#198, #200) - Possible subscription update race condition on startup -- Plaintext documents are escaped properly (regression from v1.8.0) +- Plaintext documents are escaped properly (regression in v1.8.0) - Help page scrollbar color matches what's in the theme config - Regression where lists would not appear if `bullets = false` (#234, #235) - Support multiple bookmarks with the same name diff --git a/config/config.go b/config/config.go index 54fbb89..250ce25 100644 --- a/config/config.go +++ b/config/config.go @@ -204,6 +204,7 @@ func Init() error { viper.SetDefault("a-general.page_max_size", 2097152) viper.SetDefault("a-general.page_max_time", 10) viper.SetDefault("a-general.scrollbar", "auto") + viper.SetDefault("a-general.underline", true) viper.SetDefault("keybindings.bind_reload", []string{"R", "Ctrl-R"}) viper.SetDefault("keybindings.bind_home", "Backspace") viper.SetDefault("keybindings.bind_bookmarks", "Ctrl-B") diff --git a/config/default.go b/config/default.go index 78fc465..9f98f2a 100644 --- a/config/default.go +++ b/config/default.go @@ -3,6 +3,17 @@ package config //go:generate ./default.sh var defaultConf = []byte(`# This is the default config file. # It also shows all the default values, if you don't create the file. +# You can edit this file to set your own configuration for Amfora. + +# When Amfora updates, defaults may change, but this file on your drive will not. +# You can always get the latest defaults on GitHub. +# https://github.com/makeworld-the-better-one/amfora/blob/master/default-config.toml + +# Please also check out the Amfora Wiki for more help +# https://github.com/makeworld-the-better-one/amfora/wiki +# gemini://makeworld.space/amfora-wiki/ + + # All URL values may omit the scheme and/or port, as well as the beginning double slash # Valid URL examples: @@ -74,6 +85,10 @@ page_max_time = 10 # "auto" means the scrollbar only appears when the page is longer than the window. scrollbar = "auto" +# Underline non-gemini URLs +# This is done to help color blind users +underline = true + [auth] # Authentication settings diff --git a/default-config.toml b/default-config.toml index be6f33f..09ceb3f 100644 --- a/default-config.toml +++ b/default-config.toml @@ -1,5 +1,16 @@ # This is the default config file. # It also shows all the default values, if you don't create the file. +# You can edit this file to set your own configuration for Amfora. + +# When Amfora updates, defaults may change, but this file on your drive will not. +# You can always get the latest defaults on GitHub. +# https://github.com/makeworld-the-better-one/amfora/blob/master/default-config.toml + +# Please also check out the Amfora Wiki for more help +# https://github.com/makeworld-the-better-one/amfora/wiki +# gemini://makeworld.space/amfora-wiki/ + + # All URL values may omit the scheme and/or port, as well as the beginning double slash # Valid URL examples: @@ -71,6 +82,10 @@ page_max_time = 10 # "auto" means the scrollbar only appears when the page is longer than the window. scrollbar = "auto" +# Underline non-gemini URLs +# This is done to help color blind users +underline = true + [auth] # Authentication settings diff --git a/display/thanks.go b/display/thanks.go index fd2941d..0e479c0 100644 --- a/display/thanks.go +++ b/display/thanks.go @@ -27,4 +27,5 @@ Thank you to the following contributors, who have helped make Amfora great. FOSS * Anas Mohamed (@amohamed11) * David Jimenez (@dvejmz) * Michael McDonagh (@m-mcdonagh) +* mooff (@awfulcooking) `) diff --git a/renderer/renderer.go b/renderer/renderer.go index 911f36e..74b5e14 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -159,6 +159,12 @@ func convertRegularGemini(s string, numLinks, width int, proxied bool) (string, spacing = " " } + // Underline non-gemini links if enabled + var linkTag string + if viper.GetBool("a-general.underline") { + linkTag = "::u" + } + // Wrap and add link text // Wrap the link text, but add some spaces to indent the wrapped lines past the link number // Set the style tags @@ -166,11 +172,12 @@ func convertRegularGemini(s string, numLinks, width int, proxied bool) (string, var wrappedLink []string - if viper.GetBool("a-general.color") { - pU, err := urlPkg.Parse(url) - if !proxied && err == nil && - (pU.Scheme == "" || pU.Scheme == "gemini" || pU.Scheme == "about") { - // A gemini link + pU, err := urlPkg.Parse(url) + if !proxied && err == nil && + (pU.Scheme == "" || pU.Scheme == "gemini" || pU.Scheme == "about") { + // A gemini link + + if viper.GetBool("a-general.color") { // Add the link text in blue (in a region), and a gray link number to the left of it // Those are the default colors, anyway @@ -187,33 +194,50 @@ func convertRegularGemini(s string, numLinks, width int, proxied bool) (string, `["` + strconv.Itoa(num-1) + `"][` + config.GetColorString("amfora_link") + `]` + wrappedLink[0] + `[-][""]` } else { - // Not a gemini link + // No color + + wrappedLink = wrapLine(linkText, width, + strings.Repeat(" ", len(strconv.Itoa(num))+4)+ // +4 for spaces and brackets + `["`+strconv.Itoa(num-1)+`"]`, + `[""]`, + false, // Don't indent the first line, it's the one with link number + ) + + wrappedLink[0] = `[::b][` + strconv.Itoa(num) + "[][::-] " + + `["` + strconv.Itoa(num-1) + `"]` + + wrappedLink[0] + `[""]` + } + } else { + // Not a gemini link + + if viper.GetBool("a-general.color") { + // Color wrappedLink = wrapLine(linkText, width, strings.Repeat(" ", indent)+ - `["`+strconv.Itoa(num-1)+`"][`+config.GetColorString("foreign_link")+`]`, - `[-][""]`, + `["`+strconv.Itoa(num-1)+`"][`+config.GetColorString("foreign_link")+linkTag+`]`, + `[-::-][""]`, false, // Don't indent the first line, it's the one with link number ) wrappedLink[0] = fmt.Sprintf(`[%s::b][`, config.GetColorString("link_number")) + strconv.Itoa(num) + "[]" + "[-::-]" + spacing + - `["` + strconv.Itoa(num-1) + `"][` + config.GetColorString("foreign_link") + `]` + - wrappedLink[0] + `[-][""]` + `["` + strconv.Itoa(num-1) + `"][` + config.GetColorString("foreign_link") + linkTag + `]` + + wrappedLink[0] + `[-::-][""]` + } else { + // No color + + wrappedLink = wrapLine(linkText, width, + strings.Repeat(" ", len(strconv.Itoa(num))+4)+ // +4 for spaces and brackets + `["`+strconv.Itoa(num-1)+`"][`+linkTag+`]`, + `[::-][""]`, + false, // Don't indent the first line, it's the one with link number + ) + + wrappedLink[0] = `[::b][` + strconv.Itoa(num) + "[][::-] " + + `["` + strconv.Itoa(num-1) + `"][` + linkTag + `]` + + wrappedLink[0] + `[::-][""]` } - } else { - // No colors allowed - - wrappedLink = wrapLine(linkText, width, - strings.Repeat(" ", len(strconv.Itoa(num))+4)+ // +4 for spaces and brackets - `["`+strconv.Itoa(num-1)+`"]`, - `[""]`, - false, // Don't indent the first line, it's the one with link number - ) - - wrappedLink[0] = `[::b][` + strconv.Itoa(num) + "[][::-] " + - `["` + strconv.Itoa(num-1) + `"]` + - wrappedLink[0] + `[""]` } wrappedLines = append(wrappedLines, wrappedLink...)