Skip to content

Commit

Permalink
♻️ Replace reflow package
Browse files Browse the repository at this point in the history
The `reflow` package is used to word wrap the commit description. This
is necessary to make the text sent to Git match the editor view.
Unicode support was not implemented correctly by this package and would
cause the results to be inconsistent with what was displayed. The
replacement package `ansi` resolves this problem.
  • Loading branch information
mikelorant committed Jun 1, 2024
1 parent 9fdaaec commit be130ef
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/charmbracelet/bubbles v0.18.1-0.20240531002820-296fcf77faad
github.com/charmbracelet/bubbletea v0.26.4
github.com/charmbracelet/lipgloss v0.11.0
github.com/charmbracelet/x/ansi v0.1.2
github.com/creack/pty v1.1.21
github.com/forPelevin/gomoji v1.2.0
github.com/go-git/go-billy/v5 v5.5.0
Expand All @@ -19,7 +20,6 @@ require (
github.com/lithammer/fuzzysearch v1.1.8
github.com/lrstanley/bubbletint v0.0.0-20240125042035-5615d402d4e1
github.com/muesli/gamut v0.3.1
github.com/muesli/reflow v0.3.0
github.com/muesli/termenv v0.15.2
github.com/rivo/uniseg v0.4.7
github.com/spf13/cobra v1.8.0
Expand All @@ -31,7 +31,6 @@ require (

replace (
github.com/ivanpirog/coloredcobra => github.com/mikelorant/coloredcobra v0.0.0-20240413232412-92879003fd8d
github.com/muesli/reflow => github.com/mikelorant/reflow v0.0.0-20240303072837-675d5d5cbae9
github.com/rivo/uniseg => github.com/mikelorant/uniseg v0.0.0-20240303073632-27c86650ffa5
)

Expand All @@ -41,7 +40,6 @@ require (
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/x/ansi v0.1.2 // indirect
github.com/charmbracelet/x/input v0.1.1 // indirect
github.com/charmbracelet/x/term v0.1.1 // indirect
github.com/charmbracelet/x/windows v0.1.2 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZ
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mikelorant/coloredcobra v0.0.0-20240413232412-92879003fd8d h1:+3zyO4WrrTl8PG+a8KVjgKZ9hn+Pzqpu407Ggecy4ME=
github.com/mikelorant/coloredcobra v0.0.0-20240413232412-92879003fd8d/go.mod h1:csDZxFD5oWCy1x8hxXVD4txpYQgo12WOcLS7JON5SVE=
github.com/mikelorant/reflow v0.0.0-20240303072837-675d5d5cbae9 h1:u5GthgoPfZECckPnp+N3c3TBiu21IIuwxOA4y4Wz5cI=
github.com/mikelorant/reflow v0.0.0-20240303072837-675d5d5cbae9/go.mod h1:OpGecHxg1YTnFIDjvHm/t+KGjBEnWkD5JHefBS/lrcU=
github.com/mikelorant/uniseg v0.0.0-20240303073632-27c86650ffa5 h1:CRvVC4vrkEti+XI0DdksOAspVl0/9xG4BLF/bemiKfM=
github.com/mikelorant/uniseg v0.0.0-20240303073632-27c86650ffa5/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
Expand Down
18 changes: 6 additions & 12 deletions internal/ui/body/body.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/charmbracelet/bubbles/textarea"
tea "github.com/charmbracelet/bubbletea"
"github.com/muesli/reflow/wordwrap"
"github.com/charmbracelet/x/ansi"
)

type Model struct {
Expand Down Expand Up @@ -113,19 +113,13 @@ func (m Model) Focused() bool {
}

func (m Model) Value() string {
w := wordwrap.WordWrap{
// Further details for the text reflow issue:
// https://github.com/charmbracelet/bubbles/issues/333
Limit: m.Width - 1,
Breakpoints: []rune{'-'},
Newline: []rune{'\n'},
KeepNewlines: true,
}
// Further details for the text reflow issue:
// https://github.com/charmbracelet/bubbles/issues/333
l := m.Width - 1

w.Write([]byte(m.textArea.Value()))
w.Close()
str := ansi.Wordwrap(m.textArea.Value(), l, "")

return strings.TrimSpace(w.String())
return strings.TrimSpace(str)
}

func (m Model) RawValue() string {
Expand Down

0 comments on commit be130ef

Please sign in to comment.