guix-commits
[Top][All Lists]
Advanced

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

16/26: gurses: Mini refactor.


From: John Darrington
Subject: 16/26: gurses: Mini refactor.
Date: Sun, 22 Jan 2017 12:09:24 +0000 (UTC)

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

commit b264f4e04d88195281fda81c379d2947274e8166
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]