mirror of
https://github.com/makew0rld/amfora.git
synced 2025-02-02 15:07:34 -05:00
parent
3e27338881
commit
7b27bd02dd
@ -206,6 +206,7 @@ func Init() error {
|
|||||||
viper.SetDefault("a-general.http", "default")
|
viper.SetDefault("a-general.http", "default")
|
||||||
viper.SetDefault("a-general.search", "gus.guru/search")
|
viper.SetDefault("a-general.search", "gus.guru/search")
|
||||||
viper.SetDefault("a-general.color", true)
|
viper.SetDefault("a-general.color", true)
|
||||||
|
viper.SetDefault("a-general.ansi", true)
|
||||||
viper.SetDefault("a-general.bullets", true)
|
viper.SetDefault("a-general.bullets", true)
|
||||||
viper.SetDefault("a-general.left_margin", 0.15)
|
viper.SetDefault("a-general.left_margin", 0.15)
|
||||||
viper.SetDefault("a-general.max_width", 100)
|
viper.SetDefault("a-general.max_width", 100)
|
||||||
|
@ -33,6 +33,9 @@ search = "gemini://gus.guru/search"
|
|||||||
# Whether colors will be used in the terminal
|
# Whether colors will be used in the terminal
|
||||||
color = true
|
color = true
|
||||||
|
|
||||||
|
# Whether ANSI codes from the page content should be rendered
|
||||||
|
ansi = true
|
||||||
|
|
||||||
# Whether to replace list asterisks with unicode bullets
|
# Whether to replace list asterisks with unicode bullets
|
||||||
bullets = true
|
bullets = true
|
||||||
|
|
||||||
|
@ -30,6 +30,9 @@ search = "gemini://gus.guru/search"
|
|||||||
# Whether colors will be used in the terminal
|
# Whether colors will be used in the terminal
|
||||||
color = true
|
color = true
|
||||||
|
|
||||||
|
# Whether ANSI codes from the page content should be rendered
|
||||||
|
ansi = true
|
||||||
|
|
||||||
# Whether to replace list asterisks with unicode bullets
|
# Whether to replace list asterisks with unicode bullets
|
||||||
bullets = true
|
bullets = true
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ package renderer
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
urlPkg "net/url"
|
urlPkg "net/url"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -15,12 +16,17 @@ import (
|
|||||||
"gitlab.com/tslocum/cview"
|
"gitlab.com/tslocum/cview"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Regex for identifying ANSI color codes
|
||||||
|
var ansiRegex = regexp.MustCompile(`\x1b\[[0-9;]*m`)
|
||||||
|
|
||||||
// RenderANSI renders plain text pages containing ANSI codes.
|
// RenderANSI renders plain text pages containing ANSI codes.
|
||||||
// Practically, it is used for the text/x-ansi.
|
// Practically, it is used for the text/x-ansi.
|
||||||
func RenderANSI(s string, leftMargin int) string {
|
func RenderANSI(s string, leftMargin int) string {
|
||||||
s = cview.Escape(s)
|
s = cview.Escape(s)
|
||||||
if viper.GetBool("a-general.color") {
|
if viper.GetBool("a-general.color") && viper.GetBool("a-general.ansi") {
|
||||||
s = cview.TranslateANSI(s)
|
s = cview.TranslateANSI(s)
|
||||||
|
} else {
|
||||||
|
s = ansiRegex.ReplaceAllString(s, "")
|
||||||
}
|
}
|
||||||
var shifted string
|
var shifted string
|
||||||
lines := strings.Split(s, "\n")
|
lines := strings.Split(s, "\n")
|
||||||
@ -277,9 +283,12 @@ func convertRegularGemini(s string, numLinks, width int, proxied bool) (string,
|
|||||||
// If it's not a gemini:// page, set this to true.
|
// If it's not a gemini:// page, set this to true.
|
||||||
func RenderGemini(s string, width, leftMargin int, proxied bool) (string, []string) {
|
func RenderGemini(s string, width, leftMargin int, proxied bool) (string, []string) {
|
||||||
s = cview.Escape(s)
|
s = cview.Escape(s)
|
||||||
if viper.GetBool("a-general.color") {
|
if viper.GetBool("a-general.color") && viper.GetBool("a-general.ansi") {
|
||||||
s = cview.TranslateANSI(s)
|
s = cview.TranslateANSI(s)
|
||||||
|
} else {
|
||||||
|
s = ansiRegex.ReplaceAllString(s, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
lines := strings.Split(s, "\n")
|
lines := strings.Split(s, "\n")
|
||||||
|
|
||||||
links := make([]string, 0)
|
links := make([]string, 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user