Skip to content

Commit

Permalink
Center text, fixes #233
Browse files Browse the repository at this point in the history
  • Loading branch information
makew0rld committed Dec 23, 2021
1 parent 3823a46 commit 034b4c0
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 1 addition & 4 deletions default-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions display/thanks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
`)
19 changes: 12 additions & 7 deletions display/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit 034b4c0

Please sign in to comment.