SHARE
TWEET

Untitled

a guest Mar 23rd, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "bufio"
  5.     "fmt"
  6.     "os"
  7.     "log"
  8.     "regexp"
  9. )
  10.  
  11. func repl1(hex []byte) []byte {
  12.     return []byte(fmt.Sprintf("\x1B[38;5;%dm%c%c\x1B[0m", hex[0] + 0x10*hex[1], hex[0], hex[1]))
  13. }
  14.  
  15. func repl(line []byte) []byte {
  16.     hexet, _ := regexp.Compile("[0-9a-fA-F][0-9a-fA-F]")
  17.     return hexet.ReplaceAllFunc(line, repl1)
  18. }
  19.  
  20. func main() {
  21.     hexets, _ := regexp.Compile("([^0-9a-zA-Z]|^|0x)([0-9a-fA-F][0-9a-fA-F])+([^0-9a-zA-Z]|$)")
  22.    
  23.     scanner := bufio.NewScanner(os.Stdin)
  24.     for scanner.Scan() {
  25.         line := scanner.Bytes()
  26.         line = hexets.ReplaceAllFunc(line, repl)
  27.         fmt.Println(string(line))
  28.     }
  29.    
  30.     if err := scanner.Err(); err != nil {
  31.         log.Println(err)
  32.     }
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top