From 034b4c019d45299078a9c3c2a06dda2d912fa02b Mon Sep 17 00:00:00 2001 From: makeworld Date: Wed, 22 Dec 2021 20:36:12 -0500 Subject: [PATCH] Center text, fixes #233 --- CHANGELOG.md | 4 ++++ config/config.go | 3 +-- config/default.go | 5 +---- default-config.toml | 5 +---- display/thanks.go | 1 + display/util.go | 19 ++++++++++++------- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 915fbdbe..86d634be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Syntax highlighting for preformatted text blocks with alt text (#252, #263, [wiki page](https://github.com/makeworld-the-better-one/amfora/wiki/Source-Code-Highlighting)) +### Changed +- Center text automatically, removing `left_margin` from the config (#233) +- `max_width` defaults to 80 columns instead of 100 (#233) + ### Fixed - Modal can't be closed when opening non-gemini text URLs from the commandline (#283, #284) - External programs started by Amfora remain as zombie processes (#219) diff --git a/config/config.go b/config/config.go index 6c4bf1be..bcd23bc3 100644 --- a/config/config.go +++ b/config/config.go @@ -200,8 +200,7 @@ func Init() error { viper.SetDefault("a-general.highlight_style", "monokai") viper.SetDefault("a-general.bullets", true) viper.SetDefault("a-general.show_link", false) - viper.SetDefault("a-general.left_margin", 0.15) - viper.SetDefault("a-general.max_width", 100) + viper.SetDefault("a-general.max_width", 80) viper.SetDefault("a-general.downloads", "") viper.SetDefault("a-general.temp_downloads", "") viper.SetDefault("a-general.page_max_size", 2097152) diff --git a/config/default.go b/config/default.go index 82a7b3ee..09b5099e 100644 --- a/config/default.go +++ b/config/default.go @@ -70,11 +70,8 @@ bullets = true # Whether to show link after link text show_link = false -# A number from 0 to 1, indicating what percentage of the terminal width the left margin should take up. -left_margin = 0.15 - # The max number of columns to wrap a page's text to. Preformatted blocks are not wrapped. -max_width = 100 +max_width = 80 # 'downloads' is the path to a downloads folder. # An empty value means the code will find the default downloads folder for your system. diff --git a/default-config.toml b/default-config.toml index 7e034ed9..7c426856 100644 --- a/default-config.toml +++ b/default-config.toml @@ -67,11 +67,8 @@ bullets = true # Whether to show link after link text show_link = false -# A number from 0 to 1, indicating what percentage of the terminal width the left margin should take up. -left_margin = 0.15 - # The max number of columns to wrap a page's text to. Preformatted blocks are not wrapped. -max_width = 100 +max_width = 80 # 'downloads' is the path to a downloads folder. # An empty value means the code will find the default downloads folder for your system. diff --git a/display/thanks.go b/display/thanks.go index d26a2fcf..72ee3bf0 100644 --- a/display/thanks.go +++ b/display/thanks.go @@ -29,4 +29,5 @@ Thank you to the following contributors, who have helped make Amfora great. FOSS * Michael McDonagh (@m-mcdonagh) * mooff (@awfulcooking) * Josias (@justjosias) +* mntn (@mntn-xyz) `) diff --git a/display/util.go b/display/util.go index f91f2a84..d789ea96 100644 --- a/display/util.go +++ b/display/util.go @@ -63,7 +63,14 @@ func isValidTab(t *tab) bool { } func leftMargin() int { - return int(float64(termW) * viper.GetFloat64("a-general.left_margin")) + // Return the left margin size that centers the text, assuming it's the max width + // https://github.com/makeworld-the-better-one/amfora/issues/233 + + lm := (termW - viper.GetInt("a-general.max_width")) / 2 + if lm < 0 { + return 0 + } + return lm } func textWidth() int { @@ -73,13 +80,11 @@ func textWidth() int { return viper.GetInt("a-general.max_width") } - rightMargin := leftMargin() - if leftMargin() > 10 { - // 10 is the max right margin - rightMargin = 10 - } + // Subtract left and right margin from total width to get text width + // Left and right margin are equal because text is automatically centered, see: + // https://github.com/makeworld-the-better-one/amfora/issues/233 - max := termW - leftMargin() - rightMargin + max := termW - leftMargin()*2 if max < viper.GetInt("a-general.max_width") { return max }