From eabf167bd793be9febbaf3f7f6f4660b2e2d3c5d Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Thu, 19 Aug 2021 16:44:49 -0400 Subject: [PATCH] Use unconditional wrapping to enforce a max width on Glamour output --- go.mod | 1 + go.sum | 2 ++ tui/bubbles/repo/bubble.go | 13 +++++-------- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index c1fa678e1..e3df4931f 100644 --- a/go.mod +++ b/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 ) diff --git a/go.sum b/go.sum index a426c4d7c..4b6b761fc 100644 --- a/go.sum +++ b/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= diff --git a/tui/bubbles/repo/bubble.go b/tui/bubbles/repo/bubble.go index 001a9f48b..12d45464b 100644 --- a/tui/bubbles/repo/bubble.go +++ b/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 }