Next: , Previous: A Form Example, Up: Forms Library   [Contents][Index]

4.15.3 Making it useful

The previous example does create a form and allow one to move between the fields, but, it doesn’t perform the useful function of allowing the program to fetch the contents of those fields. Also, the basic editing features like BS and DELETE are not connected.

To make it useful, it needs a couple of important changes. First, it passes more of the important editing commands like BS and DELETE to the form driver for processing. Second, it fetches the final content of the fields as one would normally do in a form application.

A more complete editing loop might look like this

;; Loop through to get user requests
(let loop ((ch (getch win)))
  (if (not (eqv? ch (key-f 1)))
         ((eqv? ch KEY_DOWN)
            ;; Go to the end of the next field
            (form-driver my-form REQ_NEXT_FIELD)
            (form-driver my-form REQ_END_LINE)))
         ((eqv? ch KEY_UP)
            ;; Go to the end of the previous field
            (form-driver my-form REQ_PREV_FIELD)
            (form-driver my-form REQ_END_LINE)))
         ((eqv? ch KEY_LEFT)
          (form-driver my-form REQ_PREV_CHAR))
         ((eqv? ch KEY_RIGHT)
          (form-driver my-form REQ_NEXT_CHAR))
         ((eqv? ch KEY_DC)
          (form-driver my-form REQ_DEL_CHAR))
         ((eqv? ch KEY_BACKSPACE)
          (form-driver my-form REQ_DEL_PREV))
          (form-driver my-form ch)))
        (loop (getch win)))))

And, gathering the contents of the form can be accomplished like this:

;; Move the cursor to ensure that the last characters typed by the
;; user get committed to the field buffer.
(form-driver my-form REQ_LAST_FIELD)
;; Unpost the form
(unpost-form my-form)

;; Store the contents of the field
(let ((result1 (field-buffer (first field) 0))
      (result2 (field-buffer (second field) 0)))
  (display (string-append "You typed " result1 " and " result2))

Next: , Previous: A Form Example, Up: Forms Library   [Contents][Index]