removing the old test UI codes
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
// Package events defines a simple event handler system
|
||||
package events
|
||||
|
||||
import "sync"
|
||||
|
||||
type Handler func(event any)
|
||||
|
||||
type Bus struct {
|
||||
mu sync.RWMutex
|
||||
handlers map[string][]Handler
|
||||
}
|
||||
|
||||
func NewBus() *Bus {
|
||||
return &Bus{
|
||||
handlers: make(map[string][]Handler),
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Bus) On(eventType any, h Handler) {
|
||||
key := typeKey(eventType)
|
||||
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
|
||||
b.handlers[key] = append(b.handlers[key], h)
|
||||
}
|
||||
|
||||
func (b *Bus) Emit(event any) {
|
||||
key := typeKey(event)
|
||||
|
||||
b.mu.RLock()
|
||||
handlers := append([]Handler{}, b.handlers[key]...)
|
||||
b.mu.RUnlock()
|
||||
|
||||
for _, h := range handlers {
|
||||
h(event)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package events
|
||||
|
||||
import (
|
||||
"esdi/tui/internal/models"
|
||||
)
|
||||
|
||||
type Error struct {
|
||||
Error error
|
||||
}
|
||||
|
||||
type WindowCreated struct {
|
||||
Window models.Window
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package events
|
||||
|
||||
import "fmt"
|
||||
|
||||
func typeKey(v any) string {
|
||||
return fmt.Sprintf("%T", v)
|
||||
}
|
||||
Reference in New Issue
Block a user