guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

120/197: gurses: Mini refactor.


From: Danny Milosavljevic
Subject: 120/197: gurses: Mini refactor.
Date: Mon, 3 Jul 2017 20:37:11 -0400 (EDT)

dannym pushed a commit to branch wip-installer-2
in repository guix.

commit 61bd7e6e72d0a219c93c234b493ad57689298830
Author: John Darrington <address@hidden>
Date:   Wed Jan 18 17:46:19 2017 +0100

    gurses: Mini refactor.
    
    * gurses/form.scm: (draw-field-space): New procedure.
---
 gurses/form.scm | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/gurses/form.scm b/gurses/form.scm
index b2161b6..bfa7620 100644
--- a/gurses/form.scm
+++ b/gurses/form.scm
@@ -34,6 +34,7 @@
 
   #:use-module (ncurses curses)
   #:use-module (ice-9 match)
+  #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-9))
 
 (define-record-type <field>
@@ -62,12 +63,21 @@
          (+ (field-cursor-position field)
             (form-tabpos form)))))
 
+(define (draw-field-space win field y x)
+  "Draws the template for FIELD at Y, X"
+  (addchstr win
+           (make-list
+             (if (list? (field-size field))
+                 (fold (lambda (x prev) (max prev (string-length x))) 0
+                       (field-size field))
+                 (field-size field))
+             (underline #\space))
+           #:y y
+           #:x x))
+
 (define (redraw-field form field n)
   "Redraw the FIELD in FORM"
-  (addchstr (form-window form)
-           (make-list (field-size field) (underline #\space))
-           #:y n
-           #:x (form-tabpos form))
+  (draw-field-space (form-window form) field n (form-tabpos form))
 
   (addstr (form-window form) (field-value field)
          #:y n
@@ -241,7 +251,7 @@ label eq? to N"
               (pos 0))
       (if (array-in-bounds? fields pos)
          (let ((f (array-ref fields pos)))
-           (addchstr win (make-list (field-size f) (underline #\space)) #:y 
pos #:x xpos)
+            (draw-field-space win f pos xpos)
            (loop fields (1+ pos)))))))
 
 (define (get-current-field form)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]