-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,187 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: gomod | ||
directory: "/" | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 10 | ||
assignees: | ||
- sha1n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name-template: 'v$RESOLVED_VERSION 🌈' | ||
tag-template: 'v$RESOLVED_VERSION' | ||
categories: | ||
- title: '🚀 Features' | ||
labels: | ||
- 'feature' | ||
- 'enhancement' | ||
- title: '🐛 Bug Fixes' | ||
labels: | ||
- 'fix' | ||
- 'bugfix' | ||
- 'bug' | ||
- title: '🧰 Maintenance' | ||
label: 'chore' | ||
change-template: '- $TITLE @$AUTHOR (#$NUMBER)' | ||
change-title-escapes: '\<*_&#@' | ||
version-resolver: | ||
major: | ||
labels: | ||
- 'major' | ||
minor: | ||
labels: | ||
- 'minor' | ||
patch: | ||
labels: | ||
- 'patch' | ||
default: patch | ||
template: | | ||
## Changes | ||
$CHANGES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Go report card | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
refresh: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Go report card | ||
uses: creekorful/[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Go | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.16 | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Test | ||
run: | | ||
go test -v -covermode=count -coverprofile=coverage.out ./... | ||
- name: Coverage | ||
uses: jandelgado/[email protected] | ||
- name: Coveralls | ||
uses: coverallsapp/[email protected] | ||
with: | ||
github-token: ${{ secrets.github_token }} | ||
path-to-lcov: coverage.lcov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Release Drafter | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
# pull_request event is required only for autolabeler | ||
pull_request: | ||
# Only following types are handled by the action, but one can default to all as well | ||
types: [opened, reopened, synchronize] | ||
|
||
jobs: | ||
update_release_draft: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: release-drafter/release-drafter@v5 | ||
# config-name: release-drafter.yml | ||
# disable-autolabeler: true | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,10 @@ | |
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
bin | ||
build | ||
vendor | ||
.vscode | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# Set VERSION to the latest version tag name. Assuming version tags are formatted 'v*' | ||
VERSION := $(shell git describe --always --abbrev=0 --tags --match "v*" $(git rev-list --tags --max-count=1)) | ||
BUILD := $(shell git rev-parse $(VERSION)) | ||
PROJECTNAME := "termite" | ||
# We pass that to the main module to generate the correct help text | ||
PROGRAMNAME := $(PROJECTNAME) | ||
|
||
# Go related variables. | ||
GOBASE := $(shell pwd) | ||
GOPATH := $(GOBASE)/vendor:$(GOBASE) | ||
GOBIN := $(GOBASE)/bin | ||
GOBUILD := $(GOBASE)/build | ||
GOFILES := $(shell find . -type f -name '*.go' -not -path './vendor/*') | ||
GOOS_DARWIN := "darwin" | ||
GOOS_LINUX := "linux" | ||
GOOS_WINDOWS := "windows" | ||
GOARCH_AMD64 := "amd64" | ||
GOARCH_ARM64 := "arm64" | ||
GOARCH_ARM := "arm" | ||
|
||
MODFLAGS=-mod=readonly | ||
|
||
# Use linker flags to provide version/build settings | ||
LDFLAGS=-ldflags "-X=main.Version=$(VERSION) -X=main.Build=$(BUILD) -X=main.ProgramName=$(PROGRAMNAME)" | ||
|
||
# Redirect error output to a file, so we can show it in development mode. | ||
STDERR := $(GOBUILD)/.$(PROJECTNAME)-stderr.txt | ||
|
||
# PID file will keep the process id of the server | ||
PID := $(GOBUILD)/.$(PROJECTNAME).pid | ||
|
||
# Make is verbose in Linux. Make it silent. | ||
MAKEFLAGS += --silent | ||
|
||
default: install lint format test compile | ||
|
||
ci-checks: lint format test | ||
|
||
install: go-get | ||
|
||
format: go-format | ||
|
||
lint: go-lint | ||
|
||
compile: | ||
@[ -d $(GOBUILD) ] || mkdir -p $(GOBUILD) | ||
@-touch $(STDERR) | ||
@-rm $(STDERR) | ||
@-$(MAKE) -s go-build #2> $(STDERR) | ||
#@cat $(STDERR) | sed -e '1s/.*/\nError:\n/' | sed 's/make\[.*/ /' | sed "/^/s/^/ /" 1>&2 | ||
|
||
|
||
test: install go-test | ||
|
||
cover: install go-cover | ||
|
||
clean: | ||
@-rm $(GOBIN)/$(PROGRAMNAME)* 2> /dev/null | ||
@-$(MAKE) go-clean | ||
|
||
go-lint: | ||
@echo " > Linting source files..." | ||
go vet $(MODFLAGS) -c=10 `go list $(MODFLAGS) ./...` | ||
|
||
go-format: | ||
@echo " > Formating source files..." | ||
gofmt -s -w $(GOFILES) | ||
|
||
go-build: go-get go-build-linux-amd64 go-build-linux-arm64 go-build-darwin-amd64 go-build-windows-amd64 go-build-windows-arm | ||
|
||
go-test: | ||
go test $(MODFLAGS) `go list $(MODFLAGS) ./...` | ||
|
||
go-cover: | ||
go test $(MODFLAGS) -coverprofile=$(GOBUILD)/.coverprof `go list $(MODFLAGS) ./...` | ||
go tool cover -html=$(GOBUILD)/.coverprof -o $(GOBUILD)/coverage.html | ||
@open $(GOBUILD)/coverage.html | ||
|
||
go-build-linux-amd64: | ||
@echo " > Building linux amd64 binaries..." | ||
@GOPATH=$(GOPATH) GOOS=$(GOOS_LINUX) GOARCH=$(GOARCH_AMD64) GOBIN=$(GOBIN) go build $(MODFLAGS) $(LDFLAGS) -o $(GOBIN)/$(PROGRAMNAME)-$(GOOS_LINUX)-$(GOARCH_AMD64) $(GOBASE)/demo | ||
|
||
go-build-linux-arm64: | ||
@echo " > Building linux arm64 binaries..." | ||
@GOPATH=$(GOPATH) GOOS=$(GOOS_LINUX) GOARCH=$(GOARCH_ARM64) GOBIN=$(GOBIN) go build $(MODFLAGS) $(LDFLAGS) -o $(GOBIN)/$(PROGRAMNAME)-$(GOOS_LINUX)-$(GOARCH_ARM64) $(GOBASE)/demo | ||
|
||
go-build-darwin-amd64: | ||
@echo " > Building darwin binaries..." | ||
@GOPATH=$(GOPATH) GOOS=$(GOOS_DARWIN) GOARCH=$(GOARCH_AMD64) GOBIN=$(GOBIN) go build $(MODFLAGS) $(LDFLAGS) -o $(GOBIN)/$(PROGRAMNAME)-$(GOOS_DARWIN)-$(GOARCH_AMD64) $(GOBASE)/demo | ||
|
||
go-build-windows-amd64: | ||
@echo " > Building windows amd64 binaries..." | ||
@GOPATH=$(GOPATH) GOOS=$(GOOS_WINDOWS) GOARCH=$(GOARCH_AMD64) GOBIN=$(GOBIN) go build $(MODFLAGS) $(LDFLAGS) -o $(GOBIN)/$(PROGRAMNAME)-$(GOOS_WINDOWS)-$(GOARCH_AMD64).exe $(GOBASE)/demo | ||
|
||
go-build-windows-arm: | ||
@echo " > Building windows arm binaries..." | ||
@GOPATH=$(GOPATH) GOOS=$(GOOS_WINDOWS) GOARCH=$(GOARCH_ARM) GOBIN=$(GOBIN) go build $(MODFLAGS) $(LDFLAGS) -o $(GOBIN)/$(PROGRAMNAME)-$(GOOS_WINDOWS)-$(GOARCH_ARM).exe $(GOBASE)/demo | ||
|
||
go-generate: | ||
@echo " > Generating dependency files..." | ||
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go generate $(generate) | ||
|
||
go-get: | ||
@echo " > Checking if there is any missing dependencies..." | ||
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go mod tidy | ||
|
||
go-install: | ||
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go install $(GOFILES) | ||
|
||
go-clean: | ||
@echo " > Cleaning build cache" | ||
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go clean $(MODFLAGS) $(GOBASE) | ||
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go clean -modcache | ||
|
||
|
||
|
||
.PHONY: help | ||
all: help | ||
help: Makefile | ||
@echo | ||
@echo " Choose a command run in "$(PROJECTNAME)":" | ||
@echo | ||
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' | ||
@echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
# termite | ||
[](https://github.com/sha1n/termite/actions/workflows/go.yml) | ||
[](https://goreportcard.com/report/github.com/sha1n/termite) | ||
[](https://github.com/sha1n/termite/actions/workflows/go-report-card.yml) | ||
[](https://github.com/sha1n/termite/actions/workflows/release-drafter.yml) | ||
[](https://opensource.org/licenses/MIT) | ||
|
||
|
||
# termite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package termite | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// Cursor represents a terminal cursor | ||
type Cursor interface { | ||
Up(l int) | ||
Down(l int) | ||
Hide() | ||
Show() | ||
} | ||
|
||
type cursor struct { | ||
t Terminal | ||
} | ||
|
||
// NewCursor returns a new cursor for the specified terminal | ||
func NewCursor(t Terminal) Cursor { | ||
return &cursor{ | ||
t: t, | ||
} | ||
} | ||
|
||
func (c *cursor) Up(lines int) { | ||
c.t.Print(fmt.Sprintf("\033[%dA", lines)) | ||
} | ||
|
||
func (c *cursor) Down(lines int) { | ||
c.t.Print(fmt.Sprintf("\033[%dB", lines)) | ||
} | ||
|
||
func (c *cursor) Hide() { | ||
c.t.Print("\033[?25l") | ||
} | ||
|
||
func (c *cursor) Show() { | ||
c.t.Print("\033[?25h") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package termite | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"sync" | ||
) | ||
|
||
type fakeTerm struct { | ||
Out *bytes.Buffer | ||
Err *bytes.Buffer | ||
outLock *sync.Mutex | ||
width int | ||
height int | ||
} | ||
|
||
// NewFakeTerminal ... | ||
func NewFakeTerminal(width, height int) Terminal { | ||
return &fakeTerm{ | ||
Out: new(bytes.Buffer), | ||
Err: new(bytes.Buffer), | ||
outLock: &sync.Mutex{}, | ||
width: width, | ||
height: height, | ||
} | ||
} | ||
|
||
func (t *fakeTerm) Width() (width int) { | ||
return t.width | ||
} | ||
|
||
func (t *fakeTerm) Height() (height int) { | ||
return t.height | ||
} | ||
|
||
func (t *fakeTerm) StdOut() io.Writer { | ||
return t.Out | ||
} | ||
|
||
func (t *fakeTerm) StdErr() io.Writer { | ||
return t.Err | ||
} | ||
|
||
func (t *fakeTerm) Print(e interface{}) { | ||
t.writeString(fmt.Sprintf("%v", e)) | ||
} | ||
|
||
func (t *fakeTerm) Println(e interface{}) { | ||
t.writeString(fmt.Sprintf("%v\r\n", e)) | ||
} | ||
|
||
func (t *fakeTerm) EraseLine() { | ||
t.writeString(TermControlEraseLine) | ||
} | ||
|
||
func (t *fakeTerm) OverwriteLine(e interface{}) { | ||
t.Print(fmt.Sprintf("%s%v", TermControlEraseLine, e)) | ||
} | ||
|
||
func (t *fakeTerm) Clear() { | ||
t.Out.Reset() | ||
} | ||
|
||
func (t *fakeTerm) writeString(s string) (n int) { | ||
t.outLock.Lock() | ||
defer t.outLock.Unlock() | ||
|
||
if n, err := t.Out.WriteString(s); err == nil { | ||
return n | ||
} | ||
|
||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module github.com/sha1n/termite | ||
|
||
go 1.15 | ||
|
||
require ( | ||
github.com/fatih/color v1.12.0 | ||
github.com/mattn/go-isatty v0.0.12 | ||
github.com/stretchr/testify v1.7.0 | ||
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a | ||
) |
Oops, something went wrong.