From 35193b79816cd3fc75d1e03a4f02e0fa1b1debaa Mon Sep 17 00:00:00 2001 From: Menno Finlay-Smits Date: Fri, 15 Feb 2019 05:45:53 +1300 Subject: [PATCH] Gofmt (#216) * 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 --- .travis.yml | 1 + Makefile | 9 +++++++++ buffer/buffer.go | 24 ++++++++++++------------ buffer/buffer_test.go | 2 +- config.go | 1 + config/defaults.go | 6 +++--- glfont/truetype.go | 2 +- gui/gui.go | 1 - gui/mouse.go | 6 +++--- main_test.go | 6 ++++-- platform/darwinLaunch.go | 2 +- platform/winLaunch.go | 2 +- platform/winproc.go | 2 +- 13 files changed, 38 insertions(+), 26 deletions(-) diff --git a/.travis.yml b/.travis.yml index 27edb20..652ce56 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,6 +29,7 @@ script: - 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 windows-cross-compile-travis; fi +- if [[ $TRAVIS_OS_NAME == 'linux' ]]; then make check-gofmt; fi env: global: - secure: "pdRpTOGQSUgbC9tK37voxUYJHMWDPJEmdMhNBsljpP9VnxxbR6JEFwvOQEmUHGlsYv8jma6a17jE60ngVQk8QP12cPh48i2bdbVgym/zTUOKFawCtPAzs8i7evh0di5eZ3uoyc42kG4skc+ePuVHbXC8jDxwaPpMqSHD7QyQc1/6ckI9LLkyWUqhnJJXkVwhmI74Aa1Im6QhywAWFMeTBRRL02cwr6k7VKSYOn6yrtzJRCALFGpZ/n58lPrpDxN7W8o+HRQP89wIDy8FyNeEPdmqGFNfMHDvI3oJRN4dGC4H9EkKf/iGuNJia1Bs+MgaG9kKlMHsI6Fkh5uw9KNTvC1llx43VRQJzm26cn1CpRxxRtF4F8lqkpY4tHjxxCitV+98ddW8jdmQYyx+LeueC5wqlO9g2M5L3oXsGMqZ++mDRDa8oQoQAVUSVtimeO8ODXFuVNR8TlupP0Cthgucil63VUZfAD8EHc2zpRSFxfYByDH53uMEinn20uovL6W42fqgboC43HOnR6aVfSANPsBFDlcpZFa2BY5RkcKyYdaLkucy0DKJ946UDfhOu6FNm0GPHq5HcgWkLojNF0dEFgG6J+SGQGiPjxTlHP/zoe61qMlWu+fYRXQnKWZN5Kk0T1TbAk6pKSE6wRLG8ddxvMg+eVpGLT+gAvQdrrkMFvs=" diff --git a/Makefile b/Makefile index 9749f29..8dc66ff 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,15 @@ test: go test -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 install: build go install -ldflags "-X github.com/liamg/aminal/version.Version=`git describe --tags`" diff --git a/buffer/buffer.go b/buffer/buffer.go index f5c657b..ef3c21e 100644 --- a/buffer/buffer.go +++ b/buffer/buffer.go @@ -52,12 +52,12 @@ func comparePositions(pos1 *Position, pos2 *Position) int { // NewBuffer creates a new terminal buffer func NewBuffer(terminalState *TerminalState) *Buffer { b := &Buffer{ - lines: []Line{}, - selectionStart: nil, - selectionEnd: nil, - selectionMode: SelectionChar, - isSelectionComplete: true, - terminalState: terminalState, + lines: []Line{}, + selectionStart: nil, + selectionEnd: nil, + selectionMode: SelectionChar, + isSelectionComplete: true, + terminalState: terminalState, } return b } @@ -167,7 +167,7 @@ func (buffer *Buffer) GetSelectedText() string { } 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++ { 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) buffer.selectionMode = mode - buffer.selectionStart = &Position { + buffer.selectionStart = &Position{ Col: int(col), Line: int(row), } @@ -214,7 +214,7 @@ func (buffer *Buffer) StartSelection(col uint16, viewRow uint16, mode SelectionM if mode == SelectionChar { buffer.selectionEnd = nil } else { - buffer.selectionEnd = &Position { + buffer.selectionEnd = &Position{ Col: int(col), 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) - buffer.selectionEnd = &Position { + buffer.selectionEnd = &Position{ Col: int(col), Line: int(row), } @@ -263,8 +263,8 @@ func (buffer *Buffer) getActualSelection() (*Position, *Position) { return nil, nil } - start := &Position {} - end := &Position {} + start := &Position{} + end := &Position{} if comparePositions(buffer.selectionStart, buffer.selectionEnd) >= 0 { start.Col = buffer.selectionStart.Col diff --git a/buffer/buffer_test.go b/buffer/buffer_test.go index bd9287a..ad866ec 100644 --- a/buffer/buffer_test.go +++ b/buffer/buffer_test.go @@ -710,4 +710,4 @@ func TestSelectingAfterText(t *testing.T) { assert.Equal(t, start.Line, 3) assert.Equal(t, end.Col, 79) assert.Equal(t, end.Line, 3) -} \ No newline at end of file +} diff --git a/config.go b/config.go index fb1e879..8a18793 100644 --- a/config.go +++ b/config.go @@ -7,6 +7,7 @@ import ( "os" "os/user" "path/filepath" + "github.com/liamg/aminal/config" "github.com/liamg/aminal/version" ) diff --git a/config/defaults.go b/config/defaults.go index 9d3f5fd..23f4b26 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -26,9 +26,9 @@ var DefaultConfig = Config{ White: strToColourNoErr("#ffffff"), Selection: strToColourNoErr("#333366"), }, - KeyMapping: KeyMappingConfig(map[string]string{}), - SearchURL: "https://www.google.com/search?q=$QUERY", - MaxLines: 1000, + KeyMapping: KeyMappingConfig(map[string]string{}), + SearchURL: "https://www.google.com/search?q=$QUERY", + MaxLines: 1000, CopyAndPasteWithMouse: true, } diff --git a/glfont/truetype.go b/glfont/truetype.go index e5dc492..d1d273a 100644 --- a/glfont/truetype.go +++ b/glfont/truetype.go @@ -64,7 +64,7 @@ func LoadTrueTypeFont(program uint32, r io.Reader, scale float32) (*Font, error) gl.BindVertexArray(0) //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), DPI: DPI, Hinting: font.HintingFull, diff --git a/gui/gui.go b/gui/gui.go index 71a1df6..ea4c2a7 100644 --- a/gui/gui.go +++ b/gui/gui.go @@ -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) { gui.SetDPIScale() } - diff --git a/gui/mouse.go b/gui/mouse.go index b29987b..5113b51 100644 --- a/gui/mouse.go +++ b/gui/mouse.go @@ -5,9 +5,9 @@ import ( "math" "github.com/go-gl/glfw/v3.2/glfw" + "github.com/liamg/aminal/buffer" "github.com/liamg/aminal/terminal" "time" - "github.com/liamg/aminal/buffer" ) func (gui *GUI) glfwScrollCallback(w *glfw.Window, xoff float64, yoff float64) { @@ -27,7 +27,7 @@ func (gui *GUI) getHandCursor() *glfw.Cursor { return gui.handCursor } -func (gui *GUI) getArrowCursor() *glfw.Cursor { +func (gui *GUI) getArrowCursor() *glfw.Cursor { if gui.arrowCursor == nil { gui.arrowCursor = glfw.CreateStandardCursor(glfw.ArrowCursor) } @@ -75,7 +75,7 @@ func (gui *GUI) updateLeftClickCount(x uint16, y uint16) int { 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++ if gui.leftClickCount > 3 { gui.leftClickCount = 3 diff --git a/main_test.go b/main_test.go index 5856eb8..d3422e0 100644 --- a/main_test.go +++ b/main_test.go @@ -92,7 +92,8 @@ func TestCursorMovement(t *testing.T) { runMain(func() { testFunc := func(term *terminal.Terminal, g *gui.GUI) { - termRef = term; guiRef = g + termRef = term + guiRef = g sleep() send(term, "vttest\n") @@ -122,7 +123,8 @@ func TestScreenFeatures(t *testing.T) { runMain(func() { testFunc := func(term *terminal.Terminal, g *gui.GUI) { - termRef = term; guiRef = g + termRef = term + guiRef = g sleep() send(term, "vttest\n") diff --git a/platform/darwinLaunch.go b/platform/darwinLaunch.go index 1b2dd44..c4c459f 100644 --- a/platform/darwinLaunch.go +++ b/platform/darwinLaunch.go @@ -8,4 +8,4 @@ import ( func LaunchTarget(target string) error { return exec.Command("open", target).Run() -} \ No newline at end of file +} diff --git a/platform/winLaunch.go b/platform/winLaunch.go index 55fef4d..432ea48 100644 --- a/platform/winLaunch.go +++ b/platform/winLaunch.go @@ -8,4 +8,4 @@ import ( func LaunchTarget(target string) error { return w32.ShellExecute(0, "", target, "", "", w32.SW_SHOW) -} \ No newline at end of file +} diff --git a/platform/winproc.go b/platform/winproc.go index d816c41..5cd4fbd 100644 --- a/platform/winproc.go +++ b/platform/winproc.go @@ -165,9 +165,9 @@ package platform import "C" import ( "errors" + "os" "syscall" "unicode/utf16" - "os" ) var procsInitSucceeded = false