Use unconditional wrapping to enforce a max width on Glamour output

Christian Rocha created

Change summary

go.mod                     |  1 +
go.sum                     |  2 ++
tui/bubbles/repo/bubble.go | 13 +++++--------
3 files changed, 8 insertions(+), 8 deletions(-)

Detailed changes

go.mod 🔗

@@ -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
 )

go.sum 🔗

@@ -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=

tui/bubbles/repo/bubble.go 🔗

@@ -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
@@ -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
 	}
@@ -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
 }