[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
08/197: installer: Add IETF contraints for hostname in entry form.
From: |
Danny Milosavljevic |
Subject: |
08/197: installer: Add IETF contraints for hostname in entry form. |
Date: |
Mon, 3 Jul 2017 20:36:51 -0400 (EDT) |
dannym pushed a commit to branch wip-installer-2
in repository guix.
commit 42e0abd5caa0ae10ffef9b3319267fc9c3154b04
Author: John Darrington <address@hidden>
Date: Sun Dec 18 10:07:23 2016 +0100
installer: Add IETF contraints for hostname in entry form.
* gnu/system/installer/hostname.scm (host-name-key-handler): Add hostname
constraints.
* gurses/form.scm (get-current-field): New procedure.
---
gnu/system/installer/hostname.scm | 34 +++++++++++++++++++++++-----------
gurses/form.scm | 5 ++++-
2 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/gnu/system/installer/hostname.scm
b/gnu/system/installer/hostname.scm
index bc10e6b..f3bfe78 100644
--- a/gnu/system/installer/hostname.scm
+++ b/gnu/system/installer/hostname.scm
@@ -59,15 +59,10 @@
(set! host-name (form-get-value form 0))
(set! page-stack (cdr page-stack))
((page-refresh (car page-stack)) (car page-stack)))
-
- ((or (eq? ch KEY_RIGHT)
- (eq? ch #\tab))
- (form-set-enabled! form #f)
- (buttons-select-next nav))
- ((eq? ch KEY_LEFT)
+ ((eq? ch #\tab)
(form-set-enabled! form #f)
- (buttons-select-prev nav))
+ (buttons-select-next nav))
((eq? ch KEY_UP)
(buttons-unselect-all nav)
@@ -76,11 +71,28 @@
((eq? ch KEY_DOWN)
(buttons-unselect-all nav)
(form-set-enabled! form #t))
- )
- (curs-set 1)
- (form-enter form ch))
- #f)
+ ;; Do not allow more than 64 characters
+ ((and (char? ch)
+ (char-set-contains? char-set:printing ch)
+ (>= (field-cursor-position (get-current-field form)) 64)))
+
+ ;; The first character may not be a hyphen
+ ((and (char? ch)
+ (eq? ch #\-)
+ (zero? (field-cursor-position (get-current-field form)))))
+
+ ;; Subsequent characters must be [-A-Za-z0-9]
+ ((and (char? ch)
+ (char-set-contains? char-set:printing ch)
+ (not (char-set-contains?
+ (char-set-adjoin char-set:letter+digit #\-) ch))
+ (positive? (field-cursor-position (get-current-field form)))))
+
+ (else
+ (curs-set 1)
+ (form-enter form ch)))
+ #f))
(define my-buttons `((continue ,(N_ "Continue") #f)))
diff --git a/gurses/form.scm b/gurses/form.scm
index 242f112..d26d76e 100644
--- a/gurses/form.scm
+++ b/gurses/form.scm
@@ -29,6 +29,7 @@
#:export (form-enabled?)
#:export (form-update-cursor)
#:export (form-set-current-field)
+ #:export (get-current-field)
#:use-module (ncurses curses)
#:use-module (srfi srfi-9))
@@ -199,7 +200,6 @@ label eq? to N"
(form-set-current-item! form which)
(move (form-window form) which (form-tabpos form)))
-
(define (form-next-field form)
(if (< (form-current-item form) (1- (array-length (form-items form))))
(begin
@@ -236,3 +236,6 @@ label eq? to N"
(let ((f (array-ref fields pos)))
(addchstr win (make-list (field-size f) (underline #\space)) #:y
pos #:x xpos)
(loop fields (1+ pos)))))))
+
+(define (get-current-field form)
+ (array-ref (form-items form) (form-current-item form)))
- branch wip-installer-2 created (now ff63588), Danny Milosavljevic, 2017/07/03
- 04/197: installer: Fix broken timezone menu., Danny Milosavljevic, 2017/07/03
- 05/197: installer: fix warning in usage of "format"., Danny Milosavljevic, 2017/07/03
- 02/197: installer: Fix broken keymap change option., Danny Milosavljevic, 2017/07/03
- 07/197: installer: Use ice-9 match., Danny Milosavljevic, 2017/07/03
- 12/197: installer: Use call-with-temporary-output-file., Danny Milosavljevic, 2017/07/03
- 08/197: installer: Add IETF contraints for hostname in entry form.,
Danny Milosavljevic <=
- 06/197: installer: use ice-9 format everywhere., Danny Milosavljevic, 2017/07/03
- 11/197: installer: Change "interfaces" from a variable to a procedure., Danny Milosavljevic, 2017/07/03
- 16/197: installer: Add new procedure to get the list of volumes., Danny Milosavljevic, 2017/07/03
- 15/197: installer: Use %default-subsitute-urls instead of our own variable., Danny Milosavljevic, 2017/07/03
- 19/197: installer: Remove unused procedure., Danny Milosavljevic, 2017/07/03
- 18/197: installer: Handle the 'back' action in the filesystems task., Danny Milosavljevic, 2017/07/03
- 13/197: installer: Add alternate method of finding TZDIR., Danny Milosavljevic, 2017/07/03
- 31/197: installer: Make minumum-store-size variable global., Danny Milosavljevic, 2017/07/03
- 33/197: installer: Improve dependencies on the final task., Danny Milosavljevic, 2017/07/03
- 17/197: installer: Add completion predicate for disk task., Danny Milosavljevic, 2017/07/03