
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
100 lines
1.8 KiB
Go
100 lines
1.8 KiB
Go
package liner
|
|
|
|
import "unicode"
|
|
|
|
// These character classes are mostly zero width (when combined).
|
|
// A few might not be, depending on the user's font. Fixing this
|
|
// is non-trivial, given that some terminals don't support
|
|
// ANSI DSR/CPR
|
|
var zeroWidth = []*unicode.RangeTable{
|
|
unicode.Mn,
|
|
unicode.Me,
|
|
unicode.Cc,
|
|
unicode.Cf,
|
|
}
|
|
|
|
var doubleWidth = []*unicode.RangeTable{
|
|
unicode.Han,
|
|
unicode.Hangul,
|
|
unicode.Hiragana,
|
|
unicode.Katakana,
|
|
}
|
|
|
|
// countGlyphs considers zero-width characters to be zero glyphs wide,
|
|
// and members of Chinese, Japanese, and Korean scripts to be 2 glyphs wide.
|
|
func countGlyphs(s []rune) int {
|
|
n := 0
|
|
for _, r := range s {
|
|
// speed up the common case
|
|
if r < 127 {
|
|
n++
|
|
continue
|
|
}
|
|
|
|
switch {
|
|
case unicode.IsOneOf(zeroWidth, r):
|
|
case unicode.IsOneOf(doubleWidth, r):
|
|
n += 2
|
|
default:
|
|
n++
|
|
}
|
|
}
|
|
return n
|
|
}
|
|
|
|
func countMultiLineGlyphs(s []rune, columns int, start int) int {
|
|
n := start
|
|
for _, r := range s {
|
|
if r < 127 {
|
|
n++
|
|
continue
|
|
}
|
|
switch {
|
|
case unicode.IsOneOf(zeroWidth, r):
|
|
case unicode.IsOneOf(doubleWidth, r):
|
|
n += 2
|
|
// no room for a 2-glyphs-wide char in the ending
|
|
// so skip a column and display it at the beginning
|
|
if n%columns == 1 {
|
|
n++
|
|
}
|
|
default:
|
|
n++
|
|
}
|
|
}
|
|
return n
|
|
}
|
|
|
|
func getPrefixGlyphs(s []rune, num int) []rune {
|
|
p := 0
|
|
for n := 0; n < num && p < len(s); p++ {
|
|
// speed up the common case
|
|
if s[p] < 127 {
|
|
n++
|
|
continue
|
|
}
|
|
if !unicode.IsOneOf(zeroWidth, s[p]) {
|
|
n++
|
|
}
|
|
}
|
|
for p < len(s) && unicode.IsOneOf(zeroWidth, s[p]) {
|
|
p++
|
|
}
|
|
return s[:p]
|
|
}
|
|
|
|
func getSuffixGlyphs(s []rune, num int) []rune {
|
|
p := len(s)
|
|
for n := 0; n < num && p > 0; p-- {
|
|
// speed up the common case
|
|
if s[p-1] < 127 {
|
|
n++
|
|
continue
|
|
}
|
|
if !unicode.IsOneOf(zeroWidth, s[p-1]) {
|
|
n++
|
|
}
|
|
}
|
|
return s[p:]
|
|
}
|