* Added Make targets for gofmt

- `make check-gofmt` will check for files that aren't gofmt compliant
- `make gofmt` will fix any gofmt error's in Aminal's source

Vendored files are ignored.

* Add gofmt check to TravisCI checks

* Fix gofmt errors
This commit is contained in:
Menno Finlay-Smits 2019-02-15 05:45:53 +13:00 committed by Liam Galvin
parent 6ded551de9
commit 35193b7981
13 changed files with 38 additions and 26 deletions

View File

@ -29,6 +29,7 @@ script:
- if [[ $TRAVIS_OS_NAME == 'osx' ]]; then make build-darwin-native-travis; fi - if [[ $TRAVIS_OS_NAME == 'osx' ]]; then make build-darwin-native-travis; fi
- if [[ $TRAVIS_OS_NAME == 'linux' ]]; then make build-linux-travis; fi - if [[ $TRAVIS_OS_NAME == 'linux' ]]; then make build-linux-travis; fi
- if [[ $TRAVIS_OS_NAME == 'linux' ]]; then make windows-cross-compile-travis; fi - if [[ $TRAVIS_OS_NAME == 'linux' ]]; then make windows-cross-compile-travis; fi
- if [[ $TRAVIS_OS_NAME == 'linux' ]]; then make check-gofmt; fi
env: env:
global: global:
- secure: "pdRpTOGQSUgbC9tK37voxUYJHMWDPJEmdMhNBsljpP9VnxxbR6JEFwvOQEmUHGlsYv8jma6a17jE60ngVQk8QP12cPh48i2bdbVgym/zTUOKFawCtPAzs8i7evh0di5eZ3uoyc42kG4skc+ePuVHbXC8jDxwaPpMqSHD7QyQc1/6ckI9LLkyWUqhnJJXkVwhmI74Aa1Im6QhywAWFMeTBRRL02cwr6k7VKSYOn6yrtzJRCALFGpZ/n58lPrpDxN7W8o+HRQP89wIDy8FyNeEPdmqGFNfMHDvI3oJRN4dGC4H9EkKf/iGuNJia1Bs+MgaG9kKlMHsI6Fkh5uw9KNTvC1llx43VRQJzm26cn1CpRxxRtF4F8lqkpY4tHjxxCitV+98ddW8jdmQYyx+LeueC5wqlO9g2M5L3oXsGMqZ++mDRDa8oQoQAVUSVtimeO8ODXFuVNR8TlupP0Cthgucil63VUZfAD8EHc2zpRSFxfYByDH53uMEinn20uovL6W42fqgboC43HOnR6aVfSANPsBFDlcpZFa2BY5RkcKyYdaLkucy0DKJ946UDfhOu6FNm0GPHq5HcgWkLojNF0dEFgG6J+SGQGiPjxTlHP/zoe61qMlWu+fYRXQnKWZN5Kk0T1TbAk6pKSE6wRLG8ddxvMg+eVpGLT+gAvQdrrkMFvs=" - secure: "pdRpTOGQSUgbC9tK37voxUYJHMWDPJEmdMhNBsljpP9VnxxbR6JEFwvOQEmUHGlsYv8jma6a17jE60ngVQk8QP12cPh48i2bdbVgym/zTUOKFawCtPAzs8i7evh0di5eZ3uoyc42kG4skc+ePuVHbXC8jDxwaPpMqSHD7QyQc1/6ckI9LLkyWUqhnJJXkVwhmI74Aa1Im6QhywAWFMeTBRRL02cwr6k7VKSYOn6yrtzJRCALFGpZ/n58lPrpDxN7W8o+HRQP89wIDy8FyNeEPdmqGFNfMHDvI3oJRN4dGC4H9EkKf/iGuNJia1Bs+MgaG9kKlMHsI6Fkh5uw9KNTvC1llx43VRQJzm26cn1CpRxxRtF4F8lqkpY4tHjxxCitV+98ddW8jdmQYyx+LeueC5wqlO9g2M5L3oXsGMqZ++mDRDa8oQoQAVUSVtimeO8ODXFuVNR8TlupP0Cthgucil63VUZfAD8EHc2zpRSFxfYByDH53uMEinn20uovL6W42fqgboC43HOnR6aVfSANPsBFDlcpZFa2BY5RkcKyYdaLkucy0DKJ946UDfhOu6FNm0GPHq5HcgWkLojNF0dEFgG6J+SGQGiPjxTlHP/zoe61qMlWu+fYRXQnKWZN5Kk0T1TbAk6pKSE6wRLG8ddxvMg+eVpGLT+gAvQdrrkMFvs="

View File

@ -11,6 +11,15 @@ test:
go test -v ./... go test -v ./...
go vet -v go vet -v
.PHONY: check-gofmt
check-gofmt:
$(eval files := $(shell gofmt -l `find -name '*.go' | grep -v vendor`))
$(if $(files),@echo "Some files not gofmt compliant: $(files)"; exit 1, @exit 0)
.PHONY: gofmt
gofmt:
gofmt -w -l `find -name '*.go' | grep -v vendor`
.PHONY: install .PHONY: install
install: build install: build
go install -ldflags "-X github.com/liamg/aminal/version.Version=`git describe --tags`" go install -ldflags "-X github.com/liamg/aminal/version.Version=`git describe --tags`"

View File

@ -167,7 +167,7 @@ func (buffer *Buffer) GetSelectedText() string {
} }
var builder strings.Builder var builder strings.Builder
builder.Grow( int(buffer.terminalState.viewWidth) * (end.Line - start.Line + 1)) // reserve space to minimize allocations builder.Grow(int(buffer.terminalState.viewWidth) * (end.Line - start.Line + 1)) // reserve space to minimize allocations
for row := start.Line; row <= end.Line; row++ { for row := start.Line; row <= end.Line; row++ {
if row >= len(buffer.lines) { if row >= len(buffer.lines) {
@ -206,7 +206,7 @@ func (buffer *Buffer) StartSelection(col uint16, viewRow uint16, mode SelectionM
row := buffer.convertViewLineToRawLine(viewRow) - uint64(buffer.terminalState.scrollLinesFromBottom) row := buffer.convertViewLineToRawLine(viewRow) - uint64(buffer.terminalState.scrollLinesFromBottom)
buffer.selectionMode = mode buffer.selectionMode = mode
buffer.selectionStart = &Position { buffer.selectionStart = &Position{
Col: int(col), Col: int(col),
Line: int(row), Line: int(row),
} }
@ -214,7 +214,7 @@ func (buffer *Buffer) StartSelection(col uint16, viewRow uint16, mode SelectionM
if mode == SelectionChar { if mode == SelectionChar {
buffer.selectionEnd = nil buffer.selectionEnd = nil
} else { } else {
buffer.selectionEnd = &Position { buffer.selectionEnd = &Position{
Col: int(col), Col: int(col),
Line: int(row), Line: int(row),
} }
@ -240,7 +240,7 @@ func (buffer *Buffer) ExtendSelection(col uint16, viewRow uint16, complete bool)
row := buffer.convertViewLineToRawLine(viewRow) - uint64(buffer.terminalState.scrollLinesFromBottom) row := buffer.convertViewLineToRawLine(viewRow) - uint64(buffer.terminalState.scrollLinesFromBottom)
buffer.selectionEnd = &Position { buffer.selectionEnd = &Position{
Col: int(col), Col: int(col),
Line: int(row), Line: int(row),
} }
@ -263,8 +263,8 @@ func (buffer *Buffer) getActualSelection() (*Position, *Position) {
return nil, nil return nil, nil
} }
start := &Position {} start := &Position{}
end := &Position {} end := &Position{}
if comparePositions(buffer.selectionStart, buffer.selectionEnd) >= 0 { if comparePositions(buffer.selectionStart, buffer.selectionEnd) >= 0 {
start.Col = buffer.selectionStart.Col start.Col = buffer.selectionStart.Col

View File

@ -7,6 +7,7 @@ import (
"os" "os"
"os/user" "os/user"
"path/filepath" "path/filepath"
"github.com/liamg/aminal/config" "github.com/liamg/aminal/config"
"github.com/liamg/aminal/version" "github.com/liamg/aminal/version"
) )

View File

@ -64,7 +64,7 @@ func LoadTrueTypeFont(program uint32, r io.Reader, scale float32) (*Font, error)
gl.BindVertexArray(0) gl.BindVertexArray(0)
//create new face to measure glyph dimensions //create new face to measure glyph dimensions
f.ttfFace = truetype.NewFace(f.ttf, &truetype.Options { f.ttfFace = truetype.NewFace(f.ttf, &truetype.Options{
Size: float64(f.scale), Size: float64(f.scale),
DPI: DPI, DPI: DPI,
Hinting: font.HintingFull, Hinting: font.HintingFull,

View File

@ -745,4 +745,3 @@ func (gui *GUI) windowPosChangeCallback(w *glfw.Window, xpos int, ypos int) {
func (gui *GUI) monitorChangeCallback(monitor *glfw.Monitor, event glfw.MonitorEvent) { func (gui *GUI) monitorChangeCallback(monitor *glfw.Monitor, event glfw.MonitorEvent) {
gui.SetDPIScale() gui.SetDPIScale()
} }

View File

@ -5,9 +5,9 @@ import (
"math" "math"
"github.com/go-gl/glfw/v3.2/glfw" "github.com/go-gl/glfw/v3.2/glfw"
"github.com/liamg/aminal/buffer"
"github.com/liamg/aminal/terminal" "github.com/liamg/aminal/terminal"
"time" "time"
"github.com/liamg/aminal/buffer"
) )
func (gui *GUI) glfwScrollCallback(w *glfw.Window, xoff float64, yoff float64) { func (gui *GUI) glfwScrollCallback(w *glfw.Window, xoff float64, yoff float64) {
@ -75,7 +75,7 @@ func (gui *GUI) updateLeftClickCount(x uint16, y uint16) int {
gui.prevLeftClickY = y gui.prevLeftClickY = y
}() }()
if gui.prevLeftClickX == x && gui.prevLeftClickY == y && time.Since(gui.leftClickTime) < time.Millisecond * 500 { if gui.prevLeftClickX == x && gui.prevLeftClickY == y && time.Since(gui.leftClickTime) < time.Millisecond*500 {
gui.leftClickCount++ gui.leftClickCount++
if gui.leftClickCount > 3 { if gui.leftClickCount > 3 {
gui.leftClickCount = 3 gui.leftClickCount = 3

View File

@ -92,7 +92,8 @@ func TestCursorMovement(t *testing.T) {
runMain(func() { runMain(func() {
testFunc := func(term *terminal.Terminal, g *gui.GUI) { testFunc := func(term *terminal.Terminal, g *gui.GUI) {
termRef = term; guiRef = g termRef = term
guiRef = g
sleep() sleep()
send(term, "vttest\n") send(term, "vttest\n")
@ -122,7 +123,8 @@ func TestScreenFeatures(t *testing.T) {
runMain(func() { runMain(func() {
testFunc := func(term *terminal.Terminal, g *gui.GUI) { testFunc := func(term *terminal.Terminal, g *gui.GUI) {
termRef = term; guiRef = g termRef = term
guiRef = g
sleep() sleep()
send(term, "vttest\n") send(term, "vttest\n")

View File

@ -165,9 +165,9 @@ package platform
import "C" import "C"
import ( import (
"errors" "errors"
"os"
"syscall" "syscall"
"unicode/utf16" "unicode/utf16"
"os"
) )
var procsInitSucceeded = false var procsInitSucceeded = false