
This commit includes updates that affects the build, testing, and deployment of Tile38. - The root level build.sh has been broken up into multiple scripts and placed in the "scripts" directory. - The vendor directory has been updated to follow the Go modules rules, thus `make` should work on isolated environments. Also some vendored packages may have been updated to a later version, if needed. - The Makefile has been updated to allow for making single binaries such as `make tile38-server`. There is some scaffolding during the build process, so from now on all binaries should be made using make. For example, to run a development version of the tile38-cli binary, do this: make tile38-cli && ./tile38-cli not this: go run cmd/tile38-cli/main.go - Travis.CI docker push script has been updated to address a change to Docker's JSON repo meta output, which in turn fixes a bug where new Tile38 versions were not being properly pushed to Docker
80 lines
1.5 KiB
Go
80 lines
1.5 KiB
Go
// +build linux darwin openbsd freebsd netbsd
|
|
|
|
package liner
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
func (s *State) cursorPos(x int) {
|
|
if s.useCHA {
|
|
// 'G' is "Cursor Character Absolute (CHA)"
|
|
fmt.Printf("\x1b[%dG", x+1)
|
|
} else {
|
|
// 'C' is "Cursor Forward (CUF)"
|
|
fmt.Print("\r")
|
|
if x > 0 {
|
|
fmt.Printf("\x1b[%dC", x)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (s *State) eraseLine() {
|
|
fmt.Print("\x1b[0K")
|
|
}
|
|
|
|
func (s *State) eraseScreen() {
|
|
fmt.Print("\x1b[H\x1b[2J")
|
|
}
|
|
|
|
func (s *State) moveUp(lines int) {
|
|
fmt.Printf("\x1b[%dA", lines)
|
|
}
|
|
|
|
func (s *State) moveDown(lines int) {
|
|
fmt.Printf("\x1b[%dB", lines)
|
|
}
|
|
|
|
func (s *State) emitNewLine() {
|
|
fmt.Print("\n")
|
|
}
|
|
|
|
type winSize struct {
|
|
row, col uint16
|
|
xpixel, ypixel uint16
|
|
}
|
|
|
|
func (s *State) getColumns() bool {
|
|
var ws winSize
|
|
ok, _, _ := syscall.Syscall(syscall.SYS_IOCTL, uintptr(syscall.Stdout),
|
|
syscall.TIOCGWINSZ, uintptr(unsafe.Pointer(&ws)))
|
|
if int(ok) < 0 {
|
|
return false
|
|
}
|
|
s.columns = int(ws.col)
|
|
if cursorColumn && s.columns > 1 {
|
|
s.columns--
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (s *State) checkOutput() {
|
|
// xterm is known to support CHA
|
|
if strings.Contains(strings.ToLower(os.Getenv("TERM")), "xterm") {
|
|
s.useCHA = true
|
|
return
|
|
}
|
|
|
|
// The test for functional ANSI CHA is unreliable (eg the Windows
|
|
// telnet command does not support reading the cursor position with
|
|
// an ANSI DSR request, despite setting TERM=ansi)
|
|
|
|
// Assume CHA isn't supported (which should be safe, although it
|
|
// does result in occasional visible cursor jitter)
|
|
s.useCHA = false
|
|
}
|