forked from cerc-io/plugeth
289b30715d
This commit converts the dependency management from Godeps to the vendor folder, also switching the tool from godep to trash. Since the upstream tool lacks a few features proposed via a few PRs, until those PRs are merged in (if), use github.com/karalabe/trash. You can update dependencies via trash --update. All dependencies have been updated to their latest version. Parts of the build system are reworked to drop old notions of Godeps and invocation of the go vet command so that it doesn't run against the vendor folder, as that will just blow up during vetting. The conversion drops OpenCL (and hence GPU mining support) from ethash and our codebase. The short reasoning is that there's noone to maintain and having opencl libs in our deps messes up builds as go install ./... tries to build them, failing with unsatisfied link errors for the C OpenCL deps. golang.org/x/net/context is not vendored in. We expect it to be fetched by the user (i.e. using go get). To keep ci.go builds reproducible the package is "vendored" in build/_vendor.
136 lines
2.7 KiB
Go
136 lines
2.7 KiB
Go
// Copyright 2016 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 (
|
|
"image"
|
|
"sync"
|
|
"time"
|
|
|
|
tm "github.com/nsf/termbox-go"
|
|
)
|
|
|
|
// Bufferer should be implemented by all renderable components.
|
|
type Bufferer interface {
|
|
Buffer() Buffer
|
|
}
|
|
|
|
// 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 {
|
|
if err := tm.Init(); err != nil {
|
|
return err
|
|
}
|
|
|
|
sysEvtChs = make([]chan Event, 0)
|
|
go hookTermboxEvt()
|
|
|
|
renderJobs = make(chan []Bufferer)
|
|
//renderLock = new(sync.RWMutex)
|
|
|
|
Body = NewGrid()
|
|
Body.X = 0
|
|
Body.Y = 0
|
|
Body.BgColor = ThemeAttr("bg")
|
|
Body.Width = TermWidth()
|
|
|
|
DefaultEvtStream.Init()
|
|
DefaultEvtStream.Merge("termbox", NewSysEvtCh())
|
|
DefaultEvtStream.Merge("timer", NewTimerCh(time.Second))
|
|
DefaultEvtStream.Merge("custom", usrEvtCh)
|
|
|
|
DefaultEvtStream.Handle("/", DefualtHandler)
|
|
DefaultEvtStream.Handle("/sys/wnd/resize", func(e Event) {
|
|
w := e.Data.(EvtWnd)
|
|
Body.Width = w.Width
|
|
})
|
|
|
|
DefaultWgtMgr = NewWgtMgr()
|
|
DefaultEvtStream.Hook(DefaultWgtMgr.WgtHandlersHook())
|
|
|
|
go func() {
|
|
for bs := range renderJobs {
|
|
render(bs...)
|
|
}
|
|
}()
|
|
|
|
return nil
|
|
}
|
|
|
|
// Close finalizes termui library,
|
|
// should be called after successful initialization when termui's functionality isn't required anymore.
|
|
func Close() {
|
|
tm.Close()
|
|
}
|
|
|
|
var renderLock sync.Mutex
|
|
|
|
func termSync() {
|
|
renderLock.Lock()
|
|
tm.Sync()
|
|
termWidth, termHeight = tm.Size()
|
|
renderLock.Unlock()
|
|
}
|
|
|
|
// TermWidth returns the current terminal's width.
|
|
func TermWidth() int {
|
|
termSync()
|
|
return termWidth
|
|
}
|
|
|
|
// TermHeight returns the current terminal's height.
|
|
func TermHeight() int {
|
|
termSync()
|
|
return termHeight
|
|
}
|
|
|
|
// Render renders all Bufferer in the given order from left to right,
|
|
// right could overlap on left ones.
|
|
func render(bs ...Bufferer) {
|
|
|
|
for _, b := range bs {
|
|
|
|
buf := b.Buffer()
|
|
// set cels in buf
|
|
for p, c := range buf.CellMap {
|
|
if p.In(buf.Area) {
|
|
|
|
tm.SetCell(p.X, p.Y, c.Ch, toTmAttr(c.Fg), toTmAttr(c.Bg))
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
renderLock.Lock()
|
|
// render
|
|
tm.Flush()
|
|
renderLock.Unlock()
|
|
}
|
|
|
|
func Clear() {
|
|
tm.Clear(tm.ColorDefault, toTmAttr(ThemeAttr("bg")))
|
|
}
|
|
|
|
func clearArea(r image.Rectangle, bg Attribute) {
|
|
for i := r.Min.X; i < r.Max.X; i++ {
|
|
for j := r.Min.Y; j < r.Max.Y; j++ {
|
|
tm.SetCell(i, j, ' ', tm.ColorDefault, toTmAttr(bg))
|
|
}
|
|
}
|
|
}
|
|
|
|
func ClearArea(r image.Rectangle, bg Attribute) {
|
|
clearArea(r, bg)
|
|
tm.Flush()
|
|
}
|
|
|
|
var renderJobs chan []Bufferer
|
|
|
|
func Render(bs ...Bufferer) {
|
|
//go func() { renderJobs <- bs }()
|
|
renderJobs <- bs
|
|
}
|