Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.61 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. (ns ^{:doc "Add some colour to your output"
  2.       :author "Josh Comer <joshjcomer@gmail.com>"}
  3.     cljcolour)
  4.  
  5. (def black {:fore "02;30" :back "02;40"})
  6. (def red {:fore "02;31" :back "02;41"})
  7. (def green {:fore "02;32" :back "02;42"})
  8. (def yellow {:fore "02;33" :back "02;43"})
  9. (def blue {:fore "02;34" :back "02;44"})
  10. (def purple {:fore "02;35" :back "02;45"})
  11. (def cyan {:fore "02;36" :back "02;46"})
  12. (def lightgrey {:fore "02;37" :back "02;47"})
  13. (def darkgrey {:fore "01;30" :back "01;40"})
  14. (def boldred {:fore "01;31" :back "01;41"})
  15. (def boldgreen {:fore "01;32" :back "01;42"})
  16. (def boldyellow {:fore "01;33" :back "01;43"})
  17. (def boldblue {:fore "01;34" :back "01;44"})
  18. (def boldpurple {:fore "01;35" :back "01;45"})
  19. (def boldcyan {:fore "01;36" :back "01;46"})
  20. (def white {:fore "01;37" :back "01;47"})
  21.  
  22. (defn create-new-colour
  23.         "Create a new colour from existing colours"
  24.         [{foreground :fore} {background :back}]
  25.         {:fore foreground :back background})
  26.  
  27. (defn add-foreground-colour
  28.         "Add foreground colour to the string"
  29.         [{foreground :fore} text]
  30.         (str "\u001b[" foreground "m" text "\u001b[m"))
  31.  
  32. (defn add-background-colour
  33.         "Add background colour to the string"
  34.         [{background :back} text]
  35.         (str "\u001b[" background "m" text "\u001b[m"))
  36.  
  37. (defn add-colour
  38.         "Add foreground and background colours to a string"
  39.         [{foreground :fore} {background :back} text]
  40.         (str "\u001b[" background ";" foreground "m" text "\u001b[m"))
  41.  
  42. (defn create-painter
  43.         "Partially apply colours to the add-colour function"
  44.         ([foreground background]
  45.         (partial add-colour foreground background))
  46.         ([custom-colour]
  47.         (partial add-colour custom-colour custom-colour)))