diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..82cc409 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: go +go: + - "1.9" +install: + - make install-ci +script: + - make ci + diff --git a/Gopkg.lock b/Gopkg.lock index 46c38c7..d97ce89 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -51,7 +51,7 @@ [[projects]] name = "github.com/stretchr/testify" - packages = ["assert"] + packages = ["assert","require"] revision = "69483b4bd14f5845b5a1e55bca19e954e827f1d0" version = "v1.1.4" @@ -70,6 +70,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "762af1e7e6510b65bbeaf64779b19184108aaa0e1279cc5f38ebb05f19e8a8a3" + inputs-digest = "6a8eca20c8e483ea61bcee8787af6d6cb4907b96a5ef90e80fbf37e013078c3b" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Makefile b/Makefile index d2e02f3..b6857bb 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,43 @@ + +GO_FILES := $(shell git ls-files | grep "\.go$$") + +PACKAGES := $(shell find $(GO_FILES) | xargs -n1 dirname | sed 's:^:./:'| uniq) + +.PHONY: test test: go test ./... +.PHONY: gofmt +gofmt: + gofmt -e -s -l $(GO_FILES) + +.PHONY: govet +govet: + go vet ./... + +.PHONY: golint +golint: + golint $(PACKAGES) + +.PHONY: errcheck +errcheck: + errcheck -ignoretests $(PACKAGES) + +.PHONY: lint +lint: gofmt govet golint errcheck + +.PHONY: install +install: + dep ensure + +.PHONY: install-ci +install-ci: + go get -u github.com/golang/dep/cmd/dep github.com/golang/lint/golint github.com/kisielk/errcheck + dep ensure + +.PHONY: ci +ci: test lint + run/%: proofs/% go run $(shell find $< -maxdepth 1 -name *.go -not -name *_test.go) diff --git a/internal/cops/braille/braille.go b/internal/cops/braille/braille.go index b6d64ca..b089c0f 100644 --- a/internal/cops/braille/braille.go +++ b/internal/cops/braille/braille.go @@ -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++ { diff --git a/internal/cops/display/colors.go b/internal/cops/display/colors.go index 9190e97..3996144 100644 --- a/internal/cops/display/colors.go +++ b/internal/cops/display/colors.go @@ -11,260 +11,260 @@ var Transparent = color.RGBA{} // the high intensity variants of the first 8 in more advanced ANSI terminals. // The next 6x6x6 colors are an RGB cube and the last 24 are shades of gray. var Colors = []color.RGBA{ - color.RGBA{0, 0, 0, 255}, - color.RGBA{128, 0, 0, 255}, - color.RGBA{0, 128, 0, 255}, - color.RGBA{128, 128, 0, 255}, - color.RGBA{0, 0, 128, 255}, - color.RGBA{128, 0, 128, 255}, - color.RGBA{0, 128, 128, 255}, - color.RGBA{192, 192, 192, 255}, - color.RGBA{128, 128, 128, 255}, - color.RGBA{255, 0, 0, 255}, - color.RGBA{0, 255, 0, 255}, - color.RGBA{255, 255, 0, 255}, - color.RGBA{0, 0, 255, 255}, - color.RGBA{255, 0, 255, 255}, - color.RGBA{0, 255, 255, 255}, - color.RGBA{255, 255, 255, 255}, - color.RGBA{0, 0, 0, 255}, - color.RGBA{0, 0, 95, 255}, - color.RGBA{0, 0, 135, 255}, - color.RGBA{0, 0, 175, 255}, - color.RGBA{0, 0, 215, 255}, - color.RGBA{0, 0, 255, 255}, - color.RGBA{0, 95, 0, 255}, - color.RGBA{0, 95, 95, 255}, - color.RGBA{0, 95, 135, 255}, - color.RGBA{0, 95, 175, 255}, - color.RGBA{0, 95, 215, 255}, - color.RGBA{0, 95, 255, 255}, - color.RGBA{0, 135, 0, 255}, - color.RGBA{0, 135, 95, 255}, - color.RGBA{0, 135, 135, 255}, - color.RGBA{0, 135, 175, 255}, - color.RGBA{0, 135, 215, 255}, - color.RGBA{0, 135, 255, 255}, - color.RGBA{0, 175, 0, 255}, - color.RGBA{0, 175, 95, 255}, - color.RGBA{0, 175, 135, 255}, - color.RGBA{0, 175, 175, 255}, - color.RGBA{0, 175, 215, 255}, - color.RGBA{0, 175, 255, 255}, - color.RGBA{0, 215, 0, 255}, - color.RGBA{0, 215, 95, 255}, - color.RGBA{0, 215, 135, 255}, - color.RGBA{0, 215, 175, 255}, - color.RGBA{0, 215, 215, 255}, - color.RGBA{0, 215, 255, 255}, - color.RGBA{0, 255, 0, 255}, - color.RGBA{0, 255, 95, 255}, - color.RGBA{0, 255, 135, 255}, - color.RGBA{0, 255, 175, 255}, - color.RGBA{0, 255, 215, 255}, - color.RGBA{0, 255, 255, 255}, - color.RGBA{95, 0, 0, 255}, - color.RGBA{95, 0, 95, 255}, - color.RGBA{95, 0, 135, 255}, - color.RGBA{95, 0, 175, 255}, - color.RGBA{95, 0, 215, 255}, - color.RGBA{95, 0, 255, 255}, - color.RGBA{95, 95, 0, 255}, - color.RGBA{95, 95, 95, 255}, - color.RGBA{95, 95, 135, 255}, - color.RGBA{95, 95, 175, 255}, - color.RGBA{95, 95, 215, 255}, - color.RGBA{95, 95, 255, 255}, - color.RGBA{95, 135, 0, 255}, - color.RGBA{95, 135, 95, 255}, - color.RGBA{95, 135, 135, 255}, - color.RGBA{95, 135, 175, 255}, - color.RGBA{95, 135, 215, 255}, - color.RGBA{95, 135, 255, 255}, - color.RGBA{95, 175, 0, 255}, - color.RGBA{95, 175, 95, 255}, - color.RGBA{95, 175, 135, 255}, - color.RGBA{95, 175, 175, 255}, - color.RGBA{95, 175, 215, 255}, - color.RGBA{95, 175, 255, 255}, - color.RGBA{95, 215, 0, 255}, - color.RGBA{95, 215, 95, 255}, - color.RGBA{95, 215, 135, 255}, - color.RGBA{95, 215, 175, 255}, - color.RGBA{95, 215, 215, 255}, - color.RGBA{95, 215, 255, 255}, - color.RGBA{95, 255, 0, 255}, - color.RGBA{95, 255, 95, 255}, - color.RGBA{95, 255, 135, 255}, - color.RGBA{95, 255, 175, 255}, - color.RGBA{95, 255, 215, 255}, - color.RGBA{95, 255, 255, 255}, - color.RGBA{135, 0, 0, 255}, - color.RGBA{135, 0, 95, 255}, - color.RGBA{135, 0, 135, 255}, - color.RGBA{135, 0, 175, 255}, - color.RGBA{135, 0, 215, 255}, - color.RGBA{135, 0, 255, 255}, - color.RGBA{135, 95, 0, 255}, - color.RGBA{135, 95, 95, 255}, - color.RGBA{135, 95, 135, 255}, - color.RGBA{135, 95, 175, 255}, - color.RGBA{135, 95, 215, 255}, - color.RGBA{135, 95, 255, 255}, - color.RGBA{135, 135, 0, 255}, - color.RGBA{135, 135, 95, 255}, - color.RGBA{135, 135, 135, 255}, - color.RGBA{135, 135, 175, 255}, - color.RGBA{135, 135, 215, 255}, - color.RGBA{135, 135, 255, 255}, - color.RGBA{135, 175, 0, 255}, - color.RGBA{135, 175, 95, 255}, - color.RGBA{135, 175, 135, 255}, - color.RGBA{135, 175, 175, 255}, - color.RGBA{135, 175, 215, 255}, - color.RGBA{135, 175, 255, 255}, - color.RGBA{135, 215, 0, 255}, - color.RGBA{135, 215, 95, 255}, - color.RGBA{135, 215, 135, 255}, - color.RGBA{135, 215, 175, 255}, - color.RGBA{135, 215, 215, 255}, - color.RGBA{135, 215, 255, 255}, - color.RGBA{135, 255, 0, 255}, - color.RGBA{135, 255, 95, 255}, - color.RGBA{135, 255, 135, 255}, - color.RGBA{135, 255, 175, 255}, - color.RGBA{135, 255, 215, 255}, - color.RGBA{135, 255, 255, 255}, - color.RGBA{175, 0, 0, 255}, - color.RGBA{175, 0, 95, 255}, - color.RGBA{175, 0, 135, 255}, - color.RGBA{175, 0, 175, 255}, - color.RGBA{175, 0, 215, 255}, - color.RGBA{175, 0, 255, 255}, - color.RGBA{175, 95, 0, 255}, - color.RGBA{175, 95, 95, 255}, - color.RGBA{175, 95, 135, 255}, - color.RGBA{175, 95, 175, 255}, - color.RGBA{175, 95, 215, 255}, - color.RGBA{175, 95, 255, 255}, - color.RGBA{175, 135, 0, 255}, - color.RGBA{175, 135, 95, 255}, - color.RGBA{175, 135, 135, 255}, - color.RGBA{175, 135, 175, 255}, - color.RGBA{175, 135, 215, 255}, - color.RGBA{175, 135, 255, 255}, - color.RGBA{175, 175, 0, 255}, - color.RGBA{175, 175, 95, 255}, - color.RGBA{175, 175, 135, 255}, - color.RGBA{175, 175, 175, 255}, - color.RGBA{175, 175, 215, 255}, - color.RGBA{175, 175, 255, 255}, - color.RGBA{175, 215, 0, 255}, - color.RGBA{175, 215, 95, 255}, - color.RGBA{175, 215, 135, 255}, - color.RGBA{175, 215, 175, 255}, - color.RGBA{175, 215, 215, 255}, - color.RGBA{175, 215, 255, 255}, - color.RGBA{175, 255, 0, 255}, - color.RGBA{175, 255, 95, 255}, - color.RGBA{175, 255, 135, 255}, - color.RGBA{175, 255, 175, 255}, - color.RGBA{175, 255, 215, 255}, - color.RGBA{175, 255, 255, 255}, - color.RGBA{215, 0, 0, 255}, - color.RGBA{215, 0, 95, 255}, - color.RGBA{215, 0, 135, 255}, - color.RGBA{215, 0, 175, 255}, - color.RGBA{215, 0, 215, 255}, - color.RGBA{215, 0, 255, 255}, - color.RGBA{215, 95, 0, 255}, - color.RGBA{215, 95, 95, 255}, - color.RGBA{215, 95, 135, 255}, - color.RGBA{215, 95, 175, 255}, - color.RGBA{215, 95, 215, 255}, - color.RGBA{215, 95, 255, 255}, - color.RGBA{215, 135, 0, 255}, - color.RGBA{215, 135, 95, 255}, - color.RGBA{215, 135, 135, 255}, - color.RGBA{215, 135, 175, 255}, - color.RGBA{215, 135, 215, 255}, - color.RGBA{215, 135, 255, 255}, - color.RGBA{215, 175, 0, 255}, - color.RGBA{215, 175, 95, 255}, - color.RGBA{215, 175, 135, 255}, - color.RGBA{215, 175, 175, 255}, - color.RGBA{215, 175, 215, 255}, - color.RGBA{215, 175, 255, 255}, - color.RGBA{215, 215, 0, 255}, - color.RGBA{215, 215, 95, 255}, - color.RGBA{215, 215, 135, 255}, - color.RGBA{215, 215, 175, 255}, - color.RGBA{215, 215, 215, 255}, - color.RGBA{215, 215, 255, 255}, - color.RGBA{215, 255, 0, 255}, - color.RGBA{215, 255, 95, 255}, - color.RGBA{215, 255, 135, 255}, - color.RGBA{215, 255, 175, 255}, - color.RGBA{215, 255, 215, 255}, - color.RGBA{215, 255, 255, 255}, - color.RGBA{255, 0, 0, 255}, - color.RGBA{255, 0, 95, 255}, - color.RGBA{255, 0, 135, 255}, - color.RGBA{255, 0, 175, 255}, - color.RGBA{255, 0, 215, 255}, - color.RGBA{255, 0, 255, 255}, - color.RGBA{255, 95, 0, 255}, - color.RGBA{255, 95, 95, 255}, - color.RGBA{255, 95, 135, 255}, - color.RGBA{255, 95, 175, 255}, - color.RGBA{255, 95, 215, 255}, - color.RGBA{255, 95, 255, 255}, - color.RGBA{255, 135, 0, 255}, - color.RGBA{255, 135, 95, 255}, - color.RGBA{255, 135, 135, 255}, - color.RGBA{255, 135, 175, 255}, - color.RGBA{255, 135, 215, 255}, - color.RGBA{255, 135, 255, 255}, - color.RGBA{255, 175, 0, 255}, - color.RGBA{255, 175, 95, 255}, - color.RGBA{255, 175, 135, 255}, - color.RGBA{255, 175, 175, 255}, - color.RGBA{255, 175, 215, 255}, - color.RGBA{255, 175, 255, 255}, - color.RGBA{255, 215, 0, 255}, - color.RGBA{255, 215, 95, 255}, - color.RGBA{255, 215, 135, 255}, - color.RGBA{255, 215, 175, 255}, - color.RGBA{255, 215, 215, 255}, - color.RGBA{255, 215, 255, 255}, - color.RGBA{255, 255, 0, 255}, - color.RGBA{255, 255, 95, 255}, - color.RGBA{255, 255, 135, 255}, - color.RGBA{255, 255, 175, 255}, - color.RGBA{255, 255, 215, 255}, - color.RGBA{255, 255, 255, 255}, - color.RGBA{8, 8, 8, 255}, - color.RGBA{18, 18, 18, 255}, - color.RGBA{28, 28, 28, 255}, - color.RGBA{38, 38, 38, 255}, - color.RGBA{48, 48, 48, 255}, - color.RGBA{58, 58, 58, 255}, - color.RGBA{68, 68, 68, 255}, - color.RGBA{78, 78, 78, 255}, - color.RGBA{88, 88, 88, 255}, - color.RGBA{98, 98, 98, 255}, - color.RGBA{108, 108, 108, 255}, - color.RGBA{118, 118, 118, 255}, - color.RGBA{128, 128, 128, 255}, - color.RGBA{138, 138, 138, 255}, - color.RGBA{148, 148, 148, 255}, - color.RGBA{158, 158, 158, 255}, - color.RGBA{168, 168, 168, 255}, - color.RGBA{178, 178, 178, 255}, - color.RGBA{188, 188, 188, 255}, - color.RGBA{198, 198, 198, 255}, - color.RGBA{208, 208, 208, 255}, - color.RGBA{218, 218, 218, 255}, - color.RGBA{228, 228, 228, 255}, - color.RGBA{238, 238, 238, 255}, + {0, 0, 0, 255}, + {128, 0, 0, 255}, + {0, 128, 0, 255}, + {128, 128, 0, 255}, + {0, 0, 128, 255}, + {128, 0, 128, 255}, + {0, 128, 128, 255}, + {192, 192, 192, 255}, + {128, 128, 128, 255}, + {255, 0, 0, 255}, + {0, 255, 0, 255}, + {255, 255, 0, 255}, + {0, 0, 255, 255}, + {255, 0, 255, 255}, + {0, 255, 255, 255}, + {255, 255, 255, 255}, + {0, 0, 0, 255}, + {0, 0, 95, 255}, + {0, 0, 135, 255}, + {0, 0, 175, 255}, + {0, 0, 215, 255}, + {0, 0, 255, 255}, + {0, 95, 0, 255}, + {0, 95, 95, 255}, + {0, 95, 135, 255}, + {0, 95, 175, 255}, + {0, 95, 215, 255}, + {0, 95, 255, 255}, + {0, 135, 0, 255}, + {0, 135, 95, 255}, + {0, 135, 135, 255}, + {0, 135, 175, 255}, + {0, 135, 215, 255}, + {0, 135, 255, 255}, + {0, 175, 0, 255}, + {0, 175, 95, 255}, + {0, 175, 135, 255}, + {0, 175, 175, 255}, + {0, 175, 215, 255}, + {0, 175, 255, 255}, + {0, 215, 0, 255}, + {0, 215, 95, 255}, + {0, 215, 135, 255}, + {0, 215, 175, 255}, + {0, 215, 215, 255}, + {0, 215, 255, 255}, + {0, 255, 0, 255}, + {0, 255, 95, 255}, + {0, 255, 135, 255}, + {0, 255, 175, 255}, + {0, 255, 215, 255}, + {0, 255, 255, 255}, + {95, 0, 0, 255}, + {95, 0, 95, 255}, + {95, 0, 135, 255}, + {95, 0, 175, 255}, + {95, 0, 215, 255}, + {95, 0, 255, 255}, + {95, 95, 0, 255}, + {95, 95, 95, 255}, + {95, 95, 135, 255}, + {95, 95, 175, 255}, + {95, 95, 215, 255}, + {95, 95, 255, 255}, + {95, 135, 0, 255}, + {95, 135, 95, 255}, + {95, 135, 135, 255}, + {95, 135, 175, 255}, + {95, 135, 215, 255}, + {95, 135, 255, 255}, + {95, 175, 0, 255}, + {95, 175, 95, 255}, + {95, 175, 135, 255}, + {95, 175, 175, 255}, + {95, 175, 215, 255}, + {95, 175, 255, 255}, + {95, 215, 0, 255}, + {95, 215, 95, 255}, + {95, 215, 135, 255}, + {95, 215, 175, 255}, + {95, 215, 215, 255}, + {95, 215, 255, 255}, + {95, 255, 0, 255}, + {95, 255, 95, 255}, + {95, 255, 135, 255}, + {95, 255, 175, 255}, + {95, 255, 215, 255}, + {95, 255, 255, 255}, + {135, 0, 0, 255}, + {135, 0, 95, 255}, + {135, 0, 135, 255}, + {135, 0, 175, 255}, + {135, 0, 215, 255}, + {135, 0, 255, 255}, + {135, 95, 0, 255}, + {135, 95, 95, 255}, + {135, 95, 135, 255}, + {135, 95, 175, 255}, + {135, 95, 215, 255}, + {135, 95, 255, 255}, + {135, 135, 0, 255}, + {135, 135, 95, 255}, + {135, 135, 135, 255}, + {135, 135, 175, 255}, + {135, 135, 215, 255}, + {135, 135, 255, 255}, + {135, 175, 0, 255}, + {135, 175, 95, 255}, + {135, 175, 135, 255}, + {135, 175, 175, 255}, + {135, 175, 215, 255}, + {135, 175, 255, 255}, + {135, 215, 0, 255}, + {135, 215, 95, 255}, + {135, 215, 135, 255}, + {135, 215, 175, 255}, + {135, 215, 215, 255}, + {135, 215, 255, 255}, + {135, 255, 0, 255}, + {135, 255, 95, 255}, + {135, 255, 135, 255}, + {135, 255, 175, 255}, + {135, 255, 215, 255}, + {135, 255, 255, 255}, + {175, 0, 0, 255}, + {175, 0, 95, 255}, + {175, 0, 135, 255}, + {175, 0, 175, 255}, + {175, 0, 215, 255}, + {175, 0, 255, 255}, + {175, 95, 0, 255}, + {175, 95, 95, 255}, + {175, 95, 135, 255}, + {175, 95, 175, 255}, + {175, 95, 215, 255}, + {175, 95, 255, 255}, + {175, 135, 0, 255}, + {175, 135, 95, 255}, + {175, 135, 135, 255}, + {175, 135, 175, 255}, + {175, 135, 215, 255}, + {175, 135, 255, 255}, + {175, 175, 0, 255}, + {175, 175, 95, 255}, + {175, 175, 135, 255}, + {175, 175, 175, 255}, + {175, 175, 215, 255}, + {175, 175, 255, 255}, + {175, 215, 0, 255}, + {175, 215, 95, 255}, + {175, 215, 135, 255}, + {175, 215, 175, 255}, + {175, 215, 215, 255}, + {175, 215, 255, 255}, + {175, 255, 0, 255}, + {175, 255, 95, 255}, + {175, 255, 135, 255}, + {175, 255, 175, 255}, + {175, 255, 215, 255}, + {175, 255, 255, 255}, + {215, 0, 0, 255}, + {215, 0, 95, 255}, + {215, 0, 135, 255}, + {215, 0, 175, 255}, + {215, 0, 215, 255}, + {215, 0, 255, 255}, + {215, 95, 0, 255}, + {215, 95, 95, 255}, + {215, 95, 135, 255}, + {215, 95, 175, 255}, + {215, 95, 215, 255}, + {215, 95, 255, 255}, + {215, 135, 0, 255}, + {215, 135, 95, 255}, + {215, 135, 135, 255}, + {215, 135, 175, 255}, + {215, 135, 215, 255}, + {215, 135, 255, 255}, + {215, 175, 0, 255}, + {215, 175, 95, 255}, + {215, 175, 135, 255}, + {215, 175, 175, 255}, + {215, 175, 215, 255}, + {215, 175, 255, 255}, + {215, 215, 0, 255}, + {215, 215, 95, 255}, + {215, 215, 135, 255}, + {215, 215, 175, 255}, + {215, 215, 215, 255}, + {215, 215, 255, 255}, + {215, 255, 0, 255}, + {215, 255, 95, 255}, + {215, 255, 135, 255}, + {215, 255, 175, 255}, + {215, 255, 215, 255}, + {215, 255, 255, 255}, + {255, 0, 0, 255}, + {255, 0, 95, 255}, + {255, 0, 135, 255}, + {255, 0, 175, 255}, + {255, 0, 215, 255}, + {255, 0, 255, 255}, + {255, 95, 0, 255}, + {255, 95, 95, 255}, + {255, 95, 135, 255}, + {255, 95, 175, 255}, + {255, 95, 215, 255}, + {255, 95, 255, 255}, + {255, 135, 0, 255}, + {255, 135, 95, 255}, + {255, 135, 135, 255}, + {255, 135, 175, 255}, + {255, 135, 215, 255}, + {255, 135, 255, 255}, + {255, 175, 0, 255}, + {255, 175, 95, 255}, + {255, 175, 135, 255}, + {255, 175, 175, 255}, + {255, 175, 215, 255}, + {255, 175, 255, 255}, + {255, 215, 0, 255}, + {255, 215, 95, 255}, + {255, 215, 135, 255}, + {255, 215, 175, 255}, + {255, 215, 215, 255}, + {255, 215, 255, 255}, + {255, 255, 0, 255}, + {255, 255, 95, 255}, + {255, 255, 135, 255}, + {255, 255, 175, 255}, + {255, 255, 215, 255}, + {255, 255, 255, 255}, + {8, 8, 8, 255}, + {18, 18, 18, 255}, + {28, 28, 28, 255}, + {38, 38, 38, 255}, + {48, 48, 48, 255}, + {58, 58, 58, 255}, + {68, 68, 68, 255}, + {78, 78, 78, 255}, + {88, 88, 88, 255}, + {98, 98, 98, 255}, + {108, 108, 108, 255}, + {118, 118, 118, 255}, + {128, 128, 128, 255}, + {138, 138, 138, 255}, + {148, 148, 148, 255}, + {158, 158, 158, 255}, + {168, 168, 168, 255}, + {178, 178, 178, 255}, + {188, 188, 188, 255}, + {198, 198, 198, 255}, + {208, 208, 208, 255}, + {218, 218, 218, 255}, + {228, 228, 228, 255}, + {238, 238, 238, 255}, } diff --git a/internal/cops/displaydraw/displaydraw.go b/internal/cops/displaydraw/displaydraw.go index 860fabb..527481c 100644 --- a/internal/cops/displaydraw/displaydraw.go +++ b/internal/cops/displaydraw/displaydraw.go @@ -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) @@ -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) } diff --git a/internal/cops/examples/borkart/main.go b/internal/cops/examples/borkart/main.go index ae8b2ee..acd9025 100644 --- a/internal/cops/examples/borkart/main.go +++ b/internal/cops/examples/borkart/main.go @@ -12,16 +12,21 @@ import ( ) func main() { - if err := Main(); err != nil { + if err := run(); err != nil { fmt.Printf("%v\n", err) } } -func Main() error { +func run() (err error) { term := terminal.New(os.Stdout.Fd()) - defer term.Restore() - term.SetRaw() + defer func() { + err = term.Restore() + }() + err = term.SetRaw() + if err != nil { + return err + } bounds, err := term.Bounds() if err != nil { @@ -72,11 +77,17 @@ Loop: buf, cur = display.RenderOver(buf, cur, front, back, display.Model24) front, back = back, front - os.Stdout.Write(buf) + _, err = os.Stdout.Write(buf) + if err != nil { + return err + } buf = buf[0:0] var rbuf [1]byte - os.Stdin.Read(rbuf[0:1]) + _, err = os.Stdin.Read(rbuf[0:1]) + if err != nil { + return err + } switch rbuf[0] { case ' ': @@ -101,7 +112,10 @@ Loop: buf, cur = cur.Home(buf) buf, cur = cur.Clear(buf) buf, cur = cur.Show(buf) - os.Stdout.Write(buf) + _, err = os.Stdout.Write(buf) + if err != nil { + return err + } buf = buf[0:0] - return nil + return err } diff --git a/internal/cops/examples/brailleline/main.go b/internal/cops/examples/brailleline/main.go index 06305ec..4d92ba7 100644 --- a/internal/cops/examples/brailleline/main.go +++ b/internal/cops/examples/brailleline/main.go @@ -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() (err error) { w, h := 32, 16 pb := image.Rect(0, 0, w, h) bb := braille.Bounds(pb) @@ -38,7 +38,7 @@ func Main() error { cur := display.Reset buf, cur = display.Render(buf, cur, front, display.Model0) buf = append(buf, "\r\n"...) - os.Stdout.Write(buf) + _, err = os.Stdout.Write(buf) - return nil + return err } diff --git a/internal/cops/examples/braillematrix/main.go b/internal/cops/examples/braillematrix/main.go index 3e3eedd..f37f19f 100644 --- a/internal/cops/examples/braillematrix/main.go +++ b/internal/cops/examples/braillematrix/main.go @@ -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() (err error) { w, h := 16, 16 pb := image.Rect(0, 0, w, h) @@ -66,7 +66,7 @@ func Main() error { cur := display.Reset buf, cur = display.Render(buf, cur, page, display.Model8) buf = append(buf, "\r\n"...) - os.Stdout.Write(buf) + _, err = os.Stdout.Write(buf) - return nil + return err } diff --git a/internal/cops/examples/braillewave/main.go b/internal/cops/examples/braillewave/main.go index d316c79..0df0d9f 100644 --- a/internal/cops/examples/braillewave/main.go +++ b/internal/cops/examples/braillewave/main.go @@ -14,15 +14,20 @@ import ( ) func main() { - if err := Main(); err != nil { + if err := run(); err != nil { fmt.Printf("%v\n", err) } } -func Main() error { +func run() (err error) { term := terminal.New(os.Stdout.Fd()) - defer term.Restore() - term.SetRaw() + defer func() { + err = term.Restore() + }() + err = term.SetRaw() + if err != nil { + return err + } bounds, err := term.Bounds() if err != nil { @@ -34,7 +39,7 @@ func Main() error { stopper := make(chan struct{}, 0) go func() { var rbuf [1]byte - os.Stdin.Read(rbuf[0:1]) + _, err = os.Stdin.Read(rbuf[0:1]) close(stopper) }() @@ -69,7 +74,10 @@ Loop: buf, cur = display.RenderOver(buf, cur, front, back, display.Model24) front, back = back, front - os.Stdout.Write(buf) + _, err = os.Stdout.Write(buf) + if err != nil { + return err + } buf = buf[0:0] select { @@ -84,8 +92,8 @@ Loop: buf, cur = cur.Home(buf) buf, cur = cur.Clear(buf) buf, cur = cur.Show(buf) - os.Stdout.Write(buf) + _, err = os.Stdout.Write(buf) buf = buf[0:0] - return nil + return err } diff --git a/internal/cops/examples/earthgif/earthgif.go b/internal/cops/examples/earthgif/earthgif.go index 73b2b9a..129dd76 100644 --- a/internal/cops/examples/earthgif/earthgif.go +++ b/internal/cops/examples/earthgif/earthgif.go @@ -15,15 +15,20 @@ import ( ) func main() { - if err := Main(); err != nil { + if err := run(); err != nil { fmt.Printf("%v\n", err) } } -func Main() error { +func run() (err error) { term := terminal.New(os.Stdin.Fd()) - defer term.Restore() - term.SetRaw() + defer func() { + err = term.Restore() + }() + err = term.SetRaw() + if err != nil { + return err + } data, err := Asset("earth.gif") if err != nil { @@ -62,7 +67,10 @@ func Main() error { go func() { var rbuf [1]byte for { - os.Stdin.Read(rbuf[0:1]) + _, err := os.Stdin.Read(rbuf[0:1]) + if err != nil { + break + } keypress <- rbuf[0] } }() @@ -78,7 +86,10 @@ Loop: buf, cur = display.RenderOver(buf, cur, front, back, display.Model24) front, back = back, front buf, cur = cur.Home(buf) - os.Stdout.Write(buf) + _, err = os.Stdout.Write(buf) + if err != nil { + break Loop + } buf = buf[0:0] delay := time.Duration(imgs.Delay[i]) * time.Millisecond * 10 @@ -98,10 +109,10 @@ Loop: buf, cur = cur.Home(buf) buf, cur = cur.Clear(buf) buf, cur = cur.Show(buf) - os.Stdout.Write(buf) + _, err = os.Stdout.Write(buf) buf = buf[0:0] - return nil + return err } func projectCenterPreserveAspect(inner, outer image.Point) image.Rectangle { diff --git a/internal/cops/examples/hicops/hicops.go b/internal/cops/examples/hicops/hicops.go index 6ac1c7d..0a337a4 100644 --- a/internal/cops/examples/hicops/hicops.go +++ b/internal/cops/examples/hicops/hicops.go @@ -14,15 +14,20 @@ import ( ) func main() { - if err := Main(); err != nil { + if err := run(); err != nil { fmt.Printf("%v\n", err) } } -func Main() error { +func run() (err error) { term := terminal.New(os.Stdin.Fd()) - defer term.Restore() - term.SetRaw() + defer func() { + err = term.Restore() + }() + err = term.SetRaw() + if err != nil { + return + } bounds, err := term.Bounds() if err != nil { @@ -51,17 +56,23 @@ func Main() error { buf, cur = cur.Home(buf) buf, cur = display.Render(buf, cur, front, display.Model24) buf, cur = cur.Home(buf) - os.Stdout.Write(buf) + _, err = os.Stdout.Write(buf) + if err != nil { + return err + } buf = buf[0:0] var input [1]byte - os.Stdin.Read(input[0:1]) + _, err = os.Stdin.Read(input[0:1]) + if err != nil { + return err + } buf, cur = cur.Home(buf) buf, cur = cur.Clear(buf) buf, cur = cur.Show(buf) - os.Stdout.Write(buf) + _, err = os.Stdout.Write(buf) buf = buf[0:0] - return nil + return err } diff --git a/internal/cops/examples/vt/main.go b/internal/cops/examples/vt/main.go index bb7d58d..a1113e7 100644 --- a/internal/cops/examples/vt/main.go +++ b/internal/cops/examples/vt/main.go @@ -13,15 +13,20 @@ import ( ) func main() { - if err := Main(); err != nil { + if err := run(); err != nil { fmt.Printf("%v\n", err) } } -func Main() error { +func run() (err error) { term := terminal.New(os.Stdin.Fd()) - defer term.Restore() - term.SetRaw() + defer func() { + err = term.Restore() + }() + err = term.SetRaw() + if err != nil { + return err + } leader, follower, err := termios.Pty() if err != nil { @@ -46,7 +51,9 @@ func Main() error { } vtw := vtio.NewDisplayWriter(bounds) - go io.Copy(vtw, leader) + go func() { + _, err = io.Copy(vtw, leader) + }() front, back := display.New2(bounds) @@ -61,7 +68,7 @@ func Main() error { r := make(chan struct{}, 0) go func() { var rbuf [1]byte - os.Stdin.Read(rbuf[0:1]) + _, err = os.Stdin.Read(rbuf[0:1]) close(r) }() @@ -73,7 +80,10 @@ DrawLoop: buf, cur = display.RenderOver(buf, cur, front, back, display.Model24) front, back = back, front // fmt.Printf("%q\r\n", buf) - os.Stdout.Write(buf) + _, err = os.Stdout.Write(buf) + if err != nil { + break DrawLoop + } buf = buf[0:0] case <-r: break DrawLoop @@ -84,8 +94,8 @@ DrawLoop: buf, cur = cur.Home(buf) buf, cur = cur.Clear(buf) buf, cur = cur.Show(buf) - os.Stdout.Write(buf) + _, err = os.Stdout.Write(buf) buf = buf[0:0] - return nil + return err } diff --git a/internal/cops/terminal/terminal.go b/internal/cops/terminal/terminal.go index 99f5446..ce0c0cf 100644 --- a/internal/cops/terminal/terminal.go +++ b/internal/cops/terminal/terminal.go @@ -21,7 +21,7 @@ type Terminal struct { // that terminal to its current state. func New(fd uintptr) Terminal { t := Terminal{fd: fd} - termios.Tcgetattr(fd, &t.old) + _ = termios.Tcgetattr(fd, &t.old) t.now = t.old return t } diff --git a/internal/cops/vtio/vtio.go b/internal/cops/vtio/vtio.go index 3b168cf..d36c019 100644 --- a/internal/cops/vtio/vtio.go +++ b/internal/cops/vtio/vtio.go @@ -1,3 +1,5 @@ +// Package vtio provides a tool for drawing a ANSI stream onto a virtualized +// display. package vtio import ( @@ -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{ @@ -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() @@ -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() @@ -110,7 +122,9 @@ func (h *displayWriterHandler) Print(b byte) error { func (h *displayWriterHandler) Execute(b byte) error { // fmt.Printf("E %q\r\n", string(b)) - h.Flush() + if err := h.Flush(); err != nil { + return err + } switch b { case '\n': h.pos.Y++ @@ -128,7 +142,9 @@ func (h *displayWriterHandler) Execute(b byte) error { // Cursor up func (h *displayWriterHandler) CUU(i int) error { - h.Flush() + if err := h.Flush(); err != nil { + return err + } // fmt.Printf("CUU\n") h.pos.Y -= i // if h.pos.Y < h.dis.Rect.Min.Y { @@ -139,7 +155,9 @@ func (h *displayWriterHandler) CUU(i int) error { // Cursor down func (h *displayWriterHandler) CUD(i int) error { - h.Flush() + if err := h.Flush(); err != nil { + return err + } // fmt.Printf("CUD\n") h.pos.Y += i // if h.pos.Y >= h.dis.Rect.Max.Y { @@ -150,7 +168,9 @@ func (h *displayWriterHandler) CUD(i int) error { // Cursor forward func (h *displayWriterHandler) CUF(i int) error { - h.Flush() + if err := h.Flush(); err != nil { + return err + } // fmt.Printf("CUF\n") h.pos.X += i // if h.pos.X >= h.dis.Rect.Max.X { @@ -161,7 +181,9 @@ func (h *displayWriterHandler) CUF(i int) error { // Cursor backward func (h *displayWriterHandler) CUB(i int) error { - h.Flush() + if err := h.Flush(); err != nil { + return err + } // fmt.Printf("CUB\n") h.pos.X -= i // if h.pos.X < h.dis.Rect.Min.X { @@ -172,19 +194,25 @@ func (h *displayWriterHandler) CUB(i int) error { // Cursor new line? func (h *displayWriterHandler) CNL(i int) error { - h.Flush() + if err := h.Flush(); err != nil { + return err + } // fmt.Printf("CNL\n") return nil } func (h *displayWriterHandler) CPL(int) error { - h.Flush() + if err := h.Flush(); err != nil { + return err + } // fmt.Printf("CPL\n") return nil } func (h *displayWriterHandler) CHA(i int) error { - h.Flush() + if err := h.Flush(); err != nil { + return err + } h.pos.X = i - 1 return nil } @@ -199,7 +227,9 @@ func (h *displayWriterHandler) VPA(i int) error { // Cursor update func (h *displayWriterHandler) CUP(y, x int) error { // fmt.Printf("CUP\r\n") - h.Flush() + if err := h.Flush(); err != nil { + return err + } h.pos.X = x - 1 h.pos.Y = y - 1 return nil @@ -207,8 +237,7 @@ func (h *displayWriterHandler) CUP(y, x int) error { // Horizontal vertical position func (h *displayWriterHandler) HVP(y, x int) error { - h.CUP(y, x) - return nil + return h.CUP(y, x) } // Text cursor enable mode (show or hide cursor) @@ -230,8 +259,7 @@ func (h *displayWriterHandler) DECCOLM(bool) error { // Erase display func (h *displayWriterHandler) ED(i int) error { // fmt.Printf("ED\r\n") - h.Flush() - return nil + return h.Flush() } // Erase line @@ -275,7 +303,9 @@ func (h *displayWriterHandler) DCH(int) error { // Set graphics rendition func (h *displayWriterHandler) SGR(codes []int) error { // fmt.Printf("SGR %#v\r\n", codes) - h.Flush() + if err := h.Flush(); err != nil { + return err + } if len(codes) == 0 { h.fg = display.Colors[7] diff --git a/internal/hilbert/hilbert.go b/internal/hilbert/hilbert.go index 326c453..39c0812 100644 --- a/internal/hilbert/hilbert.go +++ b/internal/hilbert/hilbert.go @@ -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 @@ -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 { diff --git a/internal/input/channel.go b/internal/input/channel.go index 86b8320..4829ac0 100644 --- a/internal/input/channel.go +++ b/internal/input/channel.go @@ -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 ( @@ -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 diff --git a/internal/perf/perf.go b/internal/perf/perf.go index 6dcca56..fff27e3 100644 --- a/internal/perf/perf.go +++ b/internal/perf/perf.go @@ -143,7 +143,7 @@ func (perf *Perf) stopProfiling() (err error) { } perf.shouldProfile = false perf.profiling = false - return nil + return err } func (perf *Perf) takeProfile() error { diff --git a/proofs/showroom/main.go b/proofs/showroom/main.go index 6e59d28..ce7907c 100644 --- a/proofs/showroom/main.go +++ b/proofs/showroom/main.go @@ -40,7 +40,7 @@ func run() (rerr error) { commands, mute := input.Channel(os.Stdin) defer mute() - sigwinch := make(chan os.Signal) + sigwinch := make(chan os.Signal, 1) signal.Notify(sigwinch, syscall.SIGWINCH) world := newWorld() diff --git a/proofs/splash/main.go b/proofs/splash/main.go index ca24036..e227c60 100644 --- a/proofs/splash/main.go +++ b/proofs/splash/main.go @@ -48,7 +48,7 @@ func run() (rerr error) { commands, mute := input.Channel(os.Stdin) defer mute() - sigwinch := make(chan os.Signal) + sigwinch := make(chan os.Signal, 1) signal.Notify(sigwinch, syscall.SIGWINCH) ticker := time.NewTicker(time.Second / 60)