mirror of
https://github.com/br0xen/termbox-screen.git
synced 2024-11-22 05:33:13 +00:00
Init termbox when creating a new manager
So 'Initialize' functions on first screen can access termbox
This commit is contained in:
parent
a1b5bf3c81
commit
9bfd6c5c60
15
screen.go
15
screen.go
@ -2,6 +2,8 @@ package termboxScreen
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -43,6 +45,11 @@ func NewManager() *Manager {
|
|||||||
screens: make(map[int]Screen),
|
screens: make(map[int]Screen),
|
||||||
refreshRate: NoRefresh,
|
refreshRate: NoRefresh,
|
||||||
}
|
}
|
||||||
|
if err := termbox.Init(); err != nil {
|
||||||
|
fmt.Println("Error initializing termbox")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
termbox.SetOutputMode(termbox.Output256)
|
||||||
return &m
|
return &m
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,11 +94,7 @@ func (m *Manager) Loop() error {
|
|||||||
if len(m.screens) == 0 {
|
if len(m.screens) == 0 {
|
||||||
return errors.New("Loop cannot run without screens")
|
return errors.New("Loop cannot run without screens")
|
||||||
}
|
}
|
||||||
if err := termbox.Init(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
m.running = true
|
m.running = true
|
||||||
termbox.SetOutputMode(termbox.Output256)
|
|
||||||
go m.pollUserEvents()
|
go m.pollUserEvents()
|
||||||
// We always start display the first screen added
|
// We always start display the first screen added
|
||||||
m.layoutAndDrawScreen()
|
m.layoutAndDrawScreen()
|
||||||
@ -127,6 +130,7 @@ func (m *Manager) Loop() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.running = false
|
m.running = false
|
||||||
|
close(m.events)
|
||||||
termbox.Close()
|
termbox.Close()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -151,8 +155,9 @@ func (m *Manager) SetRefreshRate(t time.Duration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) pollRefreshEvents() {
|
func (m *Manager) pollRefreshEvents() {
|
||||||
if m.refreshRate > 0 {
|
if m.refreshRate > time.Microsecond {
|
||||||
for m.running {
|
for m.running {
|
||||||
|
ioutil.WriteFile("./log", []byte(time.Now().Format(time.RFC3339)), 0644)
|
||||||
time.Sleep(m.refreshRate)
|
time.Sleep(m.refreshRate)
|
||||||
m.SendNoneEvent()
|
m.SendNoneEvent()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user