Skip to content

Commit

Permalink
Address lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Dec 29, 2017
1 parent c4937a2 commit b7abc91
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 19 deletions.
2 changes: 1 addition & 1 deletion internal/cops/braille/braille.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func Draw(dst *display.Display, r image.Rectangle, src image.Image, sp image.Poi
DrawBitmap(dst, r, bits, sp, on)
}

// DrawBitmap
// DrawBitmap FIXME
func DrawBitmap(dst *display.Display, r image.Rectangle, src BitmapReader, sp image.Point, fg color.Color) {
w, h := r.Dx(), r.Dy()
for y := 0; y < h; y++ {
Expand Down
13 changes: 9 additions & 4 deletions internal/cops/displaydraw/displaydraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"github.com/borkshop/bork/internal/cops/display"
)

func AsciiBox(d *display.Display, r image.Rectangle, fg, bg color.Color) {
// ASCIIBox draws a box onto a display with given foreground and background
// colors using ASCII "|" and "-", with "." and "'' for corners.
func ASCIIBox(d *display.Display, r image.Rectangle, fg, bg color.Color) {
r.Max = r.Max.Sub(image.Point{1, 1})
for y := r.Min.Y + 1; y < r.Max.Y; y++ {
d.Set(r.Min.X, y, "|", fg, bg)
Expand All @@ -23,15 +25,18 @@ func AsciiBox(d *display.Display, r image.Rectangle, fg, bg color.Color) {
d.Set(r.Max.X, r.Max.Y, "'", fg, bg)
}

func SpaceBox(d *display.Display, r image.Rectangle, m image.Point, c color.Color) {
// SpaceBox draws a border on the interior of the given rectangle.
// The border shows a color filled cells, but copying the screen will reveal
// "|" and "-" characters with the same foreground and background.
func SpaceBox(d *display.Display, r image.Rectangle, b image.Point, c color.Color) {
for y := r.Min.Y; y < r.Max.Y; y++ {
for x := 0; x < m.X; x++ {
for x := 0; x < b.X; x++ {
d.Set(r.Min.X+x, y, "|", c, c)
d.Set(r.Max.X-x-1, y, "|", c, c)
}
}
for x := r.Min.X; x < r.Max.X; x++ {
for y := 0; y < m.Y; y++ {
for y := 0; y < b.Y; y++ {
d.Set(x, r.Min.Y+y, "-", c, c)
d.Set(x, r.Max.Y-y-1, "-", c, c)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cops/examples/borkart/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
)

func main() {
if err := Main(); err != nil {
if err := run(); err != nil {
fmt.Printf("%v\n", err)
}
}

func Main() error {
func run() error {

term := terminal.New(os.Stdout.Fd())
defer term.Restore()
Expand Down
4 changes: 2 additions & 2 deletions internal/cops/examples/brailleline/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
)

func main() {
if err := Main(); err != nil {
if err := run(); err != nil {
fmt.Printf("%v\n", err)
}
}

func Main() error {
func run() error {
w, h := 32, 16
pb := image.Rect(0, 0, w, h)
bb := braille.Bounds(pb)
Expand Down
4 changes: 2 additions & 2 deletions internal/cops/examples/braillematrix/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
)

func main() {
if err := Main(); err != nil {
if err := run(); err != nil {
fmt.Printf("%v\n", err)
}
}

func Main() error {
func run() error {

w, h := 16, 16
pb := image.Rect(0, 0, w, h)
Expand Down
4 changes: 2 additions & 2 deletions internal/cops/examples/braillewave/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
)

func main() {
if err := Main(); err != nil {
if err := run(); err != nil {
fmt.Printf("%v\n", err)
}
}

func Main() error {
func run() error {
term := terminal.New(os.Stdout.Fd())
defer term.Restore()
term.SetRaw()
Expand Down
4 changes: 2 additions & 2 deletions internal/cops/examples/earthgif/earthgif.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
)

func main() {
if err := Main(); err != nil {
if err := run(); err != nil {
fmt.Printf("%v\n", err)
}
}

func Main() error {
func run() error {
term := terminal.New(os.Stdin.Fd())
defer term.Restore()
term.SetRaw()
Expand Down
4 changes: 2 additions & 2 deletions internal/cops/examples/hicops/hicops.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
)

func main() {
if err := Main(); err != nil {
if err := run(); err != nil {
fmt.Printf("%v\n", err)
}
}

func Main() error {
func run() error {
term := terminal.New(os.Stdin.Fd())
defer term.Restore()
term.SetRaw()
Expand Down
4 changes: 2 additions & 2 deletions internal/cops/examples/vt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
)

func main() {
if err := Main(); err != nil {
if err := run(); err != nil {
fmt.Printf("%v\n", err)
}
}

func Main() error {
func run() error {
term := terminal.New(os.Stdin.Fd())
defer term.Restore()
term.SetRaw()
Expand Down
12 changes: 12 additions & 0 deletions internal/cops/vtio/vtio.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package vtio provides a tool for drawing a ANSI stream onto a virtualized
// display.
package vtio

import (
Expand All @@ -12,6 +14,9 @@ import (
"github.com/borkshop/bork/internal/cops/display"
)

// NewDisplayWriter creates an IO writer into which you can write virtual
// terminal codes (ANSI) and capture the resulting virtualized display state.
// The implementation of the ANSI language is far from complete.
func NewDisplayWriter(rect image.Rectangle) *DisplayWriter {
dis := display.New(rect)
handler := &displayWriterHandler{
Expand All @@ -27,15 +32,20 @@ func NewDisplayWriter(rect image.Rectangle) *DisplayWriter {
}
}

// DisplayWriter captures ANSI terminal commands and draws them onto a virtual
// display.
type DisplayWriter struct {
parser *ansiterm.AnsiParser
handler *displayWriterHandler
}

// C returns a read channel. This channel will receive a non-blocking write
// whenever the underlying display changes.
func (d *DisplayWriter) C() <-chan struct{} {
return d.handler.c
}

// Write draws ANSI virtual terminal bytes onto the underlying virtual display.
func (d *DisplayWriter) Write(buf []byte) (int, error) {
d.handler.lock.Lock()
defer d.handler.lock.Unlock()
Expand All @@ -50,12 +60,14 @@ func (d *DisplayWriter) Write(buf []byte) (int, error) {
return count, err
}

// Draw captures the current display state.
func (d *DisplayWriter) Draw(e *display.Display, r image.Rectangle) {
d.handler.lock.RLock()
defer d.handler.lock.RUnlock()
display.Draw(e, r, d.handler.dis, image.ZP, draw.Src)
}

// Resize reallocates the display with different dimensions.
func (d *DisplayWriter) Resize(rect image.Rectangle) {
d.handler.lock.Lock()
defer d.handler.lock.Unlock()
Expand Down
10 changes: 10 additions & 0 deletions internal/hilbert/hilbert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ package hilbert

import "image"

// Scale is the width and height of a Hilbert space-filling curve.
// The scale must be a power of two.
type Scale int

// Encode returns the linear index of a point along a Hilbert curve with this
// scale.
func (scale Scale) Encode(pt image.Point) int {
return Encode(pt, int(scale))
}

// Decode returns the point at the given offset of a Hilbert curve with this
// scale.
func (scale Scale) Decode(hi int) image.Point {
return Decode(hi, int(scale))
}

// Encode returns the linear index of a point along a Hilbert curve for a given
// scale.
func Encode(pt image.Point, scale int) int {
var rotation image.Point
h := 0
Expand All @@ -24,6 +32,8 @@ func Encode(pt image.Point, scale int) int {
return h
}

// Decode returns the point corresponding to a given position along a Hilbert
// curve of particular size.
func Decode(h int, scale int) image.Point {
var pt, rotation image.Point
for s := 1; s < scale; s <<= 1 {
Expand Down
7 changes: 7 additions & 0 deletions internal/input/channel.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Package input provides an adapter that changes a stream of terminal input
// into a channel of commands.
// To use the command channel, read command by command and switch on the
// command type.
package input

import (
Expand All @@ -7,7 +11,10 @@ import (
"unicode"
)

// Move captures a motion command. The data are a unit vector.
type Move image.Point

// ShiftMove captures a motion command with the shift key pressed. The data are a unit vector.
type ShiftMove image.Point

// Channel returns a read channel for commands, distinguishable by type, and a
Expand Down

0 comments on commit b7abc91

Please sign in to comment.