eabf167bd793be9febbaf3f7f6f4660b2e2d3c5d

Author
Christian Rocha <christian@rocha.is>
Committer
Christian Rocha <christian@rocha.is>
Date

Message

Use unconditional wrapping to enforce a max width on Glamour output

Diff

 1diff --git a/go.mod b/go.mod
 2index c1fa678e1dbe0fca300f4a9e63d03e6b1de9b1fd..e3df4931fcf2e87e71f7faa7fe6749fe695bb689 100644
 3--- a/go.mod
 4+++ b/go.mod
 5@@ -18,6 +18,7 @@ require (
 6 	github.com/gliderlabs/ssh v0.3.3
 7 	github.com/go-git/go-git/v5 v5.4.2
 8 	github.com/meowgorithm/babyenv v1.3.0
 9+	github.com/muesli/reflow v0.3.0 // indirect
10 	github.com/muesli/termenv v0.9.0
11 	golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
12 )
13diff --git a/go.sum b/go.sum
14index a426c4d7cc62ebe634f523789962764f83a9f2ca..4b6b761fc8d4a37b8cd83c86896397ca6f871c18 100644
15--- a/go.sum
16+++ b/go.sum
17@@ -218,6 +218,8 @@ github.com/muesli/reflow v0.1.0/go.mod h1:I9bWAt7QTg/que/qmUCJBGlj7wEq8OAFBjPNjc
18 github.com/muesli/reflow v0.2.0/go.mod h1:qT22vjVmM9MIUeLgsVYe/Ye7eZlbv9dZjL3dVhUqLX8=
19 github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68 h1:y1p/ycavWjGT9FnmSjdbWUlLGvcxrY0Rw3ATltrxOhk=
20 github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=
21+github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
22+github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
23 github.com/muesli/sasquatch v0.0.0-20200811221207-66979d92330a h1:Hw/15RYEOUD6T9UCRkUmNBa33kJkH33Fui6hE4sRLKU=
24 github.com/muesli/sasquatch v0.0.0-20200811221207-66979d92330a/go.mod h1:+XG0ne5zXWBTSbbe7Z3/RWxaT8PZY6zaZ1dX6KjprYY=
25 github.com/muesli/termenv v0.7.4/go.mod h1:pZ7qY9l3F7e5xsAOS0zCew2tME+p7bWeBkotCEcIIcc=
26diff --git a/tui/bubbles/repo/bubble.go b/tui/bubbles/repo/bubble.go
27index 001a9f48b2bbe4ecf2e0d3f2967e1d68f63f5996..12d45464b8e1e83a830805910d41394f00559b32 100644
28--- a/tui/bubbles/repo/bubble.go
29+++ b/tui/bubbles/repo/bubble.go
30@@ -8,7 +8,8 @@ import (
31 	"github.com/charmbracelet/bubbles/viewport"
32 	tea "github.com/charmbracelet/bubbletea"
33 	"github.com/charmbracelet/glamour"
34-	"github.com/charmbracelet/lipgloss"
35+	"github.com/muesli/reflow/wordwrap"
36+	"github.com/muesli/reflow/wrap"
37 )
38 
39 const glamourMaxWidth = 120
40@@ -124,7 +125,7 @@ func (b *Bubble) templatize(mdt string) (string, error) {
41 
42 func (b *Bubble) glamourize(md string) (string, error) {
43 	// TODO: read gaps in appropriate style to remove the magic number below.
44-	w := b.width - b.widthMargin - 2
45+	w := b.width - b.widthMargin - 4
46 	if w > glamourMaxWidth {
47 		w = glamourMaxWidth
48 	}
49@@ -142,11 +143,7 @@ func (b *Bubble) glamourize(md string) (string, error) {
50 	}
51 	// Enforce a maximum width for cases when glamour lines run long.
52 	//
53-	// TODO: use Reflow's unconditional wrapping to force-wrap long lines. This
54-	// should utlimately happen as a Glamour option.
55-	//
56-	// See:
57-	// https://github.com/muesli/reflow#unconditional-wrapping
58-	mdt = lipgloss.NewStyle().MaxWidth(w).Render(mdt)
59+	// TODO: This should utlimately be implemented as a Glamour option.
60+	mdt = wrap.String(wordwrap.String((mdt), w), w)
61 	return mdt, nil
62 }