summaryrefslogtreecommitdiff
path: root/guix/scripts
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2022-04-09 20:26:45 +0200
committerLudovic Courtès <ludo@gnu.org>2022-04-19 18:07:49 +0200
commit5e0c3479759047311b6a518fd0bc512b232f201a (patch)
tree0b975ae4eecb5e3603ed7f6d4851beab81bf5b24 /guix/scripts
parentd08e4d52a3c9790b8141d10540d4215a1df80375 (diff)
ui: Highlight package and service search results.
* guix/ui.scm (package->recutils): Add #:highlighting parameter and use it. (display-search-results): Add #:regexps parameter; call 'colorize-full-matches' and pass #:highlighting. * guix/scripts/package.scm (process-query): Pass #:regexps to 'display-search-results'. * guix/scripts/home.scm (search): Likewise. * guix/scripts/system/search.scm (service-type->recutils): Add #:highlighting parameter and use it.
Diffstat (limited to 'guix/scripts')
-rw-r--r--guix/scripts/home.scm1
-rw-r--r--guix/scripts/package.scm3
-rw-r--r--guix/scripts/system/search.scm30
3 files changed, 22 insertions, 12 deletions
diff --git a/guix/scripts/home.scm b/guix/scripts/home.scm
index 341d83943d..f43bf865a7 100644
--- a/guix/scripts/home.scm
+++ b/guix/scripts/home.scm
@@ -733,6 +733,7 @@ description matches REGEXPS sorted by relevance, and their score."
(leave-on-EPIPE
(display-search-results matches (current-output-port)
#:print service-type->recutils
+ #:regexps regexps
#:command "guix home search")))))
diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index 22ee8a2485..d007005607 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -885,7 +885,8 @@ processed, #f otherwise."
(regexps (map (cut make-regexp* <> regexp/icase) patterns))
(matches (find-packages-by-description regexps)))
(leave-on-EPIPE
- (display-search-results matches (current-output-port)))
+ (display-search-results matches (current-output-port)
+ #:regexps regexps))
#t))
(('show _)
diff --git a/guix/scripts/system/search.scm b/guix/scripts/system/search.scm
index 2a237e03d9..d70ed266f4 100644
--- a/guix/scripts/system/search.scm
+++ b/guix/scripts/system/search.scm
@@ -20,7 +20,7 @@
(define-module (guix scripts system search)
#:use-module (guix ui)
#:use-module (guix utils)
- #:autoload (guix colors) (highlight supports-hyperlinks?)
+ #:autoload (guix colors) (color-output? highlight supports-hyperlinks?)
#:autoload (guix diagnostics) (location->hyperlink)
#:use-module (gnu services)
#:use-module (gnu services shepherd)
@@ -70,10 +70,12 @@ provided TYPE has a default value."
#:optional (width (%text-width))
#:key
(extra-fields '())
- (hyperlinks? (supports-hyperlinks? port)))
+ (hyperlinks? (supports-hyperlinks? port))
+ (highlighting identity))
"Write to PORT a recutils record of TYPE, arranging to fit within WIDTH
columns. When HYPERLINKS? is true, emit hyperlink escape sequences when
-appropriate."
+appropriate. Pass the description through HIGHLIGHTING, a one-argument
+procedure that may return a colorized version of its argument."
(define port*
(or (pager-wrapped-port port) port))
@@ -90,6 +92,11 @@ appropriate."
(fill-paragraph list width*
(string-length "extends: ")))))
+ (define highlighting*
+ (if (color-output? port*)
+ highlighting
+ identity))
+
;; Note: Don't i18n field names so that people can post-process it.
(format port "name: ~a~%"
(highlight (symbol->string (service-type-name type))
@@ -114,14 +121,15 @@ appropriate."
(when (service-type-description type)
(format port "~a~%"
- (string->recutils
- (string-trim-right
- (parameterize ((%text-width width*))
- (texi->plain-text
- (string-append "description: "
- (or (and=> (service-type-description type) P_)
- ""))))
- #\newline))))
+ (highlighting*
+ (string->recutils
+ (string-trim-right
+ (parameterize ((%text-width width*))
+ (texi->plain-text
+ (string-append "description: "
+ (or (and=> (service-type-description type) P_)
+ ""))))
+ #\newline)))))
(for-each (match-lambda
((field . value)