[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
13/18: gurses: Avoid one use of car/cdr.
From: |
John Darrington |
Subject: |
13/18: gurses: Avoid one use of car/cdr. |
Date: |
Thu, 2 Feb 2017 18:13:05 +0000 (UTC) |
jmd pushed a commit to branch wip-installer
in repository guix.
commit 9b8034d59dee00fa689c458d4b10384e341b9139
Author: John Darrington <address@hidden>
Date: Wed Feb 1 16:12:25 2017 +0100
gurses: Avoid one use of car/cdr.
* gurses/buttons.scm (buttons-post): Use match instead of car/cdr
---
gurses/buttons.scm | 73 ++++++++++++++++++++++++++--------------------------
1 file changed, 36 insertions(+), 37 deletions(-)
diff --git a/gurses/buttons.scm b/gurses/buttons.scm
index eaa7e31..5afef38 100644
--- a/gurses/buttons.scm
+++ b/gurses/buttons.scm
@@ -31,6 +31,7 @@
#:export (buttons-key-matches-symbol?)
#:use-module (ncurses curses)
+ #:use-module (ice-9 match)
#:use-module (srfi srfi-9))
(define-record-type <buttons>
@@ -114,43 +115,41 @@
(let loop ((bl (buttons-items buttons))
(i 0)
(alist '()))
- (if (null? bl)
- (reverse alist)
- (let* ((but (car bl))
- (key (car but))
- (raw-label (gettext (cadr but)))
- (use-underscore (caddr but))
- ;; Convert the raw-label into a "complex rendered string" which
- ;; has the mnemonic character highlighted
- (label.mark
- (let mk-label ((us #f)
- (mark #f)
- (output '())
- (input (string->list raw-label)))
- (if (null? input)
- (cons (reverse output) mark)
- (let ((c (car input)))
- (mk-label (eq? c #\_)
- (if mark mark (if us c #f))
- (if (and (eq? c #\_) use-underscore)
- output
- (cons
- (if us
- ;; On some terminals bold isn't
visible
- ;; Inverse is much clearer.
- (inverse c)
- (normal c))
- output))
- (cdr input))))))
- (label (car label.mark))
- (mark (cdr label.mark))
- (width (+ (length label) 2))
- (w (derwin win 3 width 0
- (round (- (* (1+ i) (/ (getmaxx win) (1+ n)))
- (/ width 2))) #:panel #f)))
- (box w 0 0)
- (addchstr w label #:y 1 #:x 1)
- (loop (cdr bl) (1+ i) (acons mark (list w key) alist))))))))
+ (match bl
+ (() (reverse alist))
+ (((key raw-label use-underscore) . _)
+ (let* (
+ ;; Convert the raw-label into a "complex rendered string"
which
+ ;; has the mnemonic character highlighted
+ (label.mark
+ (let mk-label ((us #f)
+ (mark #f)
+ (output '())
+ (input (string->list raw-label)))
+ (if (null? input)
+ (cons (reverse output) mark)
+ (let ((c (car input)))
+ (mk-label (eq? c #\_)
+ (if mark mark (if us c #f))
+ (if (and (eq? c #\_) use-underscore)
+ output
+ (cons
+ (if us
+ ;; On some terminals bold
isn't visible
+ ;; Inverse is much clearer.
+ (inverse c)
+ (normal c))
+ output))
+ (cdr input))))))
+ (label (car label.mark))
+ (mark (cdr label.mark))
+ (width (+ (length label) 2))
+ (w (derwin win 3 width 0
+ (round (- (* (1+ i) (/ (getmaxx win) (1+ n)))
+ (/ width 2))) #:panel #f)))
+ (box w 0 0)
+ (addchstr w label #:y 1 #:x 1)
+ (loop (cdr bl) (1+ i) (acons mark (list w key) alist)))))))))
- 08/18: installer: Replace 'file-browser' with 'key-map'., (continued)
- 08/18: installer: Replace 'file-browser' with 'key-map'., John Darrington, 2017/02/02
- 06/18: installer: Use _ instead of M_ for host-name-refresh., John Darrington, 2017/02/02
- 14/18: gurses: Cache the windows of buttons., John Darrington, 2017/02/02
- 16/18: installer: New procedure key-value-slurp., John Darrington, 2017/02/02
- 18/18: installer: Fix bug when changing languages., John Darrington, 2017/02/02
- 07/18: installer: New page to select language., John Darrington, 2017/02/02
- 10/18: installer: Fix i18n in dialogs., John Darrington, 2017/02/02
- 17/18: installer: Provide verbose description of locale., John Darrington, 2017/02/02
- 03/18: installer: New file i18n.scm., John Darrington, 2017/02/02
- 11/18: installer: New convenience procedures., John Darrington, 2017/02/02
- 13/18: gurses: Avoid one use of car/cdr.,
John Darrington <=
- 15/18: gurses: Use match instead of car., John Darrington, 2017/02/02
- 12/18: installer: Improve i18n in ping page., John Darrington, 2017/02/02