1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-06-19 19:25:24 +00:00

🐛 Fixed link highlighting when wrapped

This commit is contained in:
makeworld 2020-07-09 15:21:09 -04:00
parent 06a112b1cc
commit f00fbce7f9
6 changed files with 41 additions and 19 deletions

View File

@ -4,7 +4,6 @@
## Issues
- Can't go back or do other things while page is loading - need a way to stop `handleURL`
- Change renderer to start style tags on each new line of wrapped link, to prevent left margin from being highlighted
## Upstream Bugs
- Wrapping messes up on brackets

View File

@ -19,14 +19,15 @@ home = "gemini://gemini.circumlunar.space"
# If a command is set, than the URL will be added (in quotes) to the end of the command.
# A space will be prepended if necessary.
http = "default"
search = "gemini://gus.guru/search" # Any URL that will accept a query string can be put here
color = true # Whether colors will be used in the terminal
bullets = true # Whether to replace list asterisks with unicode bullets
# A number from 0 to 1, indicating what percentage of the terminal width the left margin should take up.
left_margin = 0.15
max_width = 100 # The max number of columns to wrap a page's text to. Preformatted blocks are not wrapped.
# 'downloads' is the path to a downloads folder.
# An empty value means the code will find the default downloads folder for your system.
downloads = ""
# Options for page cache - which is only for text/gemini pages
# Increase the cache size to speed up browsing at the expense of memory
[cache]

View File

@ -16,14 +16,15 @@ home = "gemini://gemini.circumlunar.space"
# If a command is set, than the URL will be added (in quotes) to the end of the command.
# A space will be prepended if necessary.
http = "default"
search = "gemini://gus.guru/search" # Any URL that will accept a query string can be put here
color = true # Whether colors will be used in the terminal
bullets = true # Whether to replace list asterisks with unicode bullets
# A number from 0 to 1, indicating what percentage of the terminal width the left margin should take up.
left_margin = 0.15
max_width = 100 # The max number of columns to wrap a page's text to. Preformatted blocks are not wrapped.
# 'downloads' is the path to a downloads folder.
# An empty value means the code will find the default downloads folder for your system.
downloads = ""
# Options for page cache - which is only for text/gemini pages
# Increase the cache size to speed up browsing at the expense of memory
[cache]

1
go.mod
View File

@ -16,6 +16,7 @@ require (
github.com/spf13/viper v1.7.0
github.com/stretchr/testify v1.6.0
gitlab.com/tslocum/cview v1.4.8-0.20200614211415-f477be8ba472
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 // indirect
golang.org/x/text v0.3.3
gopkg.in/ini.v1 v1.57.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200603094226-e3079894b1e8 // indirect

2
go.sum
View File

@ -275,6 +275,8 @@ golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200610111108-226ff32320da h1:bGb80FudwxpeucJUjPYJXuJ8Hk91vNtfvrymzwiei38=
golang.org/x/sys v0.0.0-20200610111108-226ff32320da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80=
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=

View File

@ -115,40 +115,58 @@ func convertRegularGemini(s string, numLinks, width int) (string, []string) {
links = append(links, url)
// Wrap and add link text
// Wrap the link text, but add some spaces to indent the wrapped lines past the link number
wrappedLink := wrapLine(linkText, width,
strings.Repeat(" ", len(strconv.Itoa(numLinks+len(links)))+4), // +4 for spaces and brackets
"",
false, // Don't indent the first line, it's the one with link number
)
// Set the style tags
// Add them to the first line
var wrappedLink []string
if viper.GetBool("a-general.color") {
pU, err := urlPkg.Parse(url)
if err == nil && (pU.Scheme == "" || pU.Scheme == "gemini" || pU.Scheme == "about") {
// A gemini link
// Add the link text in blue (in a region), and a gray link number to the left of it
wrappedLink = wrapLine(linkText, width,
strings.Repeat(" ", len(strconv.Itoa(numLinks+len(links)))+4)+ // +4 for spaces and brackets
`["`+strconv.Itoa(numLinks+len(links)-1)+`"][dodgerblue]`,
`[-][""]`,
false, // Don't indent the first line, it's the one with link number
)
// Add special stuff to first line, like the link number
wrappedLink[0] = `[silver::b][` + strconv.Itoa(numLinks+len(links)) + "[]" + "[-::-] " +
`[dodgerblue]["` + strconv.Itoa(numLinks+len(links)-1) + `"]` +
wrappedLink[0]
`["` + strconv.Itoa(numLinks+len(links)-1) + `"][dodgerblue]` +
wrappedLink[0] + `[-][""]`
} else {
// Not a gemini link, use purple instead
wrappedLink = wrapLine(linkText, width,
strings.Repeat(" ", len(strconv.Itoa(numLinks+len(links)))+4)+ // +4 for spaces and brackets
`["`+strconv.Itoa(numLinks+len(links)-1)+`"][#8700d7]`,
`[-][""]`,
false, // Don't indent the first line, it's the one with link number
)
wrappedLink[0] = `[silver::b][` + strconv.Itoa(numLinks+len(links)) + "[]" + "[-::-] " +
`[#8700d7]["` + strconv.Itoa(numLinks+len(links)-1) + `"]` +
wrappedLink[0]
`["` + strconv.Itoa(numLinks+len(links)-1) + `"][#8700d7]` +
wrappedLink[0] + `[-][""]`
}
} else {
// No colours allowed
wrappedLink = wrapLine(linkText, width,
strings.Repeat(" ", len(strconv.Itoa(numLinks+len(links)))+4)+ // +4 for spaces and brackets
`["`+strconv.Itoa(numLinks+len(links)-1)+`"]`,
`[""]`,
false, // Don't indent the first line, it's the one with link number
)
wrappedLink[0] = `[::b][` + strconv.Itoa(numLinks+len(links)) + "[][::-] " +
`["` + strconv.Itoa(numLinks+len(links)-1) + `"]` +
wrappedLink[0]
wrappedLink[0] + `[""]`
}
wrappedLink[len(wrappedLink)-1] += `[""][-]` // Close region and formatting at the end
wrappedLines = append(wrappedLines, wrappedLink...)
// Lists