You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fx/utils.go

51 lines
890 B
Go

10 months ago
package main
9 months ago
import (
"regexp"
)
var identifier = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_]*$`)
10 months ago
func isHexDigit(ch byte) bool {
return (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F')
}
func isDigit(ch byte) bool {
return ch >= '0' && ch <= '9'
}
10 months ago
9 months ago
func max(i, j int) int {
if i > j {
return i
}
return j
}
9 months ago
func prettyPrint(b []byte, selected bool, isChunk bool) []byte {
10 months ago
if len(b) == 0 {
9 months ago
return b
10 months ago
}
9 months ago
if selected {
return currentTheme.Cursor(b)
} else {
if isChunk {
return currentTheme.String(b)
}
switch b[0] {
case '"':
return currentTheme.String(b)
case 't', 'f':
return currentTheme.Boolean(b)
case 'n':
return currentTheme.Null(b)
case '{', '[', '}', ']':
return currentTheme.Syntax(b)
default:
if isDigit(b[0]) || b[0] == '-' {
return currentTheme.Number(b)
}
return noColor(b)
10 months ago
}
}
}