mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
edit: Export most funcs in wcwidth.go
This commit is contained in:
parent
bbca89f4c9
commit
c9686c85be
|
@ -63,7 +63,7 @@ func isCombining(r rune) bool {
|
|||
return i < n && r >= combining[i][0]
|
||||
}
|
||||
|
||||
func wcwidth(r rune) int {
|
||||
func WcWidth(r rune) int {
|
||||
switch {
|
||||
case r == 0:
|
||||
return 0
|
||||
|
@ -91,17 +91,17 @@ func wcwidth(r rune) int {
|
|||
return 1
|
||||
}
|
||||
|
||||
func wcwidths(s string) (w int) {
|
||||
func WcWidths(s string) (w int) {
|
||||
for _, r := range s {
|
||||
w += wcwidth(r)
|
||||
w += WcWidth(r)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func trimWcwidth(s string, wmax int) string {
|
||||
func TrimWcWidth(s string, wmax int) string {
|
||||
w := 0
|
||||
for i, r := range s {
|
||||
w += wcwidth(r)
|
||||
w += WcWidth(r)
|
||||
if w > wmax {
|
||||
return s[:i]
|
||||
}
|
||||
|
@ -109,10 +109,10 @@ func trimWcwidth(s string, wmax int) string {
|
|||
return s
|
||||
}
|
||||
|
||||
func forceWcwidth(s string, width int) string {
|
||||
func ForceWcWidth(s string, width int) string {
|
||||
w := 0
|
||||
for i, r := range s {
|
||||
w0 := wcwidth(r)
|
||||
w0 := WcWidth(r)
|
||||
w += w0
|
||||
if w > width {
|
||||
w -= w0
|
||||
|
|
|
@ -17,7 +17,7 @@ var wcwidthTests = []struct {
|
|||
|
||||
func TestWcwidth(t *testing.T) {
|
||||
for _, tt := range wcwidthTests {
|
||||
out := wcwidth(tt.in)
|
||||
out := WcWidth(tt.in)
|
||||
if out != tt.wanted {
|
||||
t.Errorf("wcwidth(%q) => %v, want %v", tt.in, out, tt.wanted)
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ func (b *buffer) write(r rune, attr string) {
|
|||
// BUG(xiaq): buffer.write drops unprintable runes silently
|
||||
return
|
||||
}
|
||||
wd := wcwidth(r)
|
||||
wd := WcWidth(r)
|
||||
c := cell{r, byte(wd), attr}
|
||||
|
||||
if b.col+wd > b.width {
|
||||
|
@ -318,10 +318,10 @@ func renderNavColumn(nc *navColumn, w, h int) *buffer {
|
|||
if w >= navigationListingMinWidthForPadding {
|
||||
padding := navigationListingColPadding
|
||||
b.writePadding(padding, attr)
|
||||
b.writes(forceWcwidth(text, w-2), attr)
|
||||
b.writes(ForceWcWidth(text, w-2), attr)
|
||||
b.writePadding(padding, attr)
|
||||
} else {
|
||||
b.writes(forceWcwidth(text, w), attr)
|
||||
b.writes(ForceWcWidth(text, w), attr)
|
||||
}
|
||||
}
|
||||
return b
|
||||
|
@ -395,7 +395,7 @@ tokens:
|
|||
}
|
||||
|
||||
// Write rprompt
|
||||
padding := b.width - b.col - wcwidths(bs.rprompt)
|
||||
padding := b.width - b.col - WcWidths(bs.rprompt)
|
||||
if padding >= 1 {
|
||||
b.newlineWhenFull = false
|
||||
b.writePadding(padding, "")
|
||||
|
@ -417,7 +417,7 @@ tokens:
|
|||
case modeHistory:
|
||||
text = fmt.Sprintf("History #%d", bs.history.current)
|
||||
}
|
||||
b.writes(trimWcwidth(text, width), attrForMode)
|
||||
b.writes(TrimWcWidth(text, width), attrForMode)
|
||||
}
|
||||
|
||||
// bufTips
|
||||
|
@ -425,7 +425,7 @@ tokens:
|
|||
if len(bs.tips) > 0 {
|
||||
b := newBuffer(width)
|
||||
bufTips = b
|
||||
b.writes(trimWcwidth(strings.Join(bs.tips, ", "), width), attrForTip)
|
||||
b.writes(TrimWcWidth(strings.Join(bs.tips, ", "), width), attrForTip)
|
||||
}
|
||||
|
||||
hListing := 0
|
||||
|
@ -459,7 +459,7 @@ tokens:
|
|||
colWidth := 0
|
||||
margin := completionListingColMargin
|
||||
for _, cand := range cands {
|
||||
width := wcwidths(cand.text)
|
||||
width := WcWidths(cand.text)
|
||||
if colWidth < width {
|
||||
colWidth = width
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ tokens:
|
|||
attr += attrForCurrentCompletion
|
||||
}
|
||||
text := cands[k].text
|
||||
b.writes(forceWcwidth(text, colWidth), attr)
|
||||
b.writes(ForceWcWidth(text, colWidth), attr)
|
||||
b.writePadding(margin, "")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user