Initial golint sweep for screen.go

master
Michael Dvorkin 11 years ago
parent 2e05c91d29
commit 89347a040e
  1. 107
      screen.go

@ -1,6 +1,6 @@
// Copyright (c) 2013 by Michael Dvorkin. All Rights Reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
// Use of this source code is governed by a MIT-style license that can
// be found in the LICENSE file.
package mop
@ -10,6 +10,7 @@ import (
`time`
)
// Screen ...
type Screen struct {
width int
height int
@ -18,100 +19,100 @@ type Screen struct {
markup *Markup
}
//-----------------------------------------------------------------------------
func (self *Screen) Initialize() *Screen {
// Initialize ...
func (screen *Screen) Initialize() *Screen {
if err := termbox.Init(); err != nil {
panic(err)
}
self.layout = new(Layout).Initialize()
self.markup = new(Markup).Initialize()
screen.layout = new(Layout).Initialize()
screen.markup = new(Markup).Initialize()
return self.Resize()
return screen.Resize()
}
//-----------------------------------------------------------------------------
func (self *Screen) Resize() *Screen {
self.width, self.height = termbox.Size()
self.cleared = false
// Close ...
func (screen *Screen) Close() *Screen {
termbox.Close()
return self
return screen
}
//-----------------------------------------------------------------------------
func (self *Screen) Clear() *Screen {
// Resize ...
func (screen *Screen) Resize() *Screen {
screen.width, screen.height = termbox.Size()
screen.cleared = false
return screen
}
// Clear ...
func (screen *Screen) Clear() *Screen {
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
self.cleared = true
screen.cleared = true
return self
return screen
}
//-----------------------------------------------------------------------------
func (self *Screen) Close() *Screen {
termbox.Close()
// ClearLine ...
func (screen *Screen) ClearLine(x int, y int) {
for i := x; i < screen.width; i++ {
termbox.SetCell(i, y, ' ', termbox.ColorDefault, termbox.ColorDefault)
}
return self
termbox.Flush()
}
//-----------------------------------------------------------------------------
func (self *Screen) Draw(objects ...interface{}) *Screen {
// Draw ...
func (screen *Screen) Draw(objects ...interface{}) *Screen {
for _, ptr := range objects {
switch ptr.(type) {
case *Market:
object := ptr.(*Market)
self.draw(self.layout.Market(object.Fetch()))
screen.draw(screen.layout.Market(object.Fetch()))
case *Quotes:
object := ptr.(*Quotes)
self.draw(self.layout.Quotes(object.Fetch()))
screen.draw(screen.layout.Quotes(object.Fetch()))
default:
self.draw(ptr.(string))
screen.draw(ptr.(string))
}
}
return self
return screen
}
//-----------------------------------------------------------------------------
func (self *Screen) DrawTime() {
now := time.Now().Format(`3:04:05pm PST`)
self.DrawLine(0, 0, `<right>` + now + `</right>`)
}
//-----------------------------------------------------------------------------
func (self *Screen) ClearLine(x int, y int) {
for i := x; i < self.width; i++ {
termbox.SetCell(i, y, ' ', termbox.ColorDefault, termbox.ColorDefault)
}
termbox.Flush()
}
//-----------------------------------------------------------------------------
func (self *Screen) DrawLine(x int, y int, str string) {
// DrawLine ...
func (screen *Screen) DrawLine(x int, y int, str string) {
start, column := 0, 0
for _, token := range self.markup.Tokenize(str) {
if !self.markup.IsTag(token) {
for _, token := range screen.markup.Tokenize(str) {
if !screen.markup.IsTag(token) {
for i, char := range token {
if !self.markup.RightAligned {
if !screen.markup.RightAligned {
start = x + column
column++
} else {
start = self.width - len(token) + i
start = screen.width - len(token) + i
}
termbox.SetCell(start, y, char, self.markup.Foreground, self.markup.Background)
termbox.SetCell(start, y, char, screen.markup.Foreground, screen.markup.Background)
}
}
}
termbox.Flush()
}
// private
// DrawTime ...
func (screen *Screen) DrawTime() {
now := time.Now().Format(`3:04:05pm PST`)
screen.DrawLine(0, 0, `<right>` + now + `</right>`)
}
//-----------------------------------------------------------------------------
func (self *Screen) draw(str string) {
if !self.cleared {
self.Clear()
func (screen *Screen) draw(str string) {
if !screen.cleared {
screen.Clear()
}
for row, line := range strings.Split(str, "\n") {
self.DrawLine(0, row, line)
screen.DrawLine(0, row, line)
}
}

Loading…
Cancel
Save