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/render.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/render.go')
-rw-r--r-- | Godeps/_workspace/src/github.com/gizak/termui/render.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/Godeps/_workspace/src/github.com/gizak/termui/render.go b/Godeps/_workspace/src/github.com/gizak/termui/render.go new file mode 100644 index 000000000..d697d0aea --- /dev/null +++ b/Godeps/_workspace/src/github.com/gizak/termui/render.go @@ -0,0 +1,60 @@ +// 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" + +// Bufferer should be implemented by all renderable components. +type Bufferer interface { + Buffer() []Point +} + +// Init initializes termui library. This function should be called before any others. +// After initialization, the library must be finalized by 'Close' function. +func Init() error { + Body = NewGrid() + Body.X = 0 + Body.Y = 0 + Body.BgColor = theme.BodyBg + defer func() { + w, _ := tm.Size() + Body.Width = w + evtListen() + }() + return tm.Init() +} + +// Close finalizes termui library, +// should be called after successful initialization when termui's functionality isn't required anymore. +func Close() { + tm.Close() +} + +// TermWidth returns the current terminal's width. +func TermWidth() int { + tm.Sync() + w, _ := tm.Size() + return w +} + +// TermHeight returns the current terminal's height. +func TermHeight() int { + tm.Sync() + _, h := tm.Size() + return h +} + +// Render renders all Bufferer in the given order from left to right, +// right could overlap on left ones. +func Render(rs ...Bufferer) { + tm.Clear(tm.ColorDefault, toTmAttr(theme.BodyBg)) + for _, r := range rs { + buf := r.Buffer() + for _, v := range buf { + tm.SetCell(v.X, v.Y, v.Ch, toTmAttr(v.Fg), toTmAttr(v.Bg)) + } + } + tm.Flush() +} |