import (
"errors"
+ "fmt"
"os"
"os/user"
"path/filepath"
"regexp"
+ "runtime"
"strconv"
"strings"
"time"
+ "unicode"
"unicode/utf8"
+ "github.com/blang/semver"
runewidth "github.com/mattn/go-runewidth"
)
+var (
+ // These variables should be set by the linker when compiling
+
+ // Version is the version number or commit hash
+ Version = "0.0.0-unknown"
+ // Semantic version
+ SemVersion semver.Version
+ // CommitHash is the commit this version was built on
+ CommitHash = "Unknown"
+ // CompileDate is the date this binary was compiled on
+ CompileDate = "Unknown"
+ // Debug logging
+ Debug = "ON"
+ // FakeCursor is used to disable the terminal cursor and have micro
+ // draw its own (enabled for windows consoles where the cursor is slow)
+ FakeCursor = false
+)
+
+func init() {
+ var err error
+ SemVersion, err = semver.Make(Version)
+ if err != nil {
+ fmt.Println("Invalid version: ", Version, err)
+ }
+
+ if runtime.GOOS == "windows" {
+ FakeCursor = true
+ }
+}
+
// SliceEnd returns a byte slice where the index is a rune index
// Slices off the start of the slice
func SliceEnd(slc []byte, index int) []byte {
}
// IsWordChar returns whether or not the string is a 'word character'
-// If it is a unicode character, then it does not match
-// Word characters are defined as [A-Za-z0-9_]
+// Word characters are defined as numbers, letters, or '_'
func IsWordChar(r rune) bool {
- return (r >= '0' && r <= '9') || (r >= 'A' && r <= 'Z') || (r >= 'a' && r <= 'z') || (r == '_')
+ return unicode.IsLetter(r) || unicode.IsNumber(r) || r == '_'
}
// Spaces returns a string with n spaces
// IsWhitespace returns true if the given rune is a space, tab, or newline
func IsWhitespace(c rune) bool {
- return c == ' ' || c == '\t' || c == '\n'
+ return unicode.IsSpace(c)
}
-// IsStrWhitespace returns true if the given string is all whitespace
-func IsStrWhitespace(str string) bool {
- // Range loop for unicode correctness
- for _, c := range str {
- if !IsWhitespace(c) {
+// IsBytesWhitespace returns true if the given bytes are all whitespace
+func IsBytesWhitespace(b []byte) bool {
+ for _, c := range b {
+ if !IsWhitespace(rune(c)) {
return false
}
}
return path, nil
}
-// TODO: consider changing because of snap segfault
// ReplaceHome takes a path as input and replaces ~ at the start of the path with the user's
// home directory. Does nothing if the path does not start with '~'.
func ReplaceHome(path string) (string, error) {
// coordinate (this is necessary because tabs are 1 char but
// 4 visual spaces)
func GetCharPosInLine(b []byte, visualPos int, tabsize int) int {
-
// Scan rune by rune until we exceed the visual width that we are
// looking for. Then we can return the character position we have found
i := 0 // char pos
}
return val
}
+
+func IsNonAlphaNumeric(c rune) bool {
+ return !unicode.IsLetter(c) && !unicode.IsNumber(c)
+}
+
+func ParseSpecial(s string) string {
+ return strings.Replace(s, "\\t", "\t", -1)
+}
+
+// String converts a byte array to a string (for lua plugins)
+func String(s []byte) string {
+ return string(s)
+}