summaryrefslogtreecommitdiff
path: root/guix/ui.scm
diff options
context:
space:
mode:
Diffstat (limited to 'guix/ui.scm')
-rw-r--r--guix/ui.scm111
1 files changed, 75 insertions, 36 deletions
diff --git a/guix/ui.scm b/guix/ui.scm
index a6d4fd10cf..ca5b844a43 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -2,7 +2,8 @@
;;; Copyright © 2012, 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2013 Mark H Weaver <mhw@netris.org>
;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
-;;; Copyright © 2014 Alex Kost <alezost@gmail.com>
+;;; Copyright © 2014, 2015 Alex Kost <alezost@gmail.com>
+;;; Copyright © 2015 Mathieu Lirzin <mthl@openmailbox.org>
;;; Copyright © 2014 Deck Pickard <deck.r.pickard@gmail.com>
;;;
;;; This file is part of GNU Guix.
@@ -45,6 +46,9 @@
#:use-module (ice-9 regex)
#:autoload (system repl repl) (start-repl)
#:autoload (system repl debug) (make-debug stack->vector)
+ #:use-module (texinfo)
+ #:use-module (texinfo plain-text)
+ #:use-module (texinfo string-utils)
#:export (_
N_
P_
@@ -69,6 +73,7 @@
switch-symlinks
config-directory
fill-paragraph
+ package-description-string
string->recutils
package->recutils
package-specification->name+version+output
@@ -77,6 +82,7 @@
args-fold*
parse-command-line
run-guix-command
+ run-guix
program-name
guix-warning-port
warning
@@ -98,7 +104,15 @@
(define _ (cut gettext <> %gettext-domain))
(define N_ (cut ngettext <> <> <> %gettext-domain))
-(define P_ (cut gettext <> %package-text-domain))
+
+(define (P_ msgid)
+ "Return the translation of the package description or synopsis MSGID."
+ ;; Descriptions/synopses might occasionally be empty strings, even if that
+ ;; is something we try to avoid. Since (gettext "") can return a non-empty
+ ;; string, explicitly check for that case.
+ (if (string-null? msgid)
+ msgid
+ (gettext msgid %package-text-domain)))
(define-syntax-rule (define-diagnostic name prefix)
"Create a diagnostic macro (i.e., NAME), which will prepend PREFIX to all
@@ -766,6 +780,28 @@ converted to a space; sequences of more than one line break are preserved."
;;; Packages.
;;;
+(define %text-width
+ (make-parameter (or (and=> (getenv "WIDTH") string->number)
+ 80)))
+
+(set! (@@ (texinfo plain-text) wrap*)
+ ;; XXX: Monkey patch this private procedure to let 'package->recutils'
+ ;; parameterize the fill of description field correctly.
+ (lambda strings
+ (let ((indent (fluid-ref (@@ (texinfo plain-text) *indent*))))
+ (fill-string (string-concatenate strings)
+ #:line-width (%text-width) #:initial-indent indent
+ #:subsequent-indent indent))))
+
+(define (texi->plain-text str)
+ "Return a plain-text representation of texinfo fragment STR."
+ (stexi->plain-text (texi-fragment->stexi str)))
+
+(define (package-description-string package)
+ "Return a plain-text representation of PACKAGE description field."
+ (and=> (package-description package)
+ (compose texi->plain-text P_)))
+
(define (string->recutils str)
"Return a version of STR where newlines have been replaced by newlines
followed by \"+ \", which makes for a valid multi-line field value in the
@@ -778,18 +814,9 @@ followed by \"+ \", which makes for a valid multi-line field value in the
'()
str)))
-(define* (package->recutils p port
- #:optional (width (or (and=> (getenv "WIDTH")
- string->number)
- 80)))
+(define* (package->recutils p port #:optional (width (%text-width)))
"Write to PORT a `recutils' record of package P, arranging to fit within
WIDTH columns."
- (define (description->recutils str)
- (let ((str (P_ str)))
- (string->recutils
- (fill-paragraph str width
- (string-length "description: ")))))
-
(define (dependencies->recutils packages)
(let ((list (string-join (map package-full-name
(sort packages package<?)) " ")))
@@ -833,9 +860,15 @@ WIDTH columns."
(chr chr))
(or (and=> (package-synopsis p) P_)
"")))
- (format port "description: ~a~%"
- (and=> (package-description p) description->recutils))
- (newline port))
+ (format port "~a~2%"
+ (string->recutils
+ (string-trim-right
+ (parameterize ((%text-width width))
+ (texi->plain-text
+ (string-append "description: "
+ (or (and=> (package-description p) P_)
+ ""))))
+ #\newline))))
(define (string->generations str)
"Return the list of generations matching a pattern in STR. This function
@@ -1032,31 +1065,37 @@ found."
(parameterize ((program-name command))
(apply command-main args))))
+(define (run-guix . args)
+ "Run the 'guix' command defined by command line ARGS.
+Unlike 'guix-main', this procedure assumes that locale, i18n support,
+and signal handling has already been set up."
+ (define option? (cut string-prefix? "-" <>))
+
+ (match args
+ (()
+ (format (current-error-port)
+ (_ "guix: missing command name~%"))
+ (show-guix-usage))
+ ((or ("-h") ("--help"))
+ (show-guix-help))
+ (("--version")
+ (show-version-and-exit "guix"))
+ (((? option? o) args ...)
+ (format (current-error-port)
+ (_ "guix: unrecognized option '~a'~%") o)
+ (show-guix-usage))
+ (("help" args ...)
+ (show-guix-help))
+ ((command args ...)
+ (apply run-guix-command
+ (string->symbol command)
+ args))))
+
(define guix-warning-port
(make-parameter (current-warning-port)))
(define (guix-main arg0 . args)
(initialize-guix)
- (let ()
- (define (option? str) (string-prefix? "-" str))
- (match args
- (()
- (format (current-error-port)
- (_ "guix: missing command name~%"))
- (show-guix-usage))
- ((or ("-h") ("--help"))
- (show-guix-help))
- (("--version")
- (show-version-and-exit "guix"))
- (((? option? o) args ...)
- (format (current-error-port)
- (_ "guix: unrecognized option '~a'~%") o)
- (show-guix-usage))
- (("help" args ...)
- (show-guix-help))
- ((command args ...)
- (apply run-guix-command
- (string->symbol command)
- args)))))
+ (apply run-guix args))
;;; ui.scm ends here