gnu: Properly credit Konrad Hinsen.
[jackhill/guix/guix.git] / guix / colors.scm
index 30ad231..3031f54 100644 (file)
@@ -30,6 +30,9 @@
             color?
 
             colorize-string
+            highlight
+            dim
+
             color-rules
             color-output?
             isatty?*))
@@ -128,10 +131,20 @@ that subsequent output will not have any colors in effect."
 
 (define (color-output? port)
   "Return true if we should write colored output to PORT."
-  (and (not (getenv "INSIDE_EMACS"))
-       (not (getenv "NO_COLOR"))
+  (and (not (getenv "NO_COLOR"))
        (isatty?* port)))
 
+(define (coloring-procedure color)
+  "Return a procedure that applies COLOR to the given string."
+  (lambda* (str #:optional (port (current-output-port)))
+    "Return STR with extra ANSI color attributes if PORT supports it."
+    (if (color-output? port)
+        (colorize-string str color)
+        str)))
+
+(define highlight (coloring-procedure (color BOLD)))
+(define dim (coloring-procedure (color DARK)))
+
 (define (colorize-matches rules)
   "Return a procedure that, when passed a string, returns that string
 colorized according to RULES.  RULES must be a list of tuples like: