diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-06-24 23:40:18 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-06-24 23:40:18 +0800 |
commit | 1ce40d7581bac2b776d1e47ec49c03c0fcc7fdc1 (patch) | |
tree | f7b957645b11bc19ecf7fb29baaa13530557af7a /Godeps/_workspace/src/github.com/gizak/termui/p.go | |
parent | 92ef33d97a437dce2d7b55f06342de388d95f575 (diff) | |
download | go-tangerine-1ce40d7581bac2b776d1e47ec49c03c0fcc7fdc1.tar go-tangerine-1ce40d7581bac2b776d1e47ec49c03c0fcc7fdc1.tar.gz go-tangerine-1ce40d7581bac2b776d1e47ec49c03c0fcc7fdc1.tar.bz2 go-tangerine-1ce40d7581bac2b776d1e47ec49c03c0fcc7fdc1.tar.lz go-tangerine-1ce40d7581bac2b776d1e47ec49c03c0fcc7fdc1.tar.xz go-tangerine-1ce40d7581bac2b776d1e47ec49c03c0fcc7fdc1.tar.zst go-tangerine-1ce40d7581bac2b776d1e47ec49c03c0fcc7fdc1.zip |
Godeps: remove mist remnants, add termui deps
Diffstat (limited to 'Godeps/_workspace/src/github.com/gizak/termui/p.go')
-rw-r--r-- | Godeps/_workspace/src/github.com/gizak/termui/p.go | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/Godeps/_workspace/src/github.com/gizak/termui/p.go b/Godeps/_workspace/src/github.com/gizak/termui/p.go new file mode 100644 index 000000000..e327d7489 --- /dev/null +++ b/Godeps/_workspace/src/github.com/gizak/termui/p.go @@ -0,0 +1,71 @@ +// 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 + +// Par displays a paragraph. +/* + par := termui.NewPar("Simple Text") + par.Height = 3 + par.Width = 17 + par.Border.Label = "Label" +*/ +type Par struct { + Block + Text string + TextFgColor Attribute + TextBgColor Attribute +} + +// NewPar returns a new *Par with given text as its content. +func NewPar(s string) *Par { + return &Par{ + Block: *NewBlock(), + Text: s, + TextFgColor: theme.ParTextFg, + TextBgColor: theme.ParTextBg} +} + +// Buffer implements Bufferer interface. +func (p *Par) Buffer() []Point { + ps := p.Block.Buffer() + + rs := str2runes(p.Text) + i, j, k := 0, 0, 0 + for i < p.innerHeight && k < len(rs) { + // the width of char is about to print + w := charWidth(rs[k]) + + if rs[k] == '\n' || j+w > p.innerWidth { + i++ + j = 0 // set x = 0 + if rs[k] == '\n' { + k++ + } + + if i >= p.innerHeight { + ps = append(ps, newPointWithAttrs('…', + p.innerX+p.innerWidth-1, + p.innerY+p.innerHeight-1, + p.TextFgColor, p.TextBgColor)) + break + } + + continue + } + pi := Point{} + pi.X = p.innerX + j + pi.Y = p.innerY + i + + pi.Ch = rs[k] + pi.Bg = p.TextBgColor + pi.Fg = p.TextFgColor + + ps = append(ps, pi) + + k++ + j += w + } + return p.Block.chopOverflow(ps) +} |