commit 50c225359a7e1ab7e90d99535037fa62d5edb07d
parent 2509819ba9dac51858c40777923a847ab52ca6cf
Author: ChanderG <[email protected]>
Date: Wed, 3 Dec 2025 20:05:21 +0530
add line numbers with colors
Diffstat:
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/grep.lisp b/grep.lisp
@@ -14,18 +14,18 @@
(defun color-magenta (str)
(format nil "~c[35m~a~c[0m" #\ESC str #\ESC))
+(defun color-green (str)
+ (format nil "~c[32m~a~c[0m" #\ESC str #\ESC))
(defstruct file-result
name entries)
;; rg like combined format
(defun format-file-result (fr stream)
- (write-string
- (format nil
- "~a: ~%~{~A~%~}~%"
- (color-magenta (file-result-name fr))
- (file-result-entries fr))
- stream))
+ (format stream "~a: ~%" (color-magenta (file-result-name fr)))
+ (loop for e in (file-result-entries fr) do
+ (format stream "~a: ~a~%" (color-green (car e)) (cadr e)))
+ (format stream "~%"))
;; ;; alternative grep like format to easily test parity
;; (defun format-file-result (fr stream)
@@ -38,9 +38,11 @@
(with-open-file (stream file)
(let ((results
(loop for line = (read-line stream nil :eof)
+ with i = 0
until (eq line :eof)
+ do (incf i)
if (sm:search-bmh8 match-idx line)
- collect line)))
+ collect (list i line))))
(when results
(lq:push-queue (make-file-result :name file :entries results)
*print-queue*))))