Skip to content

Commit 7fe845a

Browse files
authored
Merge pull request #848 from yorukot/develop
Replace mattn/rundwidth with ansi package more robust StringWidth
2 parents c64ada8 + fd5bc0a commit 7fe845a

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

gomod2nix.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ schema = 3
6565
version = "v1.11.5"
6666
hash = "sha256-jN5+2ED+YbIoPIuyJ4Ou5pqJb2w1uNKzp5yTjKY6rEQ="
6767
[mod."github.com/ebitengine/purego"]
68-
version = "v0.8.2"
69-
hash = "sha256-f3Q8KVX+RkHa1EsGF+U8E9MHHOCZ9j2jtMJOTPCZw08="
68+
version = "v0.8.3"
69+
hash = "sha256-JWKkqPOAa3Unq9eZrdyTjL13vZ07DDQh43IcpgCuze4="
7070
[mod."github.com/erikgeiser/coninput"]
7171
version = "v0.0.0-20211004153227-1c3628e74d0f"
7272
hash = "sha256-OWSqN1+IoL73rWXWdbbcahZu8n2al90Y3eT5Z0vgHvU="

src/internal/common/load_config.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"reflect"
1111
"runtime"
1212

13-
"github.com/mattn/go-runewidth"
13+
"github.com/charmbracelet/x/exp/term/ansi"
1414
"github.com/pelletier/go-toml/v2"
1515
"github.com/yorukot/superfile/src/internal/utils"
1616

@@ -46,34 +46,34 @@ func ValidateConfig(c *ConfigType) error {
4646
return errors.New(LoadConfigError("default_sort_type"))
4747
}
4848

49-
if runewidth.StringWidth(c.BorderTop) != 1 {
49+
if ansi.StringWidth(c.BorderTop) != 1 {
5050
return errors.New(LoadConfigError("border_top"))
5151
}
52-
if runewidth.StringWidth(c.BorderBottom) != 1 {
52+
if ansi.StringWidth(c.BorderBottom) != 1 {
5353
return errors.New(LoadConfigError("border_bottom"))
5454
}
55-
if runewidth.StringWidth(c.BorderLeft) != 1 {
55+
if ansi.StringWidth(c.BorderLeft) != 1 {
5656
return errors.New(LoadConfigError("border_left"))
5757
}
58-
if runewidth.StringWidth(c.BorderRight) != 1 {
58+
if ansi.StringWidth(c.BorderRight) != 1 {
5959
return errors.New(LoadConfigError("border_right"))
6060
}
61-
if runewidth.StringWidth(c.BorderBottomLeft) != 1 {
61+
if ansi.StringWidth(c.BorderBottomLeft) != 1 {
6262
return errors.New(LoadConfigError("border_bottom_left"))
6363
}
64-
if runewidth.StringWidth(c.BorderBottomRight) != 1 {
64+
if ansi.StringWidth(c.BorderBottomRight) != 1 {
6565
return errors.New(LoadConfigError("border_bottom_right"))
6666
}
67-
if runewidth.StringWidth(c.BorderTopLeft) != 1 {
67+
if ansi.StringWidth(c.BorderTopLeft) != 1 {
6868
return errors.New(LoadConfigError("border_top_left"))
6969
}
70-
if runewidth.StringWidth(c.BorderTopRight) != 1 {
70+
if ansi.StringWidth(c.BorderTopRight) != 1 {
7171
return errors.New(LoadConfigError("border_top_right"))
7272
}
73-
if runewidth.StringWidth(c.BorderMiddleLeft) != 1 {
73+
if ansi.StringWidth(c.BorderMiddleLeft) != 1 {
7474
return errors.New(LoadConfigError("border_middle_left"))
7575
}
76-
if runewidth.StringWidth(c.BorderMiddleRight) != 1 {
76+
if ansi.StringWidth(c.BorderMiddleRight) != 1 {
7777
return errors.New(LoadConfigError("border_middle_right"))
7878
}
7979

src/internal/ui/rendering/border.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package rendering
33
import (
44
"strings"
55

6-
"github.com/mattn/go-runewidth"
7-
86
"github.com/charmbracelet/x/exp/term/ansi"
97

108
"github.com/charmbracelet/lipgloss"
@@ -51,7 +49,7 @@ func (b *BorderConfig) AreInfoItemsTruncated() bool {
5149
// border.MiddleLeft <content> border.MiddleRight border.Bottom
5250
availWidth := actualWidth/cnt - 3
5351
for i := range b.infoItems {
54-
if runewidth.StringWidth(b.infoItems[i]) > availWidth {
52+
if ansi.StringWidth(b.infoItems[i]) > availWidth {
5553
return true
5654
}
5755
}
@@ -82,8 +80,8 @@ func (b *BorderConfig) GetBorder(borderStrings lipgloss.Border) lipgloss.Border
8280
titleAvailWidth := actualWidth - 4
8381

8482
// Basic Right truncation
85-
truncatedTitle := runewidth.Truncate(b.title, titleAvailWidth, "")
86-
remainingWidth := actualWidth - 4 - runewidth.StringWidth(truncatedTitle)
83+
truncatedTitle := ansi.Truncate(b.title, titleAvailWidth, "")
84+
remainingWidth := actualWidth - 4 - ansi.StringWidth(truncatedTitle)
8785

8886
margin := ""
8987
if remainingWidth > b.titleLeftMargin {
@@ -104,12 +102,12 @@ func (b *BorderConfig) GetBorder(borderStrings lipgloss.Border) lipgloss.Border
104102
availWidth := actualWidth/cnt - 3
105103
infoText := ""
106104
for _, item := range b.infoItems {
107-
item = runewidth.Truncate(item, availWidth, "")
105+
item = ansi.Truncate(item, availWidth, "")
108106
infoText += borderStrings.MiddleRight + item + borderStrings.MiddleLeft + borderStrings.Bottom
109107
}
110108

111109
// Fill the rest with border char.
112-
remainingWidth := actualWidth - runewidth.StringWidth(infoText)
110+
remainingWidth := actualWidth - ansi.StringWidth(infoText)
113111

114112
res.Bottom = strings.Repeat(borderStrings.Bottom, remainingWidth) + infoText
115113
}

0 commit comments

Comments
 (0)