summaryrefslogtreecommitdiffstats
path: root/src/util/util.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-01-08 01:30:31 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-01-08 02:09:56 +0900
commit1448d631a7c72905f62dbb343a8f231a1c3cc52c (patch)
tree05abfedd2a0777c2640c8259267d3ad855879dfe /src/util/util.go
parentfd137a9e875ba1fd9feed4903e102951f8098c33 (diff)
Add --height option
Diffstat (limited to 'src/util/util.go')
-rw-r--r--src/util/util.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/util/util.go b/src/util/util.go
index 2a1607ce..29e80176 100644
--- a/src/util/util.go
+++ b/src/util/util.go
@@ -6,8 +6,24 @@ import (
"time"
"github.com/junegunn/go-isatty"
+ "github.com/junegunn/go-runewidth"
)
+var _runeWidths = make(map[rune]int)
+
+// RuneWidth returns rune width
+func RuneWidth(r rune, prefixWidth int, tabstop int) int {
+ if r == '\t' {
+ return tabstop - prefixWidth%tabstop
+ } else if w, found := _runeWidths[r]; found {
+ return w
+ } else {
+ w := runewidth.RuneWidth(r)
+ _runeWidths[r] = w
+ return w
+ }
+}
+
// Max returns the largest integer
func Max(first int, second int) int {
if first >= second {