package window import ( "citrons.xyz/talk/client/buffer" "citrons.xyz/talk/tui" ) type Location interface { CreateWindow() Window } type Window interface { Location() Location Kill() Buffer() *buffer.Buffer Input() *tui.TextInput Send(text string) ShowStatusLine() } type WindowCache struct { windows map[Location]Window } func NewCache() WindowCache { return WindowCache {make(map[Location]Window)} } func (wc *WindowCache) Open(l Location) Window { if wc.windows[l] == nil { wc.windows[l] = l.CreateWindow() } return wc.windows[l] } func (wc *WindowCache) Evict(l Location) { if wc.windows[l] != nil { wc.windows[l].Kill() } delete(wc.windows, l) } func (wc *WindowCache) Get(l Location) Window { return wc.windows[l] }