mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-01 22:47:25 -04:00
Correctly word-wrap and pad unicode characters
This commit is contained in:
@@ -6,8 +6,9 @@ require (
|
||||
github.com/alecthomas/chroma v0.7.0
|
||||
github.com/logrusorgru/aurora v0.0.0-20191017060258-dc85c304c434
|
||||
github.com/mattn/go-isatty v0.0.10
|
||||
github.com/mattn/go-runewidth v0.0.7
|
||||
github.com/microcosm-cc/bluemonday v1.0.2
|
||||
github.com/muesli/reflow v0.0.0-20191128051140-93fa6301a46e
|
||||
github.com/muesli/reflow v0.0.0-20191205093112-d357691d258b
|
||||
github.com/olekukonko/tablewriter v0.0.3
|
||||
github.com/rakyll/statik v0.1.6
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
||||
|
||||
@@ -44,6 +44,8 @@ github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW1
|
||||
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
|
||||
github.com/mattn/go-runewidth v0.0.6 h1:V2iyH+aX9C5fsYCpK60U8BYIvmhqxuOL3JZcqc1NB7k=
|
||||
github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
|
||||
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/microcosm-cc/bluemonday v1.0.2 h1:5lPfLTTAvAbtS0VqT+94yOtFnGfUWYyx0+iToC3Os3s=
|
||||
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
@@ -56,6 +58,8 @@ github.com/muesli/reflow v0.0.0-20191128045928-968b9b2020ad h1:jyfh8KHPivRKjfqin
|
||||
github.com/muesli/reflow v0.0.0-20191128045928-968b9b2020ad/go.mod h1:ElDHwEb2eq5uzeCdCvT9KyrqcAfLcQg7VCL7r7JXdcc=
|
||||
github.com/muesli/reflow v0.0.0-20191128051140-93fa6301a46e h1:9UdJp/6YtIpyJZISKQJ9YNIDN9eB4yUo49oARFxtzDw=
|
||||
github.com/muesli/reflow v0.0.0-20191128051140-93fa6301a46e/go.mod h1:ElDHwEb2eq5uzeCdCvT9KyrqcAfLcQg7VCL7r7JXdcc=
|
||||
github.com/muesli/reflow v0.0.0-20191205093112-d357691d258b h1:7iJQNEN0GksbYNXZKyaa6zdMIvX89wAeHJ9EnKRFgZg=
|
||||
github.com/muesli/reflow v0.0.0-20191205093112-d357691d258b/go.mod h1:I9bWAt7QTg/que/qmUCJBGlj7wEq8OAFBjPNjc6xK4I=
|
||||
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
|
||||
github.com/olekukonko/tablewriter v0.0.3 h1:i0LBnzgiChAWHJYTQAZJDOgf8MNxAVYZJ2m63SIDimI=
|
||||
github.com/olekukonko/tablewriter v0.0.3/go.mod h1:YZeBtGzYYEsCHp2LST/u/0NDwGkRoBtmn1cIWCJiS6M=
|
||||
|
||||
+5
-5
@@ -2,6 +2,8 @@ package gold
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/mattn/go-runewidth"
|
||||
)
|
||||
|
||||
type PaddingFunc = func(w io.Writer)
|
||||
@@ -25,9 +27,10 @@ func (w *PaddingWriter) Write(b []byte) (int, error) {
|
||||
if (c >= 0x41 && c <= 0x5a) || (c >= 0x61 && c <= 0x7a) {
|
||||
// ANSI sequence terminated
|
||||
w.ansi = false
|
||||
w.lineLen--
|
||||
}
|
||||
} else {
|
||||
w.lineLen += runewidth.StringWidth(string(c))
|
||||
|
||||
if c == '\n' {
|
||||
// end of current line
|
||||
if w.Padding > 0 && uint(w.lineLen) < w.Padding {
|
||||
@@ -36,13 +39,10 @@ func (w *PaddingWriter) Write(b []byte) (int, error) {
|
||||
}
|
||||
}
|
||||
w.Forward.ResetAnsi()
|
||||
w.lineLen = -1
|
||||
w.lineLen = 0
|
||||
}
|
||||
}
|
||||
|
||||
if !w.ansi {
|
||||
w.lineLen++
|
||||
}
|
||||
_, err := w.Forward.Write([]byte(string(c)))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
Reference in New Issue
Block a user