Created
March 18, 2019 23:39
-
-
Save rain-1/2aedd55ca3317079198c7b5bf2af9fd5 to your computer and use it in GitHub Desktop.
checksum colorizer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
go build
then ;sha256sum * | ./foo
. colors the hashes for easy comparison.