* 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 == '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="

View File

@ -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`"

View File

@ -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

View File

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

View File

@ -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,
}

View File

@ -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,

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) {
gui.SetDPIScale()
}

View File

@ -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

View File

@ -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")

View File

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