Skip to content

Commit 89872e5

Browse files
committed
Merge branch 'unicode'
Officially add UTF-8 support go podbit, along with fixes for rune splitting and corrupted text encodings at table edges. Podbit now depends on libncursesw and the ncursesw wrapper for Go. Your system must support POSIX locales in order to use this support correctly. You must also have the wide character version of libncurses installed (-lncursesw).
2 parents b417973 + c341ff3 commit 89872e5

File tree

14 files changed

+46
-37
lines changed

14 files changed

+46
-37
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Podbit runs on Linux and the BSDs.
2222

2323
Podbit is written in Go. So, to build, you will need a copy of the Go command line tool. In addition, you will need:
2424

25-
* *ncurses* development libraries and headers
25+
* *ncurses* development libraries and headers, including wide character support (*libncusesw*)
2626
* A normal install of ``mpv``
2727
* A copy of GNU Make
2828
* Newsboat to enqueue podcasts - *(optional)*

colors/colors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package colors
22

33
import (
4-
"github.com/rthornton128/goncurses"
4+
"github.com/vit1251/go-ncursesw"
55
)
66

77
// Color pair ID definitions.

data/cache.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"time"
1313

1414
"github.com/dhowden/tag"
15-
"github.com/ethanv2/podbit/data/escape"
15+
1616
ev "github.com/ethanv2/podbit/event"
1717
)
1818

@@ -139,9 +139,9 @@ func (c *Cache) loadFile(path string, startup bool) {
139139

140140
ep := Episode{
141141
Queued: !startup,
142-
Title: escape.Escape(data.Title()),
142+
Title: data.Title(),
143143
Date: data.Year(),
144-
Host: escape.Escape(host),
144+
Host: host,
145145
}
146146

147147
c.episodes.Store(path, ep)

data/data.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ func IsURL(check string) bool {
122122
return err == nil && u.Scheme != "" && u.Host != ""
123123
}
124124

125+
// LimitString limits a UTF-8 string to max visible runes, showing the full
126+
// string if it is shorter than max. If max is negative or zero, an empty
127+
// string is returned.
128+
func LimitString(in string, max int) string {
129+
r := []rune(in)
130+
if max <= 0 {
131+
return ""
132+
}
133+
if max > len(r) {
134+
return in
135+
}
136+
137+
return string(r[:max])
138+
}
139+
125140
// FormatTime formats a time measured in seconds.
126141
func FormatTime(seconds float64) string {
127142
round := int(seconds)

data/escape/escape.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
// valid UTF-8.
1414
//
1515
// Data sourced from http://homoglyphs.net/
16+
//
17+
// Deprecated: This library is not for use. You should really just support
18+
// UTF-8 instead.
1619
package escape
1720

1821
// Convertibles are runes which should be converted from the map key to the map

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/blang/mpv v0.0.0-20160810175505-d56d7352e068
77
github.com/dhowden/tag v0.0.0-20201120070457-d52dcb253c63
88
github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b
9-
github.com/rthornton128/goncurses v0.0.0-20210908011339-931b33a34c71
9+
github.com/vit1251/go-ncursesw v0.0.0-20211216195139-e61a3c4242a5
1010
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1
1111
)
1212

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
99
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
1010
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
1111
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
12-
github.com/rthornton128/goncurses v0.0.0-20210908011339-931b33a34c71 h1:1lA/ljJAwqsNo7HHUG7M4XY9dkp6aYnnW5Tglh7bEgA=
13-
github.com/rthornton128/goncurses v0.0.0-20210908011339-931b33a34c71/go.mod h1:AHlKFomPTwmO7H2vL8d7VNrQNQmhMi/DBhDnHRhjbCo=
12+
github.com/vit1251/go-ncursesw v0.0.0-20211216195139-e61a3c4242a5 h1:38QNnaytR3Mhq0YO05IBNMImfFYQB2Tk5Ct/V1MWOwI=
13+
github.com/vit1251/go-ncursesw v0.0.0-20211216195139-e61a3c4242a5/go.mod h1:gTXTX4x80o63QC2qsY+NdlLgj+eiWKMwsY2YMZe6e44=
1414
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1515
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
1616
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/ethanv2/podbit/ui"
1414

1515
"github.com/juju/fslock"
16-
"github.com/rthornton128/goncurses"
16+
"github.com/vit1251/go-ncursesw"
1717
)
1818

1919
const (

ui/components/menu.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package components
22

33
import (
44
"github.com/ethanv2/podbit/colors"
5-
"github.com/rthornton128/goncurses"
5+
"github.com/vit1251/go-ncursesw"
66
)
77

88
// Menu represents a vertical panel menu of cellular entries
@@ -48,14 +48,13 @@ func (m *Menu) Render() {
4848
break
4949
}
5050

51-
var capped string
52-
capped = elem
53-
if len(capped) > m.W {
54-
capped = capped[len(capped)-m.W:]
51+
capped, decode := elem, []rune(elem)
52+
if len(decode) > m.W {
53+
capped = string(decode[len(decode)-m.W:])
5554
capped = "<" + capped
5655
} else {
5756
// Pad out to fill row
58-
for i := len(capped); i <= m.W; i++ {
57+
for i := len(decode); i <= m.W; i++ {
5958
capped += " "
6059
}
6160
}

ui/components/table.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package components
22

33
import (
44
"github.com/ethanv2/podbit/colors"
5+
"github.com/ethanv2/podbit/data"
56

6-
"github.com/rthornton128/goncurses"
7+
"github.com/vit1251/go-ncursesw"
78
)
89

910
// A Column is a vertical section of a table, defined by a
@@ -71,9 +72,7 @@ func (t *Table) Render() {
7172
panic("invalid table header: impossible column width")
7273
}
7374

74-
if len(elem.Label) > colw {
75-
elem.Label = elem.Label[:colw]
76-
}
75+
elem.Label = data.LimitString(elem.Label, colw)
7776

7877
t.Win.AttrOn(goncurses.A_BOLD)
7978
t.Win.MovePrint(t.Y, t.X+off, elem.Label)
@@ -90,13 +89,11 @@ func (t *Table) Render() {
9089
capped := entry[i]
9190
sel := c == t.sel
9291

93-
if len(capped) > colw {
94-
// Trim to fit row
95-
capped = capped[:colw-1]
96-
}
92+
capped = data.LimitString(capped, colw-1)
93+
decode := []rune(capped)
9794

9895
// Pad out to fill row
99-
for i := len(capped); i <= colw && off+len(capped) < t.W; i++ {
96+
for i := len(decode); i < colw && off+len(decode) < t.W; i++ {
10097
capped += " "
10198
}
10299

0 commit comments

Comments
 (0)