package main import ( "time" "github.com/br0xen/termbox-util" "github.com/nsf/termbox-go" ) // ServerScreen holds all that's going on :D type ServerScreen struct { initialized bool message string messageTime time.Time messageTimeout time.Duration tabIdx int } func (screen *ServerScreen) handleEvent(event termbox.Event) int { _, h := termbox.Size() if event.Type == termbox.EventKey { } return ServerScreenIndex } func (screen *ServerScreen) performLayout(style Style) { w, h := termbox.Size() if !screen.initialized { } if screen.messageTimeout > 0 && time.Since(screen.messageTime) > screen.messageTimeout { screen.clearMessage() msgString := "" msgString = termboxUtil.AlignText(msgString, w, termboxUtil.AlignLeft) screen.setMessage(msgString) } } func (screen *ServerScreen) drawScreen(style Style) { w, h := termbox.Size() screen.drawHeader(style) screen.drawFooter(style) } func (screen *ServerScreen) drawHeader(style Style) { w, _ := termbox.Size() ttl := termboxUtil.AlignTextWithFill("Boltrest Server", w+1, termboxUtil.AlignCenter, '=') termboxUtil.DrawStringAtPoint(ttl, 0, 0, style.defaultBg, style.defaultFg) } func (screen *ServerScreen) drawFooter(style Style) { _, height := termbox.Size() termboxUtil.DrawStringAtPoint(screen.message, 0, height-1, style.defaultBg, style.defaultFg) } func (screen *ServerScreen) setMessage(msg string) { screen.message = msg screen.messageTime = time.Now() screen.messageTimeout = -1 } /* setMessageWithTimeout lets you specify the timeout for the message * setting it to -1 means it won't timeout */ func (screen *ServerScreen) setMessageWithTimeout(msg string, timeout time.Duration) { screen.message = msg screen.messageTime = time.Now() screen.messageTimeout = timeout } func (screen *ServerScreen) clearMessage() { screen.message = "" screen.messageTimeout = -1 }