aboutsummaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/gizak/termui/helper.go
blob: 80d8a027883a1d4ce6b3ddeafe359c1a0393fc5a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2015 Zack Guo <gizak@icloud.com>. All rights reserved.
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.

package termui

import tm "github.com/nsf/termbox-go"
import rw "github.com/mattn/go-runewidth"

/* ---------------Port from termbox-go --------------------- */

// Attribute is printable cell's color and style.
type Attribute uint16

const (
    ColorDefault Attribute = iota
    ColorBlack
    ColorRed
    ColorGreen
    ColorYellow
    ColorBlue
    ColorMagenta
    ColorCyan
    ColorWhite
)

const NumberofColors = 8 //Have a constant that defines number of colors
const (
    AttrBold Attribute = 1 << (iota + 9)
    AttrUnderline
    AttrReverse
)

var (
    dot  = "…"
    dotw = rw.StringWidth(dot)
)

/* ----------------------- End ----------------------------- */

func toTmAttr(x Attribute) tm.Attribute {
    return tm.Attribute(x)
}

func str2runes(s string) []rune {
    return []rune(s)
}

func trimStr2Runes(s string, w int) []rune {
    if w <= 0 {
        return []rune{}
    }
    sw := rw.StringWidth(s)
    if sw > w {
        return []rune(rw.Truncate(s, w, dot))
    }
    return str2runes(s) //[]rune(rw.Truncate(s, w, ""))
}

func strWidth(s string) int {
    return rw.StringWidth(s)
}

func charWidth(ch rune) int {
    return rw.RuneWidth(ch)
}