checksum colorizer
package main | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
"log" | |
"regexp" | |
) | |
func repl1(hex []byte) []byte { | |
return []byte(fmt.Sprintf("\x1B[38;5;%dm%c%c\x1B[0m", hex[0] + 0x10*hex[1], hex[0], hex[1])) | |
} | |
func repl(line []byte) []byte { | |
hexet, _ := regexp.Compile("[0-9a-fA-F][0-9a-fA-F]") | |
return hexet.ReplaceAllFunc(line, repl1) | |
} | |
func main() { | |
hexets, _ := regexp.Compile("([^0-9a-zA-Z]|^|0x)([0-9a-fA-F][0-9a-fA-F])+([^0-9a-zA-Z]|$)") | |
scanner := bufio.NewScanner(os.Stdin) | |
for scanner.Scan() { | |
line := scanner.Bytes() | |
line = hexets.ReplaceAllFunc(line, repl) | |
fmt.Println(string(line)) | |
} | |
if err := scanner.Err(); err != nil { | |
log.Println(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
go build
then ;sha256sum * | ./foo
. colors the hashes for easy comparison.