ui: 'display-search-results' automatically invokes the pager.
* guix/ui.scm (call-with-paginated-output-port): New procedure. (with-paginated-output-port): New macro. (display-search-results): Use it instead of displaying a hint.
This commit is contained in:
parent
d67a881966
commit
c39693d760
2 changed files with 35 additions and 24 deletions
|
@ -99,6 +99,8 @@
|
||||||
(eval . (put 'with-environment-variables 'scheme-indent-function 1))
|
(eval . (put 'with-environment-variables 'scheme-indent-function 1))
|
||||||
(eval . (put 'with-fresh-gnupg-setup 'scheme-indent-function 1))
|
(eval . (put 'with-fresh-gnupg-setup 'scheme-indent-function 1))
|
||||||
|
|
||||||
|
(eval . (put 'with-paginated-output-port 'scheme-indent-function 1))
|
||||||
|
|
||||||
;; This notably allows '(' in Paredit to not insert a space when the
|
;; This notably allows '(' in Paredit to not insert a space when the
|
||||||
;; preceding symbol is one of these.
|
;; preceding symbol is one of these.
|
||||||
(eval . (modify-syntax-entry ?~ "'"))
|
(eval . (modify-syntax-entry ?~ "'"))
|
||||||
|
|
57
guix/ui.scm
57
guix/ui.scm
|
@ -69,6 +69,7 @@
|
||||||
#:use-module (ice-9 match)
|
#:use-module (ice-9 match)
|
||||||
#:use-module (ice-9 format)
|
#:use-module (ice-9 format)
|
||||||
#:use-module (ice-9 regex)
|
#:use-module (ice-9 regex)
|
||||||
|
#:autoload (ice-9 popen) (open-pipe* close-pipe)
|
||||||
#:autoload (system base compile) (compile-file)
|
#:autoload (system base compile) (compile-file)
|
||||||
#:autoload (system repl repl) (start-repl)
|
#:autoload (system repl repl) (start-repl)
|
||||||
#:autoload (system repl debug) (make-debug stack->vector)
|
#:autoload (system repl debug) (make-debug stack->vector)
|
||||||
|
@ -1557,6 +1558,27 @@ score, the more relevant OBJ is to REGEXPS."
|
||||||
zero means that PACKAGE does not match any of REGEXPS."
|
zero means that PACKAGE does not match any of REGEXPS."
|
||||||
(relevance package regexps %package-metrics))
|
(relevance package regexps %package-metrics))
|
||||||
|
|
||||||
|
(define (call-with-paginated-output-port proc)
|
||||||
|
(if (isatty?* (current-output-port))
|
||||||
|
;; Set 'LESS' so that 'less' exits if everything fits on the screen (F),
|
||||||
|
;; lets ANSI escapes through (r), does not send the termcap
|
||||||
|
;; initialization string (X).
|
||||||
|
(let ((pager (with-environment-variables `(("LESS"
|
||||||
|
,(or (getenv "LESS") "FrX")))
|
||||||
|
(open-pipe* OPEN_WRITE
|
||||||
|
(or (getenv "GUIX_PAGER") (getenv "PAGER")
|
||||||
|
"less")))))
|
||||||
|
(dynamic-wind
|
||||||
|
(const #t)
|
||||||
|
(lambda () (proc pager))
|
||||||
|
(lambda () (close-pipe pager))))
|
||||||
|
(proc (current-output-port))))
|
||||||
|
|
||||||
|
(define-syntax-rule (with-paginated-output-port port exp ...)
|
||||||
|
"Evaluate EXP... with PORT bound to a port that talks to the pager if
|
||||||
|
standard output is a tty, or with PORT set to the current output port."
|
||||||
|
(call-with-paginated-output-port (lambda (port) exp ...)))
|
||||||
|
|
||||||
(define* (display-search-results matches port
|
(define* (display-search-results matches port
|
||||||
#:key
|
#:key
|
||||||
(command "guix search")
|
(command "guix search")
|
||||||
|
@ -1573,30 +1595,17 @@ them. If PORT is a terminal, print at most a full screen of results."
|
||||||
(define (line-count str)
|
(define (line-count str)
|
||||||
(string-count str #\newline))
|
(string-count str #\newline))
|
||||||
|
|
||||||
(let loop ((matches matches))
|
(with-paginated-output-port paginated
|
||||||
(match matches
|
(let loop ((matches matches))
|
||||||
(((package . score) rest ...)
|
(match matches
|
||||||
(let* ((links? (supports-hyperlinks? port))
|
(((package . score) rest ...)
|
||||||
(text (call-with-output-string
|
(let* ((links? (supports-hyperlinks? port)))
|
||||||
(lambda (port)
|
(print package paginated
|
||||||
(print package port
|
#:hyperlinks? links?
|
||||||
#:hyperlinks? links?
|
#:extra-fields `((relevance . ,score)))
|
||||||
#:extra-fields
|
(loop rest)))
|
||||||
`((relevance . ,score)))))))
|
(()
|
||||||
(if (and (not (getenv "INSIDE_EMACS"))
|
#t)))))
|
||||||
max-rows
|
|
||||||
(> (port-line port) first-line) ;print at least one result
|
|
||||||
(> (+ 4 (line-count text) (port-line port))
|
|
||||||
max-rows))
|
|
||||||
(unless (null? rest)
|
|
||||||
(display-hint (format #f (G_ "Run @code{~a ... | less} \
|
|
||||||
to view all the results.")
|
|
||||||
command)))
|
|
||||||
(begin
|
|
||||||
(display text port)
|
|
||||||
(loop rest)))))
|
|
||||||
(()
|
|
||||||
#t))))
|
|
||||||
|
|
||||||
|
|
||||||
(define (string->generations str)
|
(define (string->generations str)
|
||||||
|
|
Reference in a new issue