46fd11ae3808

Merge
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Thu, 13 Jun 2024 12:30:10 -0400
parents cf74bfa5845a
children eb9f31c299b8
branches/tags (none)
files lisp/batchcolor.lisp

Changes

--- a/lisp/batchcolor.lisp	Wed Jun 12 14:42:07 2024 -0400
+++ b/lisp/batchcolor.lisp	Thu Jun 13 12:30:10 2024 -0400
@@ -10,6 +10,7 @@
 ;;;; Configuration ------------------------------------------------------------
 (defparameter *start* 0)
 (defparameter *dark* t)
+(defparameter *multi* t)
 
 
 ;;;; Errors -------------------------------------------------------------------
@@ -67,10 +68,14 @@
 
 (defun find-color (string)
   (gethash string *explicits*
-           (let ((colors (if *dark* *dark-colors* *light-colors*)))
-             (aref colors
-                   (mod (+ (djb2 string) *start*)
-                        (length colors))))))
+           (if *multi*
+             (let ((colors (if *dark* *dark-colors* *light-colors*)))
+               (aref colors
+                     (mod (+ (djb2 string) *start*)
+                          (length colors))))
+             (if *dark*
+               (rgb-code 5 2 3)
+               (rgb-code 2 0 2)))))
 
 (defun ansi-color-start (color)
   (format nil "~C[38;5;~Dm" #\Escape color))
@@ -128,6 +133,13 @@
     (return-from parse-explicit (cons string (rgb-code r g b))))
   (error 'malformed-explicit :spec spec))
 
+(adopt:defparameters (*option-multicolor* *option-no-multicolor*)
+  (adopt:make-boolean-options 'multicolor
+    :help "Use different colors for different matches (the default)."
+    :help-no "Use a single color for everything (a useful kludge)."
+    :long "multicolor"
+    :short #\m
+    :initial-value t))
 
 (adopt:defparameters (*option-randomize* *option-no-randomize*)
   (adopt:make-boolean-options 'randomize
@@ -187,6 +199,9 @@
   "If no FILEs are given, standard input will be used.  A file of - stands for ~
    standard input as well.~@
    ~@
+   As a handy kludge, the --no-multicolor option can be used to highlight ~
+   everything in a single color.~@
+   ~@
    Overlapping capturing groups are not supported because it's not clear what ~
    the result should be.  For example: what should ((f)oo|(b)oo) highlight when ~
    matched against 'foo'?  Should it highlight 'foo' in one color?  The 'f' in ~
@@ -224,7 +239,9 @@
                                                  *option-no-randomize*
                                                  *option-dark*
                                                  *option-light*
-                                                 *option-explicit*)))))
+                                                 *option-explicit*
+                                                 *option-multicolor*
+                                                 *option-no-multicolor*)))))
 
 
 (defmacro exit-on-ctrl-c (&body body)
@@ -237,7 +254,8 @@
   (setf *start* (if (gethash 'randomize options)
                   (random 256 (make-random-state t))
                   0)
-        *dark* (gethash 'dark options)))
+        *dark* (gethash 'dark options)
+        *multi* (gethash 'multicolor options)))
 
 (defun toplevel ()
   (sb-ext:disable-debugger)