Skip to content

Commit

Permalink
wrap at 85 and make this limit configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
NiclasvanEyk committed Oct 17, 2023
1 parent e70d76e commit ca281df
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- `changelog path` as an alias of `changelog find`
- The column at which text wraps can be configured using the `KEEPAC_WRAP_AT` environment variable

### Changed

- The output now wraps after 85 characters

### Fixed

Expand Down
27 changes: 24 additions & 3 deletions internal/changelog/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package changelog
import (
"fmt"
"os"
"strconv"

"github.com/charmbracelet/glamour"
"golang.org/x/term"
Expand Down Expand Up @@ -33,13 +34,33 @@ func Show(contents string) error {

func getWordWrapLimit() int {
current := int(os.Stdin.Fd())
// When wrapping at exatcly 85, the default contents generated
// `changelog init` wrap nicely:
//
// Changelog
//
// All notable changes to this project will be documented in this file.
//
// The format is based on Keep a Changelog https://keepachangelog.com/en/1.0.0/, and
// this project adheres to Semantic Versioning https://semver.org/spec/v2.0.0.html.
//
// Anything less than 85 leads to the links being broken up, which does not
// look very good.
fallback := 85

preferredRaw := os.Getenv("KEEPAC_WRAP_AT")
preferred, err := strconv.Atoi(preferredRaw)
if err != nil {
preferred = fallback
}

width, _, err := term.GetSize(current)
if err != nil {
return 80
return fallback
}

if width > 80 {
return 80
if width > preferred {
return preferred
}

return width
Expand Down

0 comments on commit ca281df

Please sign in to comment.