本文整理匯總了Golang中github.com/nsf/termbox-go.Clear函數的典型用法代碼示例。如果您正苦於以下問題:Golang Clear函數的具體用法?Golang Clear怎麽用?Golang Clear使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Clear函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Repaint
func (w *Window) Repaint() error {
w.Lock()
err := termbox.Clear(w.Fg, w.Bg)
width, height := termbox.Size()
if err != nil {
return err
}
for _, row := range w.Widgets[w.scrollPos:] {
j := 0
for _, c := range row.Text {
termbox.SetCell(w.x, w.y, rune(c), row.Fg[j], row.Bg[j])
j++
if w.x += 1; w.x > width {
break
}
}
w.x = 0
if w.y += 1; w.y > height {
break
}
}
w.y = 0
w.x = 0
w.Unlock()
return nil
}
示例2: Run
func (f *Form) Run() error {
draw := func() bool {
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
f.DrawInto(&box.TermBox{}, 0, 0)
termbox.Flush()
return true
}
err := termbox.Init()
defer termbox.Close()
if err != nil {
return err
}
if draw() {
f.running = true
for f.running {
ev := termbox.PollEvent()
if !f.HandleEvent(&ev) {
f.running = false
}
draw()
}
} else {
return errors.New("fail sadness")
}
return nil
}
示例3: main
func main() {
err := tb.Init()
if err != nil {
panic(err)
}
defer tb.Close()
tb.SetInputMode(tb.InputEsc)
tb.Clear(tb.ColorCyan, tb.ColorBlue)
tb.Flush()
loop:
for i := 0; ; i++ {
ev := tb.PollEvent()
switch ev.Type {
case tb.EventKey:
if ev.Key == tb.KeyCtrlC {
break loop
}
tb.SetCell(i, i, ev.Ch, tb.ColorGreen, tb.ColorBlack)
tb.Flush()
case tb.EventError:
panic(ev.Err)
}
}
}
示例4: draw
func draw() bool {
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
dots := NewCellsBox([]termbox.Cell{dot, dot, dot, dot, dot,
dot, dot, dot, dot, dot,
dot, dot, dot, dot, dot,
dot, dot, dot, dot, dot,
}, 5)
greenPlus := NewCellsBox([]termbox.Cell{greenPlus, greenPlus, greenPlus, greenPlus}, 2)
if err := greenPlus.DrawInto(dots, 1, 2); err != nil {
termbox.Close()
fmt.Fprintf(os.Stderr, "%v1\r\n", err)
return false
}
if err := dots.DrawInto(&TermBox{}, 0, 0); err != nil {
termbox.Close()
fmt.Fprintf(os.Stderr, "%v2\r\n", err)
return false
}
termbox.SetCell(0, 0, '+', termbox.ColorRed, termbox.ColorDefault)
termbox.SetCell(1, 0, '+', termbox.ColorRed, termbox.ColorDefault)
termbox.SetCell(7, 0, '+', termbox.ColorRed, termbox.ColorDefault)
termbox.Flush()
return true
}
示例5: Run
func (s *Session) Run() error {
s.mode = &ModeEdit{}
data, err := ioutil.ReadFile(s.File)
if err != nil {
return err
}
s.Buf = util.NewBuffer(data)
s.W, s.H = termbox.Size()
s.H--
s.View.SetBuf(s.Buf)
s.View.SetSize(s.W, s.H)
s.View.SetTabwidth(s.Tabwidth)
for {
s.Draw()
termbox.Flush()
termbox.Clear(0, 0)
ev := termbox.PollEvent()
switch ev.Type {
case termbox.EventKey:
s.mode, err = s.mode.HandleKey(s, ev)
if err != nil {
return err
}
case termbox.EventResize:
s.W, s.H = ev.Width, ev.Height-1
s.View.SetSize(s.W, s.H)
case termbox.EventMouse:
case termbox.EventError:
return ev.Err
}
}
}
示例6: main
/* A multiplayer rogue-like in the spirit of TOAG, but implemented in termbox-go */
func main() {
//flag.Parse()
/* start network handling and channels */
max_dimensions := 80 * 24
screen := make([]nr.Sprite, max_dimensions)
world := loadWorld()
/* initialize termbox interface */
err := tb.Init()
check(err)
tb.SetInputMode(tb.InputAlt)
w, h := tb.Size()
tb.Clear(tb.ColorBlack, tb.ColorBlack)
tb.Flush()
go draw(w, h)
for run := true; run == true; {
switch ev := tb.PollEvent(); ev.Type {
case tb.EventKey:
//key := ev.Ch
if ev.Key == tb.KeyCtrlQ {
tb.Flush()
run = false
}
default:
}
}
}
示例7: clear
func clear(fg, bg termbox.Attribute) error {
mutex.Lock()
err := termbox.Clear(fg, bg)
mutex.Unlock()
updateRootBuffer()
return err
}
示例8: RefreshScreen
// Repaints everything on the screen
func RefreshScreen() {
term.Clear(ColorWhite, ColorBlack)
for _, wnd := range comp.windows {
wnd.Draw()
}
term.Flush()
}
示例9: Render
// 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()
}
示例10: drawDrumMachine
func drawDrumMachine() {
tb.Clear(tb.ColorDefault, tb.ColorDefault)
term.ofs.seq = drawHeader()
if term.mode == newModePickSample || term.mode == newModeEnterName {
term.ofs.trk = drawSamples()
} else {
term.ofs.trk = drawSequences()
drawSections()
}
tb.Flush()
}
示例11: WaitEvent
func (tb termboxImpl) WaitEvent() bool {
switch ev := tb.proxy(); ev.Type { // PollEvent will be blocked
case termbox.EventKey:
if ev.Key == termbox.KeyEsc {
return true
}
case termbox.EventResize:
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
case termbox.EventError:
panic(ev.Err)
}
return false
}
示例12: main
func main() {
termbox.Init()
defer termbox.Close()
et, err := gaze.AnyEyeTracker()
if err != nil {
log.Println(err)
return
}
et.Connect()
defer et.Close()
termbox.Clear(0, termbox.ColorWhite) //Set bg to white.
et.StartTracking(func(data *gaze.GazeData) {
ts := data.TrackingStatus()
if ts >= gaze.BothEyesTracked && ts != gaze.OneEyeTrackedUnknownWhich {
termbox.Clear(0, termbox.ColorWhite)
drawPoint(*data.Left().GazePointOnDisplay(), leftMarker)
drawPoint(*data.Right().GazePointOnDisplay(), rightMarker)
termbox.Flush()
}
})
done := make(chan struct{})
go func() {
for {
event := termbox.PollEvent()
if event.Type == termbox.EventKey && event.Key == termbox.KeyEsc {
close(done)
}
}
}()
<-done
}
示例13: calibratePoint
func calibratePoint(et gaze.EyeTracker, x, y float64) {
termbox.Clear(0, 0)
sizeX, sizeY := termbox.Size()
dx, dy := int(float64(sizeX)*x), int(float64(sizeY)*y)
termbox.CellBuffer()[sizeX*dy+dx] = termbox.Cell{'#', marker, termbox.ColorDefault}
termbox.Flush()
//log.Printf("Termbox Size: (%d, %d)", sizeX, sizeY)
log.Printf("Calibrating (%.3f, %.3f)", x, y)
done := make(chan struct{})
time.Sleep(1 * time.Second) //Minimum time. Gives user time to react.
et.AddPointToCalibration(gaze.NewPoint2D(x, y), func(err error) {
close(done) //Synchronizing async call.
})
<-done
}
示例14: Display
// Display the baord
// b1 our board = b2 their board
func Display(b1, b2 TheirBoard, writer io.Writer) {
fmt.Println("Display")
// Clear the terminal
termbox.Clear(termbox.ColorWhite, termbox.ColorBlack)
xStart := 10
yStart := 10
print_tb(5, 5, "Battle Ships", termbox.ColorMagenta, termbox.ColorWhite)
printBoard(b1, xStart, yStart)
printBoard(b2, xStart+30, yStart)
}
示例15: Draw
func (this *Game) Draw() {
tb.Clear(tb.ColorDefault, tb.ColorDefault)
this.ForEachActivePanel(func(p *Panel) {
p.Clear()
p.DrawBorder()
})
x, y := this.Player.Position()
this.ViewPanel.Screen.SetCell(x, y, '@', tb.ColorWhite, tb.ColorBlack)
this.ForEachActivePanel(func(p *Panel) {
p.Blit()
})
tb.Flush()
}