Truncate long lines in Glamour output to fix layout

Christian Rocha created

In some cases a few characters at the end of very long words like URLs
will now be dropped. This likely needs to be fixed upstream.

Change summary

tui/bubbles/repo/bubble.go | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

Detailed changes

tui/bubbles/repo/bubble.go 🔗

@@ -15,7 +15,6 @@ import (
 	"github.com/charmbracelet/glamour"
 	"github.com/charmbracelet/lipgloss"
 	"github.com/muesli/reflow/truncate"
-	"github.com/muesli/reflow/wordwrap"
 	"github.com/muesli/reflow/wrap"
 )
 
@@ -219,10 +218,15 @@ func (b *Bubble) glamourize(md string) (string, error) {
 	if err != nil {
 		return "", err
 	}
-	// Enforce a maximum width for cases when glamour lines run long.
+	// For now, truncate long lines in Glamour that would otherwise break the
+	// layout when wrapping. This is very likely due to #43 in Reflow, which
+	// has to do with a bug in the way lines longer than the given width are
+	// wrapped.
 	//
-	// TODO: This should utlimately be implemented as a Glamour option.
-	mdt = wrap.String(wordwrap.String((mdt), w), w)
+	//     https://github.com/muesli/reflow/issues/43
+	//
+	// TODO: solve this upstream in Glamour/Reflow.
+	mdt = lipgloss.NewStyle().MaxWidth(w).Render(mdt)
 	return mdt, nil
 }