Skip to content

Commit

Permalink
Use unconditional wrapping to enforce a max width on Glamour output
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed Aug 19, 2021
1 parent 97fab1f commit eabf167
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
github.com/gliderlabs/ssh v0.3.3
github.com/go-git/go-git/v5 v5.4.2
github.com/meowgorithm/babyenv v1.3.0
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.9.0
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ github.com/muesli/reflow v0.1.0/go.mod h1:I9bWAt7QTg/que/qmUCJBGlj7wEq8OAFBjPNjc
github.com/muesli/reflow v0.2.0/go.mod h1:qT22vjVmM9MIUeLgsVYe/Ye7eZlbv9dZjL3dVhUqLX8=
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68 h1:y1p/ycavWjGT9FnmSjdbWUlLGvcxrY0Rw3ATltrxOhk=
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
github.com/muesli/sasquatch v0.0.0-20200811221207-66979d92330a h1:Hw/15RYEOUD6T9UCRkUmNBa33kJkH33Fui6hE4sRLKU=
github.com/muesli/sasquatch v0.0.0-20200811221207-66979d92330a/go.mod h1:+XG0ne5zXWBTSbbe7Z3/RWxaT8PZY6zaZ1dX6KjprYY=
github.com/muesli/termenv v0.7.4/go.mod h1:pZ7qY9l3F7e5xsAOS0zCew2tME+p7bWeBkotCEcIIcc=
Expand Down
13 changes: 5 additions & 8 deletions tui/bubbles/repo/bubble.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/glamour"
"github.com/charmbracelet/lipgloss"
"github.com/muesli/reflow/wordwrap"
"github.com/muesli/reflow/wrap"
)

const glamourMaxWidth = 120
Expand Down Expand Up @@ -124,7 +125,7 @@ func (b *Bubble) templatize(mdt string) (string, error) {

func (b *Bubble) glamourize(md string) (string, error) {
// TODO: read gaps in appropriate style to remove the magic number below.
w := b.width - b.widthMargin - 2
w := b.width - b.widthMargin - 4
if w > glamourMaxWidth {
w = glamourMaxWidth
}
Expand All @@ -142,11 +143,7 @@ func (b *Bubble) glamourize(md string) (string, error) {
}
// Enforce a maximum width for cases when glamour lines run long.
//
// TODO: use Reflow's unconditional wrapping to force-wrap long lines. This
// should utlimately happen as a Glamour option.
//
// See:
// https://github.com/muesli/reflow#unconditional-wrapping
mdt = lipgloss.NewStyle().MaxWidth(w).Render(mdt)
// TODO: This should utlimately be implemented as a Glamour option.
mdt = wrap.String(wordwrap.String((mdt), w), w)
return mdt, nil
}

0 comments on commit eabf167

Please sign in to comment.