fx/new/utils.go

38 lines
739 B
Go
Raw Normal View History

2023-09-07 20:53:51 +00:00
package main
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'
}
2023-09-08 07:56:12 +00:00
2023-09-11 11:16:10 +00:00
func prettyPrint(b []byte, selected bool, isChunk bool) []byte {
2023-09-08 07:56:12 +00:00
if len(b) == 0 {
2023-09-11 11:16:10 +00:00
return b
2023-09-08 07:56:12 +00:00
}
2023-09-11 11:16:10 +00:00
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)
2023-09-08 07:56:12 +00:00
}
}
}