2006-03-28 04:37:38 -05:00
|
|
|
|
2006-04-06 17:40:59 -04:00
|
|
|
|
2006-03-28 04:37:38 -05:00
|
|
|
;;===============================================================================
|
|
|
|
;; exeptions
|
|
|
|
|
|
|
|
(define-condition-type 'buffer-full '(error))
|
|
|
|
(define buffer-full? (condition-predicate 'buffer-full))
|
|
|
|
|
|
|
|
;; exeptions END
|
|
|
|
;;===============================================================================
|
|
|
|
|
2006-04-06 17:40:59 -04:00
|
|
|
|
2005-11-11 03:01:07 -05:00
|
|
|
;;===============================================================================
|
|
|
|
;; record input-field:
|
|
|
|
|
|
|
|
(define-record-type input-field :input-field
|
2006-03-28 04:37:38 -05:00
|
|
|
(really-make-input-field prompt
|
|
|
|
default-text
|
2005-11-11 03:01:07 -05:00
|
|
|
edit-lines
|
|
|
|
window
|
|
|
|
behavior
|
|
|
|
insert-active
|
2006-04-06 17:40:59 -04:00
|
|
|
x-loc y-loc ;; position of INPUT-FIELD
|
|
|
|
x-dim y-dim ;; size of INPUT-FIELD
|
|
|
|
x-pos y-pos ;; cursor position in INPUT-FIELD
|
|
|
|
x-edit-pos y-edit-pos ;; cursor position in edit-lines (text-buffer)
|
|
|
|
x-offset y-offset ;; what snippet of the edit-lines are shown in I_F
|
|
|
|
x-scroll y-scroll) ;; which direction is allowed to be scrolled
|
2005-11-11 03:01:07 -05:00
|
|
|
input-field?
|
2006-04-06 17:40:59 -04:00
|
|
|
(prompt input-field-prompt set-input-field-prompt!)
|
|
|
|
(default-text input-field-default-text)
|
|
|
|
(edit-lines input-field-edit-lines set-input-field-edit-lines!)
|
|
|
|
(window input-field-window set-input-field-window!)
|
|
|
|
(behavior input-field-behavior set-input-field-behavior!)
|
|
|
|
(insert-active input-field-insert-active set-input-field-insert-active!)
|
|
|
|
(x-loc input-field-x-loc set-input-field-x-loc!)
|
|
|
|
(y-loc input-field-y-loc set-input-field-y-loc!)
|
|
|
|
(x-dim input-field-x-dim set-input-field-x-dim!)
|
|
|
|
(y-dim input-field-y-dim set-input-field-y-dim!)
|
|
|
|
(x-pos input-field-x-pos set-input-field-x-pos!)
|
|
|
|
(y-pos input-field-y-pos set-input-field-y-pos!)
|
|
|
|
(x-edit-pos input-field-x-edit-pos set-input-field-x-edit-pos!)
|
|
|
|
(y-edit-pos input-field-y-edit-pos set-input-field-y-edit-pos!)
|
|
|
|
(x-offset input-field-x-offset set-input-field-x-offset!)
|
|
|
|
(y-offset input-field-y-offset set-input-field-y-offset!)
|
|
|
|
(x-scroll input-field-x-scroll set-input-field-x-scroll!)
|
|
|
|
(y-scroll input-field-y-scroll set-input-field-y-scroll!))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define-record-discloser :input-field
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(list 'input-field
|
2006-04-06 17:40:59 -04:00
|
|
|
(input-field-default-text input-field))))
|
2006-03-28 04:37:38 -05:00
|
|
|
|
2006-04-06 17:40:59 -04:00
|
|
|
(define input-field-init-text
|
|
|
|
(lambda (input-field)
|
|
|
|
(let ((prompt (input-field-prompt input-field)))
|
2006-03-28 04:37:38 -05:00
|
|
|
(if prompt
|
|
|
|
(string-append prompt
|
2006-04-06 17:40:59 -04:00
|
|
|
(input-field-default-text input-field))
|
|
|
|
(input-field-default-text input-field)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
;; record input-field END
|
|
|
|
;;===============================================================================
|
|
|
|
|
|
|
|
;;===============================================================================
|
|
|
|
;; "basics"
|
|
|
|
|
|
|
|
; ----------------------------------------------------------------------------
|
|
|
|
;; "basics" - make-input-field
|
|
|
|
|
|
|
|
(define make-input-field
|
|
|
|
(lambda (x-dim y-dim . args)
|
|
|
|
(let* ((args-len (length args))
|
2006-03-28 04:37:38 -05:00
|
|
|
(prompt (if (> args-len 0)
|
|
|
|
(car args)
|
|
|
|
#f))
|
|
|
|
(prompt-length (if prompt
|
|
|
|
(string-length prompt)
|
|
|
|
0))
|
|
|
|
(default-text (if (> args-len 1)
|
|
|
|
(cadr args)
|
2005-11-11 03:01:07 -05:00
|
|
|
""))
|
2006-03-28 04:37:38 -05:00
|
|
|
(behavior (if (> args-len 2)
|
|
|
|
(caddr args)
|
2005-11-11 03:01:07 -05:00
|
|
|
standard-behavior))
|
2006-03-28 04:37:38 -05:00
|
|
|
(insert-active (if (> args-len 3)
|
|
|
|
(cadddr args)
|
2005-11-11 03:01:07 -05:00
|
|
|
#t))
|
2006-03-28 04:37:38 -05:00
|
|
|
(x-scroll (if (> args-len 4)
|
2005-11-11 03:01:07 -05:00
|
|
|
(caddddr args)
|
2006-03-28 04:37:38 -05:00
|
|
|
#f))
|
|
|
|
(y-scroll (if (> args-len 5)
|
|
|
|
(cadddddr args)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f)))
|
2006-04-06 17:40:59 -04:00
|
|
|
(let ((input-field (really-make-input-field prompt
|
|
|
|
default-text
|
|
|
|
#f
|
|
|
|
#f
|
|
|
|
behavior
|
|
|
|
insert-active
|
|
|
|
#f #f
|
|
|
|
x-dim y-dim
|
|
|
|
prompt-length 0
|
|
|
|
prompt-length 0
|
|
|
|
0 0
|
|
|
|
x-scroll y-scroll)))
|
|
|
|
(set-input-field-edit-lines!
|
|
|
|
input-field
|
|
|
|
(string->input-field-edit-lines input-field
|
|
|
|
(input-field-init-text input-field)))
|
|
|
|
input-field))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
;; "basics" - make-input-field END
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; "basics" - remove / install-input-field & cursor-over-input-field?
|
|
|
|
|
|
|
|
;; FIXIT: sollte jemand auf die idee kommen ein input-field in mehrere
|
|
|
|
;; fenster zu installieren, müsste man hier noch was tun :-(
|
|
|
|
|
|
|
|
;; --------------------------------------------
|
|
|
|
;; input-field-lookup-list
|
|
|
|
;; für die zentrale verwaltung der input-fields
|
|
|
|
;; --------------------------------------------
|
|
|
|
(define input-fields-lookup-list '())
|
|
|
|
|
|
|
|
;; --------------------------------------------------
|
|
|
|
;; install-input-field ordnet einem input-field ein
|
|
|
|
;; window zu und trägt das input-field in die
|
|
|
|
;; look-up-liste als weak-pointer ein
|
|
|
|
;; ---------------------------------------------------
|
|
|
|
(define install-input-field
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field window x y)
|
|
|
|
(set-input-field-window! input-field window)
|
|
|
|
(set-input-field-y-loc! input-field y)
|
|
|
|
(set-input-field-x-loc! input-field x)
|
2005-11-11 03:01:07 -05:00
|
|
|
(set! input-fields-lookup-list
|
2006-04-06 17:40:59 -04:00
|
|
|
(cons (make-weak-pointer input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(util-filter (lambda (x) x)
|
2006-04-06 17:40:59 -04:00
|
|
|
input-fields-lookup-list)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define make&install-input-field
|
|
|
|
(lambda (win x-loc y-loc x-dim y-dim . args)
|
2006-03-28 04:37:38 -05:00
|
|
|
(let ((input-field (apply make-input-field
|
2006-04-06 17:40:59 -04:00
|
|
|
x-dim y-dim
|
|
|
|
args)))
|
|
|
|
(install-input-field input-field
|
|
|
|
win
|
|
|
|
x-loc y-loc)
|
|
|
|
input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define remove-input-field
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(set! input-fields-lookup-list
|
|
|
|
(let loop ((input-fields input-fields-lookup-list))
|
|
|
|
(if (null? input-fields)
|
|
|
|
'()
|
|
|
|
(let ((first (car input-fields)))
|
2006-04-06 17:40:59 -04:00
|
|
|
(if (eq? input-field first)
|
2005-11-11 03:01:07 -05:00
|
|
|
(cdr input-fields)
|
|
|
|
(cons first
|
|
|
|
(loop (cdr input-fields))))))))))
|
|
|
|
|
|
|
|
;; --------------------------------------------------------
|
|
|
|
;; cursor-over-input-field? schaut nach, ob ein input-field
|
|
|
|
;; in das übergebene window eingetragen ist und ob
|
|
|
|
;; sich der cursor über diesem befindet
|
|
|
|
;; --------------------------------------------------------
|
|
|
|
(define cursor-over-input-field?
|
|
|
|
(lambda (window)
|
|
|
|
(let ((x (getx window))
|
|
|
|
(y (gety window)))
|
2006-04-06 17:40:59 -04:00
|
|
|
(let loop ((input-field-lst input-fields-lookup-list))
|
|
|
|
(if (null? input-field-lst)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f
|
2006-04-06 17:40:59 -04:00
|
|
|
(let* ((input-field (weak-pointer-ref (car input-field-lst)))
|
|
|
|
(win (if input-field
|
|
|
|
(input-field-window input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f)))
|
|
|
|
(if (eq? window win)
|
2006-04-06 17:40:59 -04:00
|
|
|
(or (cursor-over-this-input-field? x y input-field)
|
|
|
|
(loop (cdr input-field-lst)))
|
|
|
|
(loop (cdr input-field-lst)))))))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define cursor-over-this-input-field?
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (cursor-x cursor-y input-field)
|
|
|
|
(let* ((upper-left-x (input-field-x-loc input-field))
|
|
|
|
(upper-left-y (input-field-y-loc input-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
(lower-right-x (- (+ upper-left-x
|
2006-04-06 17:40:59 -04:00
|
|
|
(input-field-x-dim input-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
1))
|
|
|
|
(lower-right-y (- (+ upper-left-y
|
2006-04-06 17:40:59 -04:00
|
|
|
(input-field-y-dim input-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
1)))
|
|
|
|
(if (and (>= cursor-y upper-left-y)
|
|
|
|
(<= cursor-y lower-right-y)
|
|
|
|
(>= cursor-x upper-left-x)
|
|
|
|
(<= cursor-x lower-right-x))
|
2006-04-06 17:40:59 -04:00
|
|
|
input-field
|
2005-11-11 03:01:07 -05:00
|
|
|
#f))))
|
|
|
|
;; "basics" - remove / install-input-field & cursor-over-input-field END
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
;; "basics" - selectors
|
|
|
|
|
2006-04-06 17:40:59 -04:00
|
|
|
;; TODOO - besser mit "export-as"... oder wie das heißt
|
|
|
|
(define input-field-default-text input-field-default-text)
|
|
|
|
(define input-field-x-location input-field-x-loc)
|
|
|
|
(define input-field-y-location input-field-y-loc)
|
|
|
|
(define input-field-x-size input-field-x-dim)
|
|
|
|
(define input-field-y-size input-field-y-dim)
|
|
|
|
(define input-field-column input-field-x-edit-pos)
|
|
|
|
(define input-field-line input-field-y-edit-pos)
|
|
|
|
(define input-field-x-scroll input-field-x-scroll)
|
|
|
|
(define input-field-y-scroll input-field-y-scroll)
|
|
|
|
(define input-field-insert input-field-insert-active)
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define input-field-text
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(let* ((prompt (input-field-prompt input-field))
|
|
|
|
(lst (cat (input-field-edit-lines input-field))))
|
2006-03-28 04:37:38 -05:00
|
|
|
(list->string (if prompt
|
|
|
|
(drop lst (string-length prompt))
|
|
|
|
lst)))))
|
|
|
|
|
|
|
|
(define set-input-field-text!
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field text)
|
|
|
|
(goto-begin-of-line input-field)
|
|
|
|
(set-input-field-edit-lines! input-field
|
|
|
|
(string->input-field-edit-lines
|
|
|
|
input-field
|
|
|
|
(let ((prompt (input-field-prompt input-field)))
|
|
|
|
(if prompt
|
|
|
|
(string-append prompt
|
|
|
|
text)
|
|
|
|
text))))
|
|
|
|
(goto-end-of-last-line input-field)))
|
2006-03-28 04:37:38 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define input-field-text-wp
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(list->string (cat (input-field-edit-lines input-field)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
|
|
|
|
;; "basics" - selectors END
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
;; "basics" - clear/reset
|
|
|
|
|
|
|
|
(define input-field-clear
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(let* ((prompt (input-field-prompt input-field))
|
2006-03-28 04:37:38 -05:00
|
|
|
(x-pos (if prompt
|
|
|
|
(string-length prompt)
|
|
|
|
0)))
|
2006-04-06 17:40:59 -04:00
|
|
|
(set-input-field-x-offset! input-field 0)
|
|
|
|
(set-input-field-y-offset! input-field 0)
|
|
|
|
(set-input-field-x-pos! input-field x-pos)
|
|
|
|
(set-input-field-y-pos! input-field 0)
|
|
|
|
(set-input-field-x-edit-pos! input-field x-pos)
|
|
|
|
(set-input-field-y-edit-pos! input-field 0)
|
|
|
|
(set-input-field-edit-lines! input-field (if prompt
|
|
|
|
(list (string->list prompt))
|
|
|
|
'(()))))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define input-field-reset
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(let ((x-pos (let ((prompt (input-field-prompt input-field)))
|
2006-03-28 04:37:38 -05:00
|
|
|
(if prompt
|
|
|
|
(string-length prompt)
|
|
|
|
0))))
|
2006-04-06 17:40:59 -04:00
|
|
|
(set-input-field-x-offset! input-field 0)
|
|
|
|
(set-input-field-y-offset! input-field 0)
|
|
|
|
(set-input-field-x-pos! input-field x-pos)
|
|
|
|
(set-input-field-y-pos! input-field 0)
|
|
|
|
(set-input-field-x-edit-pos! input-field x-pos)
|
|
|
|
(set-input-field-y-edit-pos! input-field 0)
|
|
|
|
(set-input-field-edit-lines!
|
|
|
|
input-field
|
|
|
|
(string->input-field-edit-lines input-field
|
|
|
|
(input-field-init-text input-field))))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
;; "basics" - clear/reset END
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; "basics" END
|
|
|
|
;;===============================================================================
|
|
|
|
|
|
|
|
;;===============================================================================
|
|
|
|
;; draw/refresh functions
|
|
|
|
|
|
|
|
(define paint-black
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(let ((blank-string (make-string (input-field-x-dim input-field)
|
|
|
|
#\space))
|
|
|
|
(y-dim (input-field-y-dim input-field))
|
|
|
|
(x-loc (input-field-x-loc input-field))
|
|
|
|
(y-loc (input-field-y-loc input-field))
|
|
|
|
(win (input-field-window input-field)))
|
|
|
|
(let loop ((dy 0))
|
|
|
|
(if (= dy y-dim)
|
2005-11-11 03:01:07 -05:00
|
|
|
#t
|
|
|
|
(begin
|
|
|
|
(mvwaddstr win
|
|
|
|
(+ y-loc dy) x-loc
|
2006-04-06 17:40:59 -04:00
|
|
|
blank-string)
|
|
|
|
(loop (+ dy 1))))))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
|
|
|
|
(define refresh-position
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(wmove (input-field-window input-field)
|
|
|
|
(+ (input-field-y-loc input-field)
|
|
|
|
(input-field-y-pos input-field))
|
|
|
|
(+ (input-field-x-loc input-field)
|
|
|
|
(input-field-x-pos input-field)))))
|
|
|
|
|
2005-11-11 03:01:07 -05:00
|
|
|
|
2006-03-28 04:37:38 -05:00
|
|
|
(define input-field-window-lines
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(let ((x-loc (input-field-x-loc input-field))
|
|
|
|
(y-loc (input-field-y-loc input-field))
|
|
|
|
(x-dim (input-field-x-dim input-field))
|
|
|
|
(y-dim (input-field-y-dim input-field))
|
|
|
|
(x-offset (input-field-x-offset input-field))
|
|
|
|
(y-offset (input-field-y-offset input-field))
|
|
|
|
(win (input-field-window input-field)))
|
|
|
|
(let* ((input-field-lines (map (lambda (input-field-line)
|
2005-11-11 03:01:07 -05:00
|
|
|
(util-filter (lambda (char)
|
|
|
|
(not (char=? char #\newline)))
|
2006-04-06 17:40:59 -04:00
|
|
|
input-field-line))
|
2005-11-11 03:01:07 -05:00
|
|
|
(cat (map (lambda (edit-line)
|
2006-04-06 17:40:59 -04:00
|
|
|
(edit-line->input-field-lines input-field
|
2005-11-11 03:01:07 -05:00
|
|
|
edit-line))
|
2006-04-06 17:40:59 -04:00
|
|
|
(input-field-edit-lines input-field)))))
|
|
|
|
(input-field-lines-cut (take (drop (map (lambda (input-field-line)
|
|
|
|
(take (drop input-field-line
|
2005-11-11 03:01:07 -05:00
|
|
|
x-offset)
|
|
|
|
x-dim))
|
2006-04-06 17:40:59 -04:00
|
|
|
input-field-lines)
|
2005-11-11 03:01:07 -05:00
|
|
|
y-offset)
|
2006-03-28 04:37:38 -05:00
|
|
|
y-dim)))
|
2006-04-06 17:40:59 -04:00
|
|
|
input-field-lines-cut))))
|
2006-03-28 04:37:38 -05:00
|
|
|
|
|
|
|
(define refresh-all
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(let ((x-loc (input-field-x-loc input-field))
|
|
|
|
(y-loc (input-field-y-loc input-field))
|
|
|
|
(x-dim (input-field-x-dim input-field))
|
|
|
|
(y-dim (input-field-y-dim input-field))
|
|
|
|
(x-offset (input-field-x-offset input-field))
|
|
|
|
(y-offset (input-field-y-offset input-field))
|
|
|
|
(win (input-field-window input-field)))
|
|
|
|
(let* ((input-field-lines-filled (map (lambda (input-field-line)
|
|
|
|
(fill-up input-field-line
|
|
|
|
x-dim
|
|
|
|
#\space))
|
|
|
|
(fill-up (map (lambda (input-field-line)
|
|
|
|
(fill-up input-field-line
|
|
|
|
x-dim
|
|
|
|
#\space))
|
|
|
|
(input-field-window-lines input-field))
|
|
|
|
; (edit-lines->input-field-lines input-field
|
|
|
|
; (input-field-edit-lines input-field)))
|
|
|
|
y-dim
|
|
|
|
'()))))
|
|
|
|
(let loop ((lines input-field-lines-filled)
|
2005-11-11 03:01:07 -05:00
|
|
|
(y-ofst 0))
|
|
|
|
(if (null? lines)
|
2006-04-06 17:40:59 -04:00
|
|
|
(refresh-position input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(begin
|
|
|
|
(mvwaddstr win
|
|
|
|
(+ y-loc y-ofst)
|
|
|
|
x-loc
|
|
|
|
(list->string (car lines)))
|
|
|
|
(loop (cdr lines)
|
|
|
|
(+ y-ofst 1)))))))))
|
|
|
|
|
|
|
|
;; draw/refresh functions END
|
|
|
|
;;===============================================================================
|
|
|
|
|
|
|
|
;;===============================================================================
|
|
|
|
;; send-input-field
|
|
|
|
|
2006-04-06 17:40:59 -04:00
|
|
|
|
|
|
|
;; (values <known> <act>)....
|
|
|
|
;; <known> == #f wird direkt
|
|
|
|
;; von send-input-field abgefangen.
|
|
|
|
(define care-for-return
|
|
|
|
(lambda (input-field msg)
|
|
|
|
(case msg
|
|
|
|
((buffer-full)
|
|
|
|
(values 'buffer-full 'buffer-full)) ;; das ist böse²! sollte eigentlich über signals gemacht werden -- die konnte ich aber nicht catchen :'(
|
|
|
|
((just-position)
|
|
|
|
(refresh-position input-field)
|
|
|
|
(values #t #t))
|
|
|
|
((side-effect)
|
|
|
|
(values #t #f))
|
|
|
|
((#f) ;; konnte nichts machen
|
|
|
|
(values #t #f))
|
|
|
|
((#t) ;; etwas zugefügt oder entfernt
|
|
|
|
(refresh-all input-field)
|
|
|
|
(values #t #t))
|
|
|
|
(else
|
|
|
|
(values #t #f)))))
|
|
|
|
|
2005-11-11 03:01:07 -05:00
|
|
|
(define send-input-field
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field msg . args)
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (integer? msg)
|
2006-04-06 17:40:59 -04:00
|
|
|
(cond ((get-behavior input-field msg) =>
|
2005-11-11 03:01:07 -05:00
|
|
|
(lambda (method)
|
2006-04-06 17:40:59 -04:00
|
|
|
(apply really-send-input-field input-field method args)))
|
|
|
|
(else (apply really-send-input-field input-field msg args)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(values #f #f))))
|
|
|
|
|
|
|
|
(define really-send-input-field
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field msg . args)
|
2005-11-11 03:01:07 -05:00
|
|
|
(cond ((and (number? msg)
|
|
|
|
(or (and (> msg 31)
|
|
|
|
(< msg 127))
|
|
|
|
(= msg 10)
|
|
|
|
(= msg 13)))
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(insert-char input-field
|
|
|
|
(if (= msg 13)
|
|
|
|
#\newline
|
|
|
|
(ascii->char msg)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'move-prev-line)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(move-prev-line input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'move-next-line)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(move-next-line input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'move-left)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(move-left input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'move-right)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(move-right input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'delete-right)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(delete-right input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'move-forward)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(move-forward input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'move-backward)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(move-backward input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'delete-left)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(delete-left input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'delete-all-right)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(delete-all-right input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'delete-all-left)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(delete-all-left input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'delete-line)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(delete-line input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'goto-begin-of-line)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(goto-begin-of-line input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'goto-end-of-line)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(goto-end-of-line input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'goto-begin-of-first-line)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(goto-begin-of-first-line input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'goto-begin-of-last-line)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(goto-begin-of-last-line input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'goto-begin-of-word-forward)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(goto-begin-of-word-forward input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'goto-begin-of-word-backward)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(goto-begin-of-word-backward input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'goto-end-of-word-forward)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(goto-begin-of-word-forward input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'goto-end-of-word-backward)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(goto-begin-of-word-backward input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
; ((eq? msg 'input-field-move-up)
|
2006-04-06 17:40:59 -04:00
|
|
|
; (care-for-return input-field
|
|
|
|
; (input-field-move-up input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
; ((eq? msg 'input-field-move-down)
|
2006-04-06 17:40:59 -04:00
|
|
|
; (care-for-return input-field
|
|
|
|
; (input-field-move-down input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
; ((eq? msg 'input-field-move-left)
|
2006-04-06 17:40:59 -04:00
|
|
|
; (care-for-return input-field
|
|
|
|
; (input-field-move-left input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
; ((eq? msg 'input-field-move-right)
|
2006-04-06 17:40:59 -04:00
|
|
|
; (care-for-return input-field
|
|
|
|
; (input-field-move-right input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'toggle-insert)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(toggle-insert input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'restore)
|
2006-04-06 17:40:59 -04:00
|
|
|
(care-for-return input-field
|
|
|
|
(restore-input-field input-field)))
|
|
|
|
((eq? msg 'refresh-all)
|
|
|
|
(refresh-all input-field)
|
|
|
|
(values #t #t))
|
2005-11-11 03:01:07 -05:00
|
|
|
((list? msg)
|
|
|
|
(for-each (lambda (msg-single)
|
2006-04-06 17:40:59 -04:00
|
|
|
(send-input-field input-field
|
2005-11-11 03:01:07 -05:00
|
|
|
msg-single))
|
|
|
|
msg)
|
|
|
|
(values #t #t))
|
|
|
|
(else (values #f #f)))))
|
|
|
|
|
|
|
|
;; send-input-field END
|
|
|
|
;;===============================================================================
|
|
|
|
;;===============================================================================
|
|
|
|
;; behavior lists
|
|
|
|
|
|
|
|
(define standard-behavior
|
|
|
|
(list (cons key-up
|
|
|
|
'move-prev-line)
|
|
|
|
(cons key-down
|
|
|
|
'move-next-line)
|
|
|
|
(cons key-left
|
|
|
|
'move-left)
|
|
|
|
(cons key-right
|
|
|
|
'move-right)
|
|
|
|
(cons key-backspace
|
|
|
|
'delete-left)
|
|
|
|
(cons key-dc
|
|
|
|
'delete-right)
|
|
|
|
(cons key-home
|
|
|
|
'goto-begin-of-line)
|
|
|
|
(cons key-end
|
|
|
|
'goto-end-of-line)))
|
|
|
|
|
|
|
|
(define standard-behavior-pro
|
|
|
|
(append standard-behavior
|
2006-03-28 04:37:38 -05:00
|
|
|
(list (cons 2;; C-b
|
2005-11-11 03:01:07 -05:00
|
|
|
'move-left)
|
2006-03-28 04:37:38 -05:00
|
|
|
(cons 6;; C-f
|
2005-11-11 03:01:07 -05:00
|
|
|
'move-right)
|
2006-03-28 04:37:38 -05:00
|
|
|
(cons 16;; C-p
|
2005-11-11 03:01:07 -05:00
|
|
|
'move-prev-line)
|
2006-03-28 04:37:38 -05:00
|
|
|
(cons 14;; C-n
|
2005-11-11 03:01:07 -05:00
|
|
|
'move-next-line)
|
2006-03-28 04:37:38 -05:00
|
|
|
(cons 1;; C-a
|
2005-11-11 03:01:07 -05:00
|
|
|
'goto-begin-of-line)
|
2006-03-28 04:37:38 -05:00
|
|
|
(cons 5;; C-e
|
2005-11-11 03:01:07 -05:00
|
|
|
'goto-end-of-line)
|
2006-03-28 04:37:38 -05:00
|
|
|
(cons 4;; C-d
|
2005-11-11 03:01:07 -05:00
|
|
|
'delete-right)
|
2006-03-28 04:37:38 -05:00
|
|
|
(cons 11;; C-k
|
2005-11-11 03:01:07 -05:00
|
|
|
'delete-all-right))))
|
|
|
|
|
|
|
|
;; behavior lists END
|
|
|
|
;;===============================================================================
|
|
|
|
;;===============================================================================
|
|
|
|
;; behavior methods
|
|
|
|
|
|
|
|
(define get-behavior
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field msg)
|
|
|
|
(let loop ((behavior (input-field-behavior input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (null? behavior)
|
|
|
|
#f
|
|
|
|
(if (eq? msg (caar behavior))
|
|
|
|
(cdar behavior)
|
|
|
|
(loop (cdr behavior)))))))
|
|
|
|
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; move
|
|
|
|
|
|
|
|
(define move-prev-line
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(if (first-line? input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f
|
|
|
|
(begin
|
2006-04-06 17:40:59 -04:00
|
|
|
(set-input-field-y-edit-pos! input-field
|
|
|
|
(- (input-field-y-edit-pos input-field)
|
|
|
|
1))
|
|
|
|
(prompt-pos-check input-field)
|
|
|
|
(sync-input-field-edit-pos input-field)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define move-next-line
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(if (last-line? input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f
|
|
|
|
(begin
|
2006-04-06 17:40:59 -04:00
|
|
|
(set-input-field-y-edit-pos! input-field
|
|
|
|
(+ (input-field-y-edit-pos input-field)
|
|
|
|
1))
|
|
|
|
(sync-input-field-edit-pos input-field)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define move-left
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(if (begin-of-line? input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f
|
|
|
|
(begin
|
2006-04-06 17:40:59 -04:00
|
|
|
(set-input-field-x-edit-pos! input-field
|
|
|
|
(- (input-field-x-edit-pos input-field)
|
|
|
|
1))
|
|
|
|
(prompt-pos-check input-field)
|
|
|
|
(sync-input-field-edit-pos input-field)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define move-right
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(if (or (end-of-line? input-field)
|
|
|
|
(and (right-border? input-field)
|
|
|
|
(lower-border? input-field)
|
|
|
|
(not (input-field-y-scroll input-field))
|
|
|
|
(not (input-field-x-scroll input-field))))
|
2005-11-11 03:01:07 -05:00
|
|
|
#f
|
|
|
|
(begin
|
2006-04-06 17:40:59 -04:00
|
|
|
(set-input-field-x-edit-pos! input-field
|
|
|
|
(+ (input-field-x-edit-pos input-field)
|
|
|
|
1))
|
|
|
|
(sync-input-field-edit-pos input-field)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define move-forward
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(cond ((move-right input-field) =>
|
|
|
|
id)
|
|
|
|
((move-next-line input-field)
|
|
|
|
(goto-begin-of-line input-field)
|
|
|
|
#t) ;;vorsichsthalber -- worst case -- vielleicht gescrollt
|
|
|
|
(else #f))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define move-backward
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(cond ((move-left input-field) =>
|
|
|
|
id)
|
|
|
|
((move-prev-line input-field)
|
|
|
|
(goto-end-of-line input-field)
|
|
|
|
#t) ;;worst case
|
|
|
|
(else #f))))
|
|
|
|
|
|
|
|
(define sync-input-field-edit-pos
|
|
|
|
(lambda (input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(call-with-values
|
|
|
|
(lambda ()
|
2006-04-06 17:40:59 -04:00
|
|
|
(edit-pos->input-field-pos input-field
|
|
|
|
(input-field-x-edit-pos input-field)
|
|
|
|
(input-field-y-edit-pos input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(lambda (x-pos y-pos)
|
2006-04-06 17:40:59 -04:00
|
|
|
(set-input-field-x-pos! input-field
|
|
|
|
(- x-pos (input-field-x-offset input-field)))
|
|
|
|
(set-input-field-y-pos! input-field
|
|
|
|
(- y-pos (input-field-y-offset input-field)))))
|
|
|
|
(legalize-position input-field)
|
|
|
|
(if (not (legal-offsets? input-field))
|
|
|
|
(legalize-offsets input-field))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
;; move END
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; scroll
|
|
|
|
|
|
|
|
(define scroll-up
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(set-input-field-y-offset! input-field
|
|
|
|
(- (input-field-y-offset input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
1))
|
|
|
|
#t))
|
|
|
|
|
|
|
|
(define scroll-down
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(set-input-field-y-offset! input-field
|
|
|
|
(+ (input-field-y-offset input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
1))
|
|
|
|
#t))
|
|
|
|
|
|
|
|
(define scroll-left
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(set-input-field-x-offset! input-field
|
|
|
|
(- (input-field-x-offset input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
1))
|
|
|
|
#t))
|
|
|
|
|
|
|
|
(define scroll-right
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(set-input-field-x-offset! input-field
|
|
|
|
(+ (input-field-x-offset input-field)
|
2006-03-28 04:37:38 -05:00
|
|
|
1))
|
|
|
|
#t))
|
2005-11-11 03:01:07 -05:00
|
|
|
;; scroll END
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; insert
|
|
|
|
|
|
|
|
(define insert-char
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field char)
|
|
|
|
(if (and (cursor-at-edit-end-position? input-field)
|
|
|
|
(space-left? input-field)
|
|
|
|
(not (char=? char #\newline)))
|
|
|
|
(begin
|
|
|
|
(set-input-field-edit-lines! input-field
|
|
|
|
(let ((rev-edit-lines
|
|
|
|
(reverse (input-field-edit-lines input-field))))
|
|
|
|
(reverse (cons (append (car rev-edit-lines)
|
|
|
|
(list char))
|
|
|
|
(cdr rev-edit-lines)))))
|
|
|
|
(move-right input-field))
|
|
|
|
(insert-char-complex input-field char))))
|
|
|
|
|
|
|
|
(define insert-char-complex
|
|
|
|
(lambda (input-field char)
|
|
|
|
(let* ((y-edit-pos (input-field-y-edit-pos input-field))
|
|
|
|
(edit-lines (input-field-edit-lines input-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
(current-line (list-ref edit-lines
|
|
|
|
y-edit-pos))
|
|
|
|
(new-lines-tmp (string->edit-lines
|
|
|
|
(list->string
|
|
|
|
((if (or (char=? char #\newline)
|
2006-04-06 17:40:59 -04:00
|
|
|
(input-field-insert-active input-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
insert
|
|
|
|
replace)
|
|
|
|
current-line
|
2006-04-06 17:40:59 -04:00
|
|
|
(input-field-x-edit-pos input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
char))))
|
|
|
|
(new-lines (if (and (= (+ y-edit-pos 1)
|
|
|
|
(length edit-lines))
|
2006-04-06 17:40:59 -04:00
|
|
|
(end-of-line? input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(char=? char #\newline))
|
|
|
|
(append new-lines-tmp '(()))
|
|
|
|
new-lines-tmp))
|
|
|
|
(new-edit-lines (append (take edit-lines
|
|
|
|
y-edit-pos)
|
|
|
|
new-lines
|
|
|
|
(drop edit-lines
|
|
|
|
(+ y-edit-pos 1)))))
|
2006-04-06 17:40:59 -04:00
|
|
|
(if (or (input-field-y-scroll input-field)
|
|
|
|
(= (length (edit-lines->input-field-lines input-field new-lines))
|
|
|
|
(length (edit-line->input-field-lines input-field current-line)))
|
|
|
|
(<= (length (edit-lines->input-field-lines input-field new-edit-lines))
|
|
|
|
(input-field-y-dim input-field)))
|
|
|
|
(begin (set-input-field-edit-lines! input-field new-edit-lines)
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (char=? char #\newline)
|
2006-04-06 17:40:59 -04:00
|
|
|
(begin (set-input-field-x-edit-pos! input-field 0)
|
|
|
|
(set-input-field-y-edit-pos!
|
|
|
|
input-field
|
|
|
|
(+ (input-field-y-edit-pos input-field)
|
|
|
|
1))
|
|
|
|
(sync-input-field-edit-pos input-field))
|
|
|
|
(move-right input-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
#t)
|
2006-03-28 04:37:38 -05:00
|
|
|
'buffer-full))))
|
|
|
|
; (signal 'buffer-full
|
2006-04-06 17:40:59 -04:00
|
|
|
; (input-field-x-edit-pos input-field)
|
|
|
|
; (input-field-y-edit-pos input-field))))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
;; insert END
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; delete
|
|
|
|
|
|
|
|
(define delete-right
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(let* ((x-edit-pos (input-field-x-edit-pos input-field))
|
|
|
|
(y-edit-pos (input-field-y-edit-pos input-field))
|
|
|
|
(edit-lines (input-field-edit-lines input-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
(current-line (list-ref edit-lines
|
|
|
|
y-edit-pos))
|
|
|
|
(current-line-len (length current-line)))
|
|
|
|
(if (and (< x-edit-pos current-line-len)
|
|
|
|
(not (char=? (list-ref current-line
|
|
|
|
x-edit-pos)
|
|
|
|
#\newline)))
|
|
|
|
(let ((new-line (remove current-line
|
|
|
|
x-edit-pos)))
|
2006-04-06 17:40:59 -04:00
|
|
|
(set-input-field-edit-lines! input-field
|
|
|
|
(replace edit-lines
|
|
|
|
y-edit-pos
|
|
|
|
new-line))
|
2005-11-11 03:01:07 -05:00
|
|
|
#t)
|
|
|
|
#f))))
|
|
|
|
|
|
|
|
(define delete-left
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(if (move-left input-field)
|
|
|
|
(delete-right input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f)))
|
|
|
|
|
|
|
|
(define delete-all-left
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(let* ((x-edit-pos (input-field-x-edit-pos input-field))
|
|
|
|
(y-edit-pos (input-field-y-edit-pos input-field))
|
|
|
|
(edit-lines (input-field-edit-lines input-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
(current-line (list-ref edit-lines
|
|
|
|
y-edit-pos)))
|
|
|
|
(if (not (zero? x-edit-pos))
|
|
|
|
(begin
|
2006-04-06 17:40:59 -04:00
|
|
|
(set-input-field-edit-lines! input-field
|
|
|
|
(replace edit-lines
|
|
|
|
y-edit-pos
|
|
|
|
(drop current-line
|
|
|
|
x-edit-pos)))
|
|
|
|
(set-input-field-x-edit-pos! input-field 0)
|
|
|
|
(sync-input-field-edit-pos input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#t)
|
|
|
|
#f))))
|
|
|
|
|
|
|
|
(define delete-all-right
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(let* ((x-edit-pos (input-field-x-edit-pos input-field))
|
|
|
|
(y-edit-pos (input-field-y-edit-pos input-field))
|
|
|
|
(edit-lines (input-field-edit-lines input-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
(current-line (list-ref edit-lines
|
|
|
|
y-edit-pos)))
|
2006-04-06 17:40:59 -04:00
|
|
|
(if (and (end-of-line? input-field)
|
|
|
|
(not (last-line? input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(begin
|
2006-04-06 17:40:59 -04:00
|
|
|
(set-input-field-edit-lines! input-field
|
|
|
|
(append (take edit-lines
|
|
|
|
y-edit-pos)
|
|
|
|
(list
|
|
|
|
(append
|
|
|
|
(reverse (cdr (reverse current-line)))
|
|
|
|
(list-ref edit-lines
|
|
|
|
(+ y-edit-pos 1))))
|
|
|
|
(drop edit-lines
|
|
|
|
(+ y-edit-pos 2))))
|
2005-11-11 03:01:07 -05:00
|
|
|
#t)
|
|
|
|
(begin
|
2006-04-06 17:40:59 -04:00
|
|
|
(set-input-field-edit-lines! input-field
|
|
|
|
(replace edit-lines
|
|
|
|
y-edit-pos
|
|
|
|
(let ((new-line (take current-line
|
|
|
|
x-edit-pos)))
|
|
|
|
(if (char=? (last current-line)
|
|
|
|
#\newline)
|
|
|
|
(append new-line
|
|
|
|
(list #\newline))
|
|
|
|
new-line))))
|
2005-11-11 03:01:07 -05:00
|
|
|
#t)))))
|
|
|
|
|
|
|
|
(define delete-line
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(let* ((x-edit-pos (input-field-x-edit-pos input-field))
|
|
|
|
(y-edit-pos (input-field-y-edit-pos input-field))
|
|
|
|
(edit-lines (input-field-edit-lines input-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
(edit-lines-len (length edit-lines))
|
|
|
|
(current-line (list-ref edit-lines
|
|
|
|
y-edit-pos)))
|
|
|
|
(if (= edit-lines-len 1)
|
|
|
|
(begin
|
2006-04-06 17:40:59 -04:00
|
|
|
(set-input-field-edit-lines! input-field
|
|
|
|
'(()))
|
|
|
|
(set-input-field-x-edit-pos! input-field
|
|
|
|
0)
|
|
|
|
(sync-input-field-edit-pos input-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
(begin
|
2006-04-06 17:40:59 -04:00
|
|
|
(set-input-field-edit-lines! input-field
|
|
|
|
(remove edit-lines
|
|
|
|
y-edit-pos))
|
|
|
|
(set-input-field-x-edit-pos! input-field
|
|
|
|
0)
|
|
|
|
(set-input-field-y-edit-pos! input-field
|
|
|
|
(min y-edit-pos
|
|
|
|
(- edit-lines-len 2)))
|
|
|
|
(sync-input-field-edit-pos input-field))))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
;; delete END
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; goto
|
|
|
|
|
|
|
|
;; TODOO - fertig machen... (siehe #f)
|
|
|
|
|
|
|
|
(define goto-begin-of-word-forward
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(goto-next-forward input-field #\space #\newline)
|
|
|
|
(goto-next-not-forward input-field #\space #\newline)
|
2005-11-11 03:01:07 -05:00
|
|
|
#t))
|
|
|
|
|
|
|
|
|
|
|
|
(define goto-end-of-word-forward
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f))
|
|
|
|
|
|
|
|
|
|
|
|
(define goto-begin-of-word-backward
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(if (and (goto-next-not-backward input-field #\space #\newline)
|
|
|
|
(goto-next-backward input-field #\space #\newline))
|
|
|
|
(move-forward input-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
#t))
|
|
|
|
|
|
|
|
(define goto-end-of-word-backward
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f))
|
|
|
|
|
|
|
|
(define goto-begin-of-line
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(set-input-field-x-edit-pos! input-field 0)
|
|
|
|
(prompt-pos-check input-field)
|
|
|
|
(sync-input-field-edit-pos input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define goto-end-of-line
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(let ((x-edit-pos (input-field-x-edit-pos input-field))
|
|
|
|
(y-edit-pos (input-field-y-edit-pos input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(call-with-values
|
|
|
|
(lambda ()
|
2006-04-06 17:40:59 -04:00
|
|
|
(let* ((current-line (list-ref (input-field-edit-lines input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
y-edit-pos)))
|
|
|
|
(if (null? current-line)
|
2006-04-06 17:40:59 -04:00
|
|
|
(set-input-field-x-edit-pos! input-field 0)
|
2005-11-11 03:01:07 -05:00
|
|
|
(let ((len (length current-line))
|
|
|
|
(end-char (last current-line)))
|
2006-04-06 17:40:59 -04:00
|
|
|
(set-input-field-x-edit-pos! input-field
|
|
|
|
(if (char=? end-char
|
|
|
|
#\newline)
|
|
|
|
(- len 1)
|
|
|
|
len))))
|
|
|
|
(edit-pos->input-field-pos input-field
|
|
|
|
(input-field-x-edit-pos input-field)
|
|
|
|
y-edit-pos)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(lambda (x-pos y-pos)
|
2006-04-06 17:40:59 -04:00
|
|
|
(set-input-field-x-pos! input-field
|
|
|
|
(- x-pos
|
|
|
|
(input-field-x-offset input-field)))
|
|
|
|
(set-input-field-y-pos! input-field
|
|
|
|
(- y-pos
|
|
|
|
(input-field-y-offset input-field)))
|
|
|
|
(sync-input-field-edit-pos input-field))))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define goto-begin-of-first-line
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(set-input-field-x-edit-pos! input-field 0)
|
|
|
|
(set-input-field-y-edit-pos! input-field 0)
|
|
|
|
(prompt-pos-check input-field)
|
|
|
|
(sync-input-field-edit-pos input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define goto-end-of-first-line
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f))
|
|
|
|
|
|
|
|
(define goto-begin-of-last-line
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(set-input-field-x-edit-pos! input-field 0)
|
|
|
|
(set-input-field-y-edit-pos! input-field
|
|
|
|
(- (length (input-field-edit-lines input-field))
|
|
|
|
1))
|
|
|
|
(prompt-pos-check input-field)
|
|
|
|
(sync-input-field-edit-pos input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define goto-end-of-last-line
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(goto-begin-of-last-line input-field)
|
|
|
|
(goto-end-of-line input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define goto-next-forward
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field . chars)
|
|
|
|
(if (move-forward input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(let loop ()
|
2006-04-06 17:40:59 -04:00
|
|
|
(let ((sign (sign-under-cursor input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (and sign
|
|
|
|
(memq sign chars))
|
|
|
|
#t
|
2006-04-06 17:40:59 -04:00
|
|
|
(if (move-forward input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(loop)
|
|
|
|
#f))))
|
|
|
|
#f)))
|
|
|
|
|
|
|
|
(define goto-next-not-forward
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field . chars)
|
|
|
|
(if (move-forward input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(let loop ()
|
2006-04-06 17:40:59 -04:00
|
|
|
(let ((sign (sign-under-cursor input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (and sign
|
|
|
|
(not (memq sign chars)))
|
|
|
|
#t
|
2006-04-06 17:40:59 -04:00
|
|
|
(if (move-forward input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(loop)
|
|
|
|
#f))))
|
|
|
|
#f)))
|
|
|
|
|
|
|
|
(define goto-next-backward
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field . chars)
|
|
|
|
(if (move-backward input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(let loop ()
|
2006-04-06 17:40:59 -04:00
|
|
|
(let ((sign (sign-under-cursor input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (and sign
|
|
|
|
(memq sign chars))
|
2006-03-28 04:37:38 -05:00
|
|
|
(begin
|
2006-04-06 17:40:59 -04:00
|
|
|
(prompt-pos-check input-field)
|
2006-03-28 04:37:38 -05:00
|
|
|
#t)
|
2006-04-06 17:40:59 -04:00
|
|
|
(if (move-backward input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(loop)
|
2006-03-28 04:37:38 -05:00
|
|
|
(begin
|
2006-04-06 17:40:59 -04:00
|
|
|
(prompt-pos-check input-field)
|
2006-03-28 04:37:38 -05:00
|
|
|
#f)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
#f)))
|
|
|
|
|
|
|
|
(define goto-next-not-backward
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field . chars)
|
|
|
|
(if (move-backward input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(let loop ()
|
2006-04-06 17:40:59 -04:00
|
|
|
(let ((sign (sign-under-cursor input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (and sign
|
|
|
|
(not (memq sign chars)))
|
2006-03-28 04:37:38 -05:00
|
|
|
(begin
|
2006-04-06 17:40:59 -04:00
|
|
|
(prompt-pos-check input-field)
|
2006-03-28 04:37:38 -05:00
|
|
|
#t)
|
2006-04-06 17:40:59 -04:00
|
|
|
(if (move-backward input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(loop)
|
2006-03-28 04:37:38 -05:00
|
|
|
(begin
|
2006-04-06 17:40:59 -04:00
|
|
|
(prompt-pos-check input-field)
|
2006-03-28 04:37:38 -05:00
|
|
|
#f)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
#f)))
|
|
|
|
|
|
|
|
;; goto END
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; others
|
|
|
|
(define toggle-insert
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(set-input-field-insert-active!
|
|
|
|
input-field
|
|
|
|
(not (input-field-insert-active input-field)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
;; others END
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; behavior methods END
|
|
|
|
;;===============================================================================
|
|
|
|
|
|
|
|
;;===============================================================================
|
|
|
|
;; "mutate" functions and few others
|
|
|
|
|
2006-04-06 17:40:59 -04:00
|
|
|
(define restore-input-field
|
|
|
|
(lambda (input-field)
|
|
|
|
(set-input-field-edit-lines!
|
|
|
|
input-field
|
|
|
|
(string->input-field-edit-lines input-field
|
|
|
|
(input-field-text-wp input-field)))
|
|
|
|
(sync-input-field-edit-pos input-field)
|
|
|
|
#t))
|
|
|
|
|
2005-11-11 03:01:07 -05:00
|
|
|
(define input-field-refresh
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(really-send-input-field input-field 'refresh-all)))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
;(define input-field-move-up
|
2006-04-06 17:40:59 -04:00
|
|
|
; (lambda (input-field)
|
|
|
|
; (let ((y-loc (input-field-y-loc input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
; (if (> y-loc 1)
|
|
|
|
; (begin
|
2006-04-06 17:40:59 -04:00
|
|
|
; (paint-black input-field)
|
|
|
|
; (set-input-field-y-loc! input-field (- y-loc
|
2005-11-11 03:01:07 -05:00
|
|
|
; 1))
|
|
|
|
; #t)
|
|
|
|
; #f))))
|
|
|
|
|
|
|
|
;(define input-field-move-down
|
2006-04-06 17:40:59 -04:00
|
|
|
; (lambda (input-field)
|
|
|
|
; (let ((y-loc (input-field-y-loc input-field)))
|
|
|
|
; (if (< (+ y-loc (input-field-y-dim input-field))
|
|
|
|
; (- (getmaxy (input-field-window input-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
; 1))
|
|
|
|
; (begin
|
2006-04-06 17:40:59 -04:00
|
|
|
; (paint-black input-field)
|
|
|
|
; (set-input-field-y-loc! input-field (+ y-loc
|
2005-11-11 03:01:07 -05:00
|
|
|
; 1))
|
|
|
|
; #t)
|
|
|
|
; #f))))
|
|
|
|
|
|
|
|
;(define input-field-move-left
|
2006-04-06 17:40:59 -04:00
|
|
|
; (lambda (input-field)
|
|
|
|
; (let ((x-loc (input-field-x-loc input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
; (if (> x-loc 1)
|
|
|
|
; (begin
|
2006-04-06 17:40:59 -04:00
|
|
|
; (paint-black input-field)
|
|
|
|
; (set-input-field-x-loc! input-field (- x-loc
|
2005-11-11 03:01:07 -05:00
|
|
|
; 1))
|
|
|
|
; #t)
|
|
|
|
; #f))))
|
|
|
|
|
|
|
|
;(define input-field-move-right
|
2006-04-06 17:40:59 -04:00
|
|
|
; (lambda (input-field)
|
|
|
|
; (let ((x-loc (input-field-x-loc input-field)))
|
|
|
|
; (if (< (+ x-loc (input-field-x-dim input-field))
|
|
|
|
; (- (getmaxx (input-field-window input-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
; 1))
|
|
|
|
; (begin
|
2006-04-06 17:40:59 -04:00
|
|
|
; (paint-black input-field)
|
|
|
|
; (set-input-field-x-loc! input-field (+ x-loc
|
2005-11-11 03:01:07 -05:00
|
|
|
; 1))
|
|
|
|
; #t)
|
|
|
|
; #f))))
|
|
|
|
|
|
|
|
(define input-field-move
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field x y)
|
|
|
|
(let ((win (input-field-window input-field)))
|
2006-03-28 04:37:38 -05:00
|
|
|
(if (and (>= x 0)
|
|
|
|
(>= y 0)
|
2006-04-06 17:40:59 -04:00
|
|
|
(<= (+ x (input-field-x-dim input-field)) ; (input-field-x-loc input-field)) ;; + x-loc
|
2006-03-28 04:37:38 -05:00
|
|
|
(getmaxx win))
|
2006-04-06 17:40:59 -04:00
|
|
|
(<= (+ y (input-field-y-dim input-field)) ; (input-field-y-loc input-field)) ;; + y-loc
|
2006-03-28 04:37:38 -05:00
|
|
|
(getmaxy win)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(begin
|
2006-04-06 17:40:59 -04:00
|
|
|
(paint-black input-field)
|
|
|
|
(set-input-field-x-loc! input-field x)
|
|
|
|
(set-input-field-y-loc! input-field y)
|
|
|
|
#t)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f))))
|
|
|
|
|
|
|
|
(define input-field-resize
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field x y)
|
|
|
|
(let ((win (input-field-window input-field)))
|
2006-03-28 04:37:38 -05:00
|
|
|
(if (and (>= x 0)
|
|
|
|
(>= y 0)
|
2006-04-06 17:40:59 -04:00
|
|
|
(<= (+ x (input-field-x-loc input-field)) ; (input-field-x-dim input-field)) ;; + x-dim
|
2006-03-28 04:37:38 -05:00
|
|
|
(getmaxx win))
|
2006-04-06 17:40:59 -04:00
|
|
|
(<= (+ y (input-field-y-loc input-field)) ; (input-field-y-dim input-field)) ;; + y-dim
|
2006-03-28 04:37:38 -05:00
|
|
|
(getmaxy win)))
|
2006-04-06 17:40:59 -04:00
|
|
|
(let* ((prompt (input-field-prompt input-field))
|
2006-03-28 04:37:38 -05:00
|
|
|
(x-pos (if prompt
|
|
|
|
(string-length prompt)
|
|
|
|
0)))
|
2006-04-06 17:40:59 -04:00
|
|
|
(paint-black input-field)
|
|
|
|
(set-input-field-x-dim! input-field x)
|
|
|
|
(set-input-field-y-dim! input-field y)
|
|
|
|
(set-input-field-edit-lines!
|
|
|
|
input-field
|
|
|
|
(string->input-field-edit-lines input-field
|
|
|
|
(input-field-text-wp input-field)))
|
|
|
|
(sync-input-field-edit-pos input-field)
|
|
|
|
(legalize-position input-field)
|
|
|
|
(if (not (legal-offsets? input-field))
|
|
|
|
(legalize-offsets input-field))
|
|
|
|
#t)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f))))
|
|
|
|
|
|
|
|
(define input-field-toggle-x-scroll
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(let* ((prompt (input-field-prompt input-field))
|
2006-03-28 04:37:38 -05:00
|
|
|
(x-pos (if prompt
|
|
|
|
(string-length prompt)
|
|
|
|
0)))
|
2006-04-06 17:40:59 -04:00
|
|
|
(paint-black input-field)
|
|
|
|
(set-input-field-x-scroll! input-field
|
|
|
|
(not (input-field-x-scroll input-field)))
|
|
|
|
(set-input-field-edit-lines!
|
|
|
|
input-field
|
|
|
|
(string->input-field-edit-lines input-field
|
|
|
|
(input-field-text-wp input-field)))
|
|
|
|
(sync-input-field-edit-pos input-field)
|
|
|
|
(legalize-position input-field)
|
|
|
|
(if (not (legal-offsets? input-field))
|
|
|
|
(legalize-offsets input-field))
|
|
|
|
#t)))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define input-field-toggle-y-scroll
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(let* ((prompt (input-field-prompt input-field))
|
2006-03-28 04:37:38 -05:00
|
|
|
(x-pos (if prompt
|
|
|
|
(string-length prompt)
|
|
|
|
0)))
|
2006-04-06 17:40:59 -04:00
|
|
|
(paint-black input-field)
|
|
|
|
(set-input-field-y-scroll! input-field
|
|
|
|
(not (input-field-y-scroll input-field)))
|
|
|
|
(set-input-field-edit-lines!
|
|
|
|
input-field
|
|
|
|
(string->input-field-edit-lines input-field
|
|
|
|
(input-field-text-wp input-field)))
|
|
|
|
(sync-input-field-edit-pos input-field)
|
|
|
|
(legalize-position input-field)
|
|
|
|
(if (not (legal-offsets? input-field))
|
|
|
|
(legalize-offsets input-field))
|
|
|
|
#t)))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
;; mutate-functions END
|
|
|
|
;;===============================================================================
|
|
|
|
|
|
|
|
;;===============================================================================
|
|
|
|
;; helpfunctions (converter, predicates...)
|
|
|
|
|
|
|
|
(define string->edit-lines
|
|
|
|
(lambda (str)
|
|
|
|
(let loop ((chars (string->list str)))
|
|
|
|
(if (null? chars)
|
|
|
|
'()
|
|
|
|
(call-with-values
|
|
|
|
(lambda ()
|
|
|
|
(split-after-first-newline chars))
|
|
|
|
(lambda (line chars)
|
|
|
|
(cons line
|
|
|
|
(loop chars))))))))
|
|
|
|
|
|
|
|
(define string->edit-lines-with-null
|
|
|
|
(lambda (str)
|
|
|
|
(let* ((edit-lines (let loop ((chars (string->list str)))
|
|
|
|
(if (null? chars)
|
|
|
|
'()
|
|
|
|
(call-with-values
|
|
|
|
(lambda ()
|
|
|
|
(split-after-first-newline chars))
|
|
|
|
(lambda (line chars)
|
|
|
|
(cons line
|
|
|
|
(loop chars)))))))
|
|
|
|
(last-line (if (null? edit-lines)
|
|
|
|
#f
|
|
|
|
(last edit-lines))))
|
|
|
|
(if (and last-line
|
|
|
|
(not (null? last-line))
|
|
|
|
(char=? (last last-line)
|
|
|
|
#\newline))
|
|
|
|
(append edit-lines '(()))
|
|
|
|
edit-lines))))
|
|
|
|
|
|
|
|
(define split-after-first-newline
|
|
|
|
(lambda (chars)
|
|
|
|
(let loop ((line '())
|
|
|
|
(chars chars))
|
|
|
|
(if (null? chars)
|
|
|
|
(values (reverse line) chars)
|
|
|
|
(let ((char (car chars))
|
|
|
|
(rest (cdr chars)))
|
|
|
|
(if (char=? char #\newline)
|
|
|
|
(values (reverse (cons char line))
|
|
|
|
rest)
|
|
|
|
(loop (cons char line)
|
|
|
|
rest)))))))
|
|
|
|
|
2006-04-06 17:40:59 -04:00
|
|
|
(define edit-line->input-field-lines
|
|
|
|
(lambda (input-field edit-line)
|
|
|
|
(let ((x-dim (input-field-x-dim input-field))
|
|
|
|
(x-scroll (input-field-x-scroll input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (or x-scroll
|
|
|
|
(null? edit-line))
|
|
|
|
(list edit-line)
|
|
|
|
(let loop ((edit-line edit-line))
|
|
|
|
(if (null? edit-line)
|
|
|
|
'()
|
|
|
|
(call-with-values
|
|
|
|
(lambda ()
|
2006-04-06 17:40:59 -04:00
|
|
|
(split-input-field-line-from-edit-line x-dim edit-line))
|
|
|
|
(lambda (input-field-line edit-line)
|
|
|
|
(cons input-field-line
|
2005-11-11 03:01:07 -05:00
|
|
|
(loop edit-line))))))))))
|
|
|
|
|
2006-04-06 17:40:59 -04:00
|
|
|
(define edit-lines->input-field-lines
|
|
|
|
(lambda (input-field edit-lines)
|
2005-11-11 03:01:07 -05:00
|
|
|
(cat (map (lambda (edit-line)
|
2006-04-06 17:40:59 -04:00
|
|
|
(edit-line->input-field-lines input-field edit-line))
|
2005-11-11 03:01:07 -05:00
|
|
|
edit-lines))))
|
|
|
|
|
2006-04-06 17:40:59 -04:00
|
|
|
(define split-input-field-line-from-edit-line
|
2005-11-11 03:01:07 -05:00
|
|
|
(lambda (x-dim edit-line)
|
2006-04-06 17:40:59 -04:00
|
|
|
(let loop ((input-field-line '())
|
2005-11-11 03:01:07 -05:00
|
|
|
(rest edit-line)
|
|
|
|
(space-left x-dim))
|
|
|
|
(if (null? rest)
|
2006-04-06 17:40:59 -04:00
|
|
|
(values (reverse input-field-line)
|
2005-11-11 03:01:07 -05:00
|
|
|
rest)
|
|
|
|
(let ((char (car rest)))
|
|
|
|
(cond ((char=? char #\newline)
|
|
|
|
(values (reverse (cons char
|
2006-04-06 17:40:59 -04:00
|
|
|
input-field-line))
|
2005-11-11 03:01:07 -05:00
|
|
|
(cdr rest)))
|
|
|
|
((zero? space-left)
|
2006-04-06 17:40:59 -04:00
|
|
|
(values (reverse input-field-line)
|
2005-11-11 03:01:07 -05:00
|
|
|
rest))
|
|
|
|
(else
|
2006-04-06 17:40:59 -04:00
|
|
|
(loop (cons char input-field-line)
|
2005-11-11 03:01:07 -05:00
|
|
|
(cdr rest)
|
|
|
|
(- space-left 1)))))))))
|
|
|
|
|
2006-04-06 17:40:59 -04:00
|
|
|
(define input-field-lines->edit-lines
|
|
|
|
(lambda (input-field-lines)
|
|
|
|
(let loop ((rest input-field-lines))
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (null? rest)
|
|
|
|
'()
|
|
|
|
(call-with-values
|
|
|
|
(lambda ()
|
2006-04-06 17:40:59 -04:00
|
|
|
(split-edit-line-from-input-field-lines rest))
|
2005-11-11 03:01:07 -05:00
|
|
|
(lambda (edit-line rest)
|
|
|
|
(cons edit-line
|
|
|
|
(loop rest))))))))
|
|
|
|
|
2006-04-06 17:40:59 -04:00
|
|
|
(define split-edit-line-from-input-field-lines
|
|
|
|
(lambda (input-field-lines)
|
2005-11-11 03:01:07 -05:00
|
|
|
(let loop ((edit-line '())
|
2006-04-06 17:40:59 -04:00
|
|
|
(rest input-field-lines))
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (null? rest)
|
|
|
|
(values (reverse edit-line) '())
|
|
|
|
(let ((rev-line (reverse (car rest))))
|
|
|
|
(if (null? rev-line)
|
|
|
|
(values '() (cdr rest))
|
|
|
|
(if (char=? (car rev-line)
|
|
|
|
#\newline)
|
|
|
|
(values (reverse (append rev-line
|
|
|
|
edit-line))
|
|
|
|
(cdr rest))
|
|
|
|
(loop (append rev-line
|
|
|
|
edit-line)
|
|
|
|
(cdr rest)))))))))
|
|
|
|
|
2006-04-06 17:40:59 -04:00
|
|
|
(define string->input-field-edit-lines
|
|
|
|
(lambda (input-field string)
|
2005-11-11 03:01:07 -05:00
|
|
|
(let* ((edit-lines (string->edit-lines-with-null string))
|
2006-04-06 17:40:59 -04:00
|
|
|
(input-field-lines (edit-lines->input-field-lines input-field edit-lines))
|
|
|
|
(input-field-lines-cut (if (input-field-y-scroll input-field)
|
|
|
|
input-field-lines
|
|
|
|
(take input-field-lines
|
|
|
|
(input-field-y-dim input-field)))))
|
|
|
|
(input-field-lines->edit-lines input-field-lines-cut))))
|
|
|
|
|
|
|
|
(define input-field->edit-pos
|
|
|
|
(lambda (input-field)
|
|
|
|
(let ((x-pos (+ (input-field-x-offset input-field)
|
|
|
|
(input-field-x-pos input-field)))
|
|
|
|
(y-pos (+ (input-field-y-offset input-field)
|
|
|
|
(input-field-y-pos input-field)))
|
|
|
|
(x-scroll (input-field-x-scroll input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(if x-scroll
|
|
|
|
(values x-pos y-pos)
|
2006-04-06 17:40:59 -04:00
|
|
|
(let loop ((edit-lines (input-field-edit-lines input-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
(y-edit-pos 0)
|
|
|
|
(y-pos y-pos))
|
|
|
|
(if (null? edit-lines)
|
|
|
|
(let ((y-edit-pos (- y-edit-pos 1)))
|
2006-04-06 17:40:59 -04:00
|
|
|
(values (length (list-ref (input-field-edit-lines input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
y-edit-pos))
|
|
|
|
y-edit-pos))
|
|
|
|
(let* ((edit-line (car edit-lines))
|
2006-04-06 17:40:59 -04:00
|
|
|
(num-input-field-lines
|
|
|
|
(length
|
|
|
|
(edit-line->input-field-lines input-field edit-line))))
|
|
|
|
(if (< y-pos num-input-field-lines)
|
2005-11-11 03:01:07 -05:00
|
|
|
(values (+ (* y-pos
|
2006-04-06 17:40:59 -04:00
|
|
|
(input-field-x-dim input-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
x-pos)
|
|
|
|
y-edit-pos)
|
|
|
|
(loop (cdr edit-lines)
|
|
|
|
(+ y-edit-pos 1)
|
2006-04-06 17:40:59 -04:00
|
|
|
(- y-pos num-input-field-lines))))))))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
2006-04-06 17:40:59 -04:00
|
|
|
(define edit-pos->input-field-pos
|
|
|
|
(lambda (input-field x-edit-pos y-edit-pos)
|
|
|
|
(if (input-field-x-scroll input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(values x-edit-pos y-edit-pos)
|
2006-04-06 17:40:59 -04:00
|
|
|
(let loop ((edit-lines (input-field-edit-lines input-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
(y-edit-pos y-edit-pos)
|
|
|
|
(y-pos 0))
|
|
|
|
(if (null? edit-lines)
|
2006-04-06 17:40:59 -04:00
|
|
|
'error--edit-pos->input-field-pos
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (zero? y-edit-pos)
|
2006-04-06 17:40:59 -04:00
|
|
|
(let ((x-dim (input-field-x-dim input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(values (modulo x-edit-pos
|
|
|
|
x-dim)
|
|
|
|
(+ y-pos
|
|
|
|
(quotient x-edit-pos
|
|
|
|
x-dim))))
|
|
|
|
(loop (cdr edit-lines)
|
|
|
|
(- y-edit-pos 1)
|
|
|
|
(+ y-pos
|
|
|
|
(length
|
2006-04-06 17:40:59 -04:00
|
|
|
(edit-line->input-field-lines input-field
|
|
|
|
(car edit-lines)))))))))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; legalize-position
|
|
|
|
(define legalize-position
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(let* ((x-edit-pos (input-field-x-edit-pos input-field))
|
|
|
|
(y-edit-pos (input-field-y-edit-pos input-field))
|
|
|
|
(current-line (list-ref (input-field-edit-lines input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
y-edit-pos))
|
|
|
|
(current-line-len (length current-line)))
|
|
|
|
(if (or (> x-edit-pos current-line-len)
|
|
|
|
(and (> current-line-len 0)
|
|
|
|
(= x-edit-pos current-line-len)
|
|
|
|
(char=? (last current-line)
|
|
|
|
#\newline)))
|
2006-04-06 17:40:59 -04:00
|
|
|
(goto-end-of-line input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
#t))
|
|
|
|
|
2006-03-28 04:37:38 -05:00
|
|
|
(define prompt-pos-check
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(if (zero? (input-field-y-edit-pos input-field))
|
|
|
|
(let ((prompt (input-field-prompt input-field)))
|
2006-03-28 04:37:38 -05:00
|
|
|
(if prompt
|
|
|
|
(let ((prompt-length (string-length prompt)))
|
2006-04-06 17:40:59 -04:00
|
|
|
(if (< (input-field-x-edit-pos input-field)
|
2006-03-28 04:37:38 -05:00
|
|
|
prompt-length)
|
2006-04-06 17:40:59 -04:00
|
|
|
(set-input-field-x-edit-pos! input-field prompt-length))))))))
|
2006-03-28 04:37:38 -05:00
|
|
|
|
2005-11-11 03:01:07 -05:00
|
|
|
(define legal-offsets?
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(let ((x (input-field-x-pos input-field))
|
|
|
|
(y (input-field-y-pos input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(and (>= x 0)
|
2006-04-06 17:40:59 -04:00
|
|
|
(< x (input-field-x-dim input-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
(>= y 0)
|
2006-04-06 17:40:59 -04:00
|
|
|
(< y (input-field-y-dim input-field))))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
|
|
|
|
(define legalize-offsets
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(let ((x-pos (input-field-x-pos input-field))
|
|
|
|
(x-offset (input-field-x-offset input-field))
|
|
|
|
(x-dim (input-field-x-dim input-field))
|
|
|
|
(y-pos (input-field-y-pos input-field))
|
|
|
|
(y-offset (input-field-y-offset input-field))
|
|
|
|
(y-dim (input-field-y-dim input-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (< x-pos 0)
|
|
|
|
(begin
|
|
|
|
(set! x-offset (+ x-offset x-pos))
|
|
|
|
(set! x-pos 0)))
|
|
|
|
(if (> (+ x-pos 1)
|
|
|
|
x-dim)
|
|
|
|
(let ((dx (- (+ x-pos 1)
|
|
|
|
x-dim)))
|
|
|
|
(set! x-offset (+ x-offset dx))
|
|
|
|
(set! x-pos (- x-pos dx))))
|
|
|
|
(if (< y-pos 0)
|
|
|
|
(begin
|
|
|
|
(set! y-offset (+ y-offset y-pos))
|
|
|
|
(set! y-pos 0)))
|
|
|
|
(if (> (+ y-pos 1)
|
|
|
|
y-dim)
|
|
|
|
(let ((dy (- (+ y-pos 1)
|
|
|
|
y-dim)))
|
|
|
|
(set! y-offset (+ y-offset dy))
|
|
|
|
(set! y-pos (- y-pos dy))))
|
2006-04-06 17:40:59 -04:00
|
|
|
(set-input-field-x-pos! input-field x-pos)
|
|
|
|
(set-input-field-x-offset! input-field x-offset)
|
|
|
|
(set-input-field-y-pos! input-field y-pos)
|
|
|
|
(set-input-field-y-offset! input-field y-offset)
|
2005-11-11 03:01:07 -05:00
|
|
|
#t)))
|
|
|
|
;; legalize-position END
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; predicates
|
|
|
|
|
|
|
|
(define first-line?
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(zero? (input-field-y-edit-pos input-field))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define last-line?
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(= (+ (input-field-y-edit-pos input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
1)
|
2006-04-06 17:40:59 -04:00
|
|
|
(length (input-field-edit-lines input-field)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define begin-of-line?
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(zero? (input-field-x-edit-pos input-field))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define end-of-line?
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(let* ((x-edit-pos (input-field-x-edit-pos input-field))
|
|
|
|
(y-edit-pos (input-field-y-edit-pos input-field))
|
|
|
|
(edit-line (list-ref (input-field-edit-lines input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
y-edit-pos)))
|
|
|
|
(or (= x-edit-pos
|
|
|
|
(length edit-line))
|
|
|
|
(char=? (list-ref edit-line
|
|
|
|
x-edit-pos)
|
|
|
|
#\newline)))))
|
|
|
|
|
2006-04-06 17:40:59 -04:00
|
|
|
(define cursor-at-edit-end-position?
|
|
|
|
(lambda (input-field)
|
|
|
|
(and (end-of-line? input-field)
|
|
|
|
(last-line? input-field))))
|
|
|
|
|
2005-11-11 03:01:07 -05:00
|
|
|
(define left-border?
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(= (input-field-x-pos input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
0)))
|
|
|
|
|
|
|
|
(define right-border?
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(= (input-field-x-pos input-field)
|
|
|
|
(- (input-field-x-dim input-field) 1))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define lower-border?
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(= (input-field-y-pos input-field)
|
|
|
|
(- (input-field-y-dim input-field) 1))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define upper-border?
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(= (input-field-y-pos input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
0)))
|
2006-04-06 17:40:59 -04:00
|
|
|
|
|
|
|
(define space-left?
|
|
|
|
(lambda (input-field)
|
|
|
|
(not (and (lower-border? input-field)
|
|
|
|
(right-border? input-field)))))
|
|
|
|
|
2005-11-11 03:01:07 -05:00
|
|
|
;; predicates END
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; selectors
|
|
|
|
|
|
|
|
(define sign-under-cursor
|
2006-04-06 17:40:59 -04:00
|
|
|
(lambda (input-field)
|
|
|
|
(let* ((x-edit-pos (input-field-x-edit-pos input-field))
|
|
|
|
(y-edit-pos (input-field-y-edit-pos input-field))
|
|
|
|
(current-line (list-ref (input-field-edit-lines input-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
y-edit-pos))
|
|
|
|
(current-line-len (length current-line)))
|
|
|
|
(if (< x-edit-pos current-line-len)
|
|
|
|
(list-ref current-line x-edit-pos)
|
|
|
|
#f))))
|
|
|
|
|
|
|
|
;; selectors END
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; helpfunctions END
|
|
|
|
;;===============================================================================
|
|
|
|
|
2006-04-06 17:40:59 -04:00
|
|
|
|
2005-11-11 03:01:07 -05:00
|
|
|
;;===============================================================================
|
|
|
|
;; "primitives"
|
|
|
|
|
2006-04-06 17:40:59 -04:00
|
|
|
(define id
|
|
|
|
(lambda (x)
|
|
|
|
x))
|
|
|
|
|
2005-11-11 03:01:07 -05:00
|
|
|
(define caddddr
|
|
|
|
(lambda (x)
|
|
|
|
(car (cddddr x))))
|
|
|
|
|
2006-03-28 04:37:38 -05:00
|
|
|
(define cadddddr
|
|
|
|
(lambda (x)
|
|
|
|
(car (cdr (cddddr x)))))
|
|
|
|
|
2005-11-11 03:01:07 -05:00
|
|
|
(define last
|
|
|
|
(lambda (lst)
|
|
|
|
(if (null? lst)
|
|
|
|
'error--last
|
|
|
|
(car (reverse lst)))))
|
|
|
|
|
|
|
|
(define fill-up
|
|
|
|
(lambda (lst len elem)
|
|
|
|
(append lst
|
|
|
|
(let loop ((n (- len
|
|
|
|
(length lst))))
|
|
|
|
(if (< n 0)
|
2006-04-06 17:40:59 -04:00
|
|
|
'() ;'error--fill-up
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (zero? n)
|
|
|
|
'()
|
|
|
|
(cons elem
|
|
|
|
(loop (- n 1)))))))))
|
|
|
|
|
|
|
|
(define cat
|
|
|
|
(lambda (lst-lst)
|
|
|
|
(if (null? lst-lst)
|
|
|
|
'()
|
|
|
|
(append (car lst-lst)
|
|
|
|
(cat (cdr lst-lst))))))
|
|
|
|
|
|
|
|
(define split
|
|
|
|
(lambda (lst n)
|
|
|
|
(let loop ((fst '())
|
|
|
|
(scnd lst)
|
|
|
|
(n n))
|
|
|
|
(if (or (null? scnd)
|
|
|
|
(zero? n))
|
|
|
|
(values (reverse fst) scnd)
|
|
|
|
(loop (cons (car scnd)
|
|
|
|
fst)
|
|
|
|
(cdr scnd)
|
|
|
|
(- n 1))))))
|
|
|
|
|
|
|
|
(define remove
|
|
|
|
(lambda (lst pos)
|
|
|
|
(append (take lst pos)
|
|
|
|
(drop lst (+ pos 1)))))
|
|
|
|
|
|
|
|
(define insert
|
|
|
|
(lambda (lst n elem)
|
|
|
|
(if (zero? n)
|
|
|
|
(cons elem lst)
|
|
|
|
(cons (car lst)
|
|
|
|
(insert (cdr lst)
|
|
|
|
(- n 1)
|
|
|
|
elem)))))
|
|
|
|
|
|
|
|
(define replace
|
|
|
|
(lambda (lst n elem)
|
|
|
|
(if (zero? n)
|
|
|
|
(cons elem
|
|
|
|
(if (null? lst)
|
|
|
|
lst
|
|
|
|
(cdr lst)))
|
|
|
|
(cons (car lst)
|
|
|
|
(replace (cdr lst)
|
|
|
|
(- n 1)
|
|
|
|
elem)))))
|
|
|
|
|
2006-04-06 17:40:59 -04:00
|
|
|
;; "save" versions of take and drop
|
|
|
|
|
2005-11-11 03:01:07 -05:00
|
|
|
(define take
|
|
|
|
(lambda (lst n)
|
|
|
|
(if (or (null? lst)
|
|
|
|
(zero? n))
|
|
|
|
'()
|
|
|
|
(cons (car lst)
|
|
|
|
(take (cdr lst)
|
|
|
|
(- n 1))))))
|
|
|
|
|
|
|
|
(define drop
|
|
|
|
(lambda (lst n)
|
|
|
|
(if (or (null? lst)
|
|
|
|
(zero? n))
|
|
|
|
lst
|
|
|
|
(drop (cdr lst)
|
|
|
|
(- n 1)))))
|
|
|
|
|