package window import ( "citrons.xyz/talk/client/buffer" "citrons.xyz/talk/tui" ) type Location interface { CreateWindow() Window } type Window interface { Prompt Location() Location Kill() Buffer() *buffer.Buffer ShowComposingReply() } type Prompt interface { 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] } type DefaultWindow struct { In tui.TextInput Buf buffer.Buffer } func (dw *DefaultWindow) Location() Location { return nil } func (w *DefaultWindow) Buffer() *buffer.Buffer { return &w.Buf } func (dw *DefaultWindow) Kill() {} func (w *DefaultWindow) Input() *tui.TextInput { return &w.In } func (w *DefaultWindow) Send(text string) {} func (w *DefaultWindow) ShowStatusLine() {} func (w *DefaultWindow) ShowComposingReply() {}