ui.go 538 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package ui
  2. import (
  3. "sync"
  4. )
  5. type Command int
  6. const (
  7. QUIT = iota
  8. )
  9. type View interface {
  10. SetUi(*Ui)
  11. }
  12. type Ui struct {
  13. // the model always updates
  14. Updates *Broadcast
  15. // all views put their commands into this channel
  16. Cmds chan Command
  17. // all threads may add themself to this to wait for clean shutdown
  18. Wait *sync.WaitGroup
  19. }
  20. func NewUi(views ...View) *Ui {
  21. ui := &Ui{
  22. Updates: NewBroadcast(),
  23. Cmds: make(chan Command),
  24. Wait: new(sync.WaitGroup),
  25. }
  26. for _, v := range views {
  27. v.SetUi(ui)
  28. }
  29. return ui
  30. }