2006-03-28 04:37:38 -05:00
|
|
|
|
|
|
|
;;===============================================================================
|
|
|
|
;; exeptions
|
|
|
|
|
|
|
|
(define-condition-type 'buffer-full '(error))
|
|
|
|
(define buffer-full? (condition-predicate 'buffer-full))
|
|
|
|
|
|
|
|
;; exeptions END
|
|
|
|
;;===============================================================================
|
|
|
|
|
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-03-28 04:37:38 -05:00
|
|
|
x-loc y-loc ;; position of INPUT-I-F-FIELD
|
|
|
|
x-dim y-dim ;; size of INPUT-I-F-FIELD
|
|
|
|
x-pos y-pos ;; cursor position in INPUT-I-F-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-03-28 04:37:38 -05:00
|
|
|
(prompt input-if-field-prompt set-input-if-field-prompt!)
|
|
|
|
(default-text input-if-field-default-text)
|
|
|
|
(edit-lines input-if-field-edit-lines set-input-if-field-edit-lines!)
|
|
|
|
(window input-if-field-window set-input-if-field-window!)
|
|
|
|
(behavior input-if-field-behavior set-input-if-field-behavior!)
|
|
|
|
(insert-active input-if-field-insert-active set-input-if-field-insert-active!)
|
|
|
|
(x-loc input-if-field-x-loc set-input-if-field-x-loc!)
|
|
|
|
(y-loc input-if-field-y-loc set-input-if-field-y-loc!)
|
|
|
|
(x-dim input-if-field-x-dim set-input-if-field-x-dim!)
|
|
|
|
(y-dim input-if-field-y-dim set-input-if-field-y-dim!)
|
|
|
|
(x-pos input-if-field-x-pos set-input-if-field-x-pos!)
|
|
|
|
(y-pos input-if-field-y-pos set-input-if-field-y-pos!)
|
|
|
|
(x-edit-pos input-if-field-x-edit-pos set-input-if-field-x-edit-pos!)
|
|
|
|
(y-edit-pos input-if-field-y-edit-pos set-input-if-field-y-edit-pos!)
|
|
|
|
(x-offset input-if-field-x-offset set-input-if-field-x-offset!)
|
|
|
|
(y-offset input-if-field-y-offset set-input-if-field-y-offset!)
|
|
|
|
(x-scroll input-if-field-x-scroll set-input-if-field-x-scroll!)
|
|
|
|
(y-scroll input-if-field-y-scroll set-input-if-field-y-scroll!))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define-record-discloser :input-field
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(list 'input-field
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-default-text input-i-f-field))))
|
|
|
|
|
|
|
|
(define input-if-field-init-text
|
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let ((prompt (input-if-field-prompt input-i-f-field)))
|
|
|
|
(if prompt
|
|
|
|
(string-append prompt
|
|
|
|
(input-if-field-default-text input-i-f-field))
|
|
|
|
(input-if-field-default-text input-i-f-field)))))
|
|
|
|
|
|
|
|
(define input-field-prompt input-if-field-prompt)
|
|
|
|
(define set-input-field-prompt! set-input-if-field-prompt!)
|
|
|
|
(define input-field-x-edit-pos input-if-field-x-edit-pos)
|
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-03-28 04:37:38 -05:00
|
|
|
(let ((input-i-f-field (really-make-input-field prompt
|
|
|
|
default-text
|
2005-11-11 03:01:07 -05:00
|
|
|
#f
|
|
|
|
#f
|
|
|
|
behavior
|
|
|
|
insert-active
|
2006-03-28 04:37:38 -05:00
|
|
|
#f #f
|
|
|
|
x-dim y-dim
|
|
|
|
prompt-length 0
|
|
|
|
prompt-length 0
|
|
|
|
0 0
|
2005-11-11 03:01:07 -05:00
|
|
|
x-scroll y-scroll)))
|
2006-03-28 04:37:38 -05:00
|
|
|
(set-input-if-field-edit-lines! input-i-f-field
|
|
|
|
(string->input-if-field-edit-lines input-i-f-field
|
|
|
|
(input-if-field-init-text input-i-f-field)))
|
|
|
|
input-i-f-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-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field window x y)
|
|
|
|
(set-input-if-field-window! input-i-f-field window)
|
|
|
|
(set-input-if-field-y-loc! input-i-f-field y)
|
|
|
|
(set-input-if-field-x-loc! input-i-f-field x)
|
2005-11-11 03:01:07 -05:00
|
|
|
(set! input-fields-lookup-list
|
2006-03-28 04:37:38 -05:00
|
|
|
(cons (make-weak-pointer input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(util-filter (lambda (x) x)
|
|
|
|
input-fields-lookup-list)))
|
2006-03-28 04:37:38 -05:00
|
|
|
(refresh-all input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(wrefresh window)))
|
|
|
|
|
|
|
|
(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
|
|
|
|
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-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-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-03-28 04:37:38 -05:00
|
|
|
(if (eq? input-i-f-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-03-28 04:37:38 -05:00
|
|
|
(let loop ((input-i-f-field-lst input-fields-lookup-list))
|
|
|
|
(if (null? input-i-f-field-lst)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f
|
2006-03-28 04:37:38 -05:00
|
|
|
(let* ((input-i-f-field (weak-pointer-ref (car input-i-f-field-lst)))
|
|
|
|
(win (if input-i-f-field
|
|
|
|
(input-if-field-window input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f)))
|
|
|
|
(if (eq? window win)
|
2006-03-28 04:37:38 -05:00
|
|
|
(or (cursor-over-this-input-field? x y input-i-f-field)
|
|
|
|
(loop (cdr input-i-f-field-lst)))
|
|
|
|
(loop (cdr input-i-f-field-lst)))))))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define cursor-over-this-input-field?
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (cursor-x cursor-y input-i-f-field)
|
|
|
|
(let* ((upper-left-x (input-if-field-x-loc input-i-f-field))
|
|
|
|
(upper-left-y (input-if-field-y-loc input-i-f-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
(lower-right-x (- (+ upper-left-x
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-x-dim input-i-f-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
1))
|
|
|
|
(lower-right-y (- (+ upper-left-y
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-y-dim input-i-f-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-03-28 04:37:38 -05:00
|
|
|
input-i-f-field
|
2005-11-11 03:01:07 -05:00
|
|
|
#f))))
|
|
|
|
;; "basics" - remove / install-input-field & cursor-over-input-field END
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
;; "basics" - selectors
|
|
|
|
|
|
|
|
;; TODOO - vielleicht gibt's sowas wie "export-as"
|
|
|
|
|
2006-03-28 04:37:38 -05:00
|
|
|
(define input-field-default-text input-if-field-default-text)
|
|
|
|
(define input-field-x-location input-if-field-x-loc)
|
|
|
|
(define input-field-y-location input-if-field-y-loc)
|
|
|
|
(define input-field-x-size input-if-field-x-dim)
|
|
|
|
(define input-field-y-size input-if-field-y-dim)
|
|
|
|
(define input-field-column input-if-field-x-edit-pos)
|
|
|
|
(define input-field-line input-if-field-y-edit-pos)
|
|
|
|
(define input-field-x-scroll input-if-field-x-scroll)
|
|
|
|
(define input-field-y-scroll input-if-field-y-scroll)
|
|
|
|
(define input-field-insert input-if-field-insert-active)
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define input-field-text
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let* ((prompt (input-if-field-prompt input-i-f-field))
|
|
|
|
(lst (cat (input-if-field-edit-lines input-i-f-field))))
|
|
|
|
(list->string (if prompt
|
|
|
|
(drop lst (string-length prompt))
|
|
|
|
lst)))))
|
|
|
|
|
|
|
|
(define set-input-field-text!
|
|
|
|
(lambda (input-i-f-field text)
|
|
|
|
; (set-input-if-field-edit-lines! input-i-f-field
|
|
|
|
; (string->edit-lines input-i-f-field text))))
|
|
|
|
(goto-begin-of-line input-i-f-field)
|
|
|
|
(set-input-if-field-edit-lines! input-i-f-field
|
|
|
|
(string->input-if-field-edit-lines input-i-f-field
|
|
|
|
(let ((prompt (input-if-field-prompt input-i-f-field)))
|
|
|
|
(if prompt
|
|
|
|
(string-append prompt
|
|
|
|
text)
|
|
|
|
text))))
|
|
|
|
(goto-end-of-line input-i-f-field)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define input-field-text-wp
|
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(list->string (cat (input-if-field-edit-lines input-i-f-field)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
;(define input-field-edit-pos
|
2006-03-28 04:37:38 -05:00
|
|
|
; (lambda (input-i-f-field)
|
|
|
|
; (values (input-if-field-x-edit-pos input-i-f-field)
|
|
|
|
; (input-if-field-y-edit-pos input-i-f-field))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
;; "basics" - selectors END
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
;; "basics" - clear/reset
|
|
|
|
|
|
|
|
(define input-field-clear
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let* ((prompt (input-if-field-prompt input-i-f-field))
|
|
|
|
(x-pos (if prompt
|
|
|
|
(string-length prompt)
|
|
|
|
0)))
|
|
|
|
(set-input-if-field-x-offset! input-i-f-field 0)
|
|
|
|
(set-input-if-field-y-offset! input-i-f-field 0)
|
|
|
|
(set-input-if-field-x-pos! input-i-f-field x-pos)
|
|
|
|
(set-input-if-field-y-pos! input-i-f-field 0)
|
|
|
|
(set-input-if-field-x-edit-pos! input-i-f-field x-pos)
|
|
|
|
(set-input-if-field-y-edit-pos! input-i-f-field 0)
|
|
|
|
(set-input-if-field-edit-lines! input-i-f-field (if prompt
|
|
|
|
(list (string->list prompt))
|
|
|
|
'(())))
|
|
|
|
(refresh-all input-i-f-field))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define input-field-reset
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let ((x-pos (let ((prompt (input-if-field-prompt input-i-f-field)))
|
|
|
|
(if prompt
|
|
|
|
(string-length prompt)
|
|
|
|
0))))
|
|
|
|
(set-input-if-field-x-offset! input-i-f-field 0)
|
|
|
|
(set-input-if-field-y-offset! input-i-f-field 0)
|
|
|
|
(set-input-if-field-x-pos! input-i-f-field x-pos)
|
|
|
|
(set-input-if-field-y-pos! input-i-f-field 0)
|
|
|
|
(set-input-if-field-x-edit-pos! input-i-f-field x-pos)
|
|
|
|
(set-input-if-field-y-edit-pos! input-i-f-field 0)
|
|
|
|
(set-input-if-field-edit-lines! input-i-f-field
|
|
|
|
(string->input-if-field-edit-lines input-i-f-field
|
|
|
|
(input-if-field-init-text input-i-f-field)))
|
|
|
|
(refresh-all input-i-f-field))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
;; "basics" - clear/reset END
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; "basics" END
|
|
|
|
;;===============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
;;===============================================================================
|
|
|
|
;; draw/refresh functions
|
|
|
|
|
|
|
|
(define paint-black
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let ((x-dim (input-if-field-x-dim input-i-f-field))
|
|
|
|
(y-dim (input-if-field-y-dim input-i-f-field))
|
|
|
|
(x-loc (input-if-field-x-loc input-i-f-field))
|
|
|
|
(y-loc (input-if-field-y-loc input-i-f-field))
|
|
|
|
(win (input-if-field-window input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(let loop ((dy 0)
|
|
|
|
(strings (map list->string
|
|
|
|
(fill-up '()
|
|
|
|
y-dim
|
|
|
|
(fill-up '()
|
|
|
|
x-dim
|
|
|
|
#\space)))))
|
|
|
|
(if (null? strings)
|
|
|
|
#t
|
|
|
|
(begin
|
|
|
|
(mvwaddstr win
|
|
|
|
(+ y-loc dy) x-loc
|
|
|
|
(car strings))
|
|
|
|
(loop (+ dy 1)
|
|
|
|
(cdr strings))))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-03-28 04:37:38 -05:00
|
|
|
;;; TODO (performance):
|
2005-11-11 03:01:07 -05:00
|
|
|
;;; funktionen geben zurück welcher
|
|
|
|
;;; refresh notwendig ist z.b.:
|
|
|
|
;;; 'position
|
|
|
|
;;; 'current-line
|
|
|
|
;;; 'from-current-line ...
|
2006-03-28 04:37:38 -05:00
|
|
|
;;; input-if-field-refresh ruft dann das richtige auf
|
2005-11-11 03:01:07 -05:00
|
|
|
|
2006-03-28 04:37:38 -05:00
|
|
|
(define input-if-field-refresh
|
|
|
|
(lambda (input-i-f-field msg)
|
|
|
|
(cond ((eq? msg 'buffer-full) ;; TODO buffer-full should be signaled
|
|
|
|
(values 'buffer-full #f)) ;; --- had no clou how to catch it ... :-(
|
|
|
|
(msg
|
|
|
|
(refresh-all input-i-f-field))
|
|
|
|
(else (values #t #f)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define refresh-position
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(wmove (input-if-field-window input-i-f-field)
|
|
|
|
(+ (input-if-field-y-loc input-i-f-field)
|
|
|
|
(input-if-field-y-pos input-i-f-field))
|
|
|
|
(+ (input-if-field-x-loc input-i-f-field)
|
|
|
|
(input-if-field-x-pos input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(values #t #t)))
|
|
|
|
|
2006-03-28 04:37:38 -05:00
|
|
|
;(define refresh-from-position ;; TODO
|
|
|
|
; (lambda (input-i-f-field)
|
|
|
|
; #f))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
2006-03-28 04:37:38 -05:00
|
|
|
(define input-field-window-lines
|
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let ((x-loc (input-if-field-x-loc input-i-f-field))
|
|
|
|
(y-loc (input-if-field-y-loc input-i-f-field))
|
|
|
|
(x-dim (input-if-field-x-dim input-i-f-field))
|
|
|
|
(y-dim (input-if-field-y-dim input-i-f-field))
|
|
|
|
(x-offset (input-if-field-x-offset input-i-f-field))
|
|
|
|
(y-offset (input-if-field-y-offset input-i-f-field))
|
|
|
|
(win (input-if-field-window input-i-f-field)))
|
|
|
|
(let* ((input-if-field-lines (map (lambda (input-if-field-line)
|
2005-11-11 03:01:07 -05:00
|
|
|
(util-filter (lambda (char)
|
|
|
|
(not (char=? char #\newline)))
|
2006-03-28 04:37:38 -05:00
|
|
|
input-if-field-line))
|
2005-11-11 03:01:07 -05:00
|
|
|
(cat (map (lambda (edit-line)
|
2006-03-28 04:37:38 -05:00
|
|
|
(edit-line->input-if-field-lines input-i-f-field
|
2005-11-11 03:01:07 -05:00
|
|
|
edit-line))
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-edit-lines input-i-f-field)))))
|
|
|
|
(input-if-field-lines-cut (take (drop (map (lambda (input-if-field-line)
|
|
|
|
(take (drop input-if-field-line
|
2005-11-11 03:01:07 -05:00
|
|
|
x-offset)
|
|
|
|
x-dim))
|
2006-03-28 04:37:38 -05:00
|
|
|
input-if-field-lines)
|
2005-11-11 03:01:07 -05:00
|
|
|
y-offset)
|
2006-03-28 04:37:38 -05:00
|
|
|
y-dim)))
|
|
|
|
input-if-field-lines-cut))))
|
|
|
|
|
|
|
|
(define refresh-all
|
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let ((x-loc (input-if-field-x-loc input-i-f-field))
|
|
|
|
(y-loc (input-if-field-y-loc input-i-f-field))
|
|
|
|
(x-dim (input-if-field-x-dim input-i-f-field))
|
|
|
|
(y-dim (input-if-field-y-dim input-i-f-field))
|
|
|
|
(x-offset (input-if-field-x-offset input-i-f-field))
|
|
|
|
(y-offset (input-if-field-y-offset input-i-f-field))
|
|
|
|
(win (input-if-field-window input-i-f-field)))
|
|
|
|
(let* ((input-if-field-lines-filled (map (lambda (input-if-field-line)
|
|
|
|
(fill-up input-if-field-line
|
2005-11-11 03:01:07 -05:00
|
|
|
x-dim
|
|
|
|
#\space))
|
2006-03-28 04:37:38 -05:00
|
|
|
(fill-up (map (lambda (input-if-field-line)
|
|
|
|
(fill-up input-if-field-line
|
|
|
|
x-dim
|
|
|
|
#\space))
|
|
|
|
(input-field-window-lines input-i-f-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
y-dim
|
|
|
|
'()))))
|
2006-03-28 04:37:38 -05:00
|
|
|
(let loop ((lines input-if-field-lines-filled)
|
2005-11-11 03:01:07 -05:00
|
|
|
(y-ofst 0))
|
|
|
|
(if (null? lines)
|
2006-03-28 04:37:38 -05:00
|
|
|
(refresh-position input-i-f-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)))))))))
|
|
|
|
|
|
|
|
(define refresh-current-line
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f))
|
|
|
|
|
|
|
|
;; draw/refresh functions END
|
|
|
|
;;===============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
;;===============================================================================
|
|
|
|
;; send-input-field
|
|
|
|
|
|
|
|
(define send-input-field
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field msg . args)
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (integer? msg)
|
2006-03-28 04:37:38 -05:00
|
|
|
(cond ((get-behavior input-i-f-field msg) =>
|
2005-11-11 03:01:07 -05:00
|
|
|
(lambda (method)
|
2006-03-28 04:37:38 -05:00
|
|
|
(apply really-send-input-field input-i-f-field method args)))
|
|
|
|
(else (apply really-send-input-field input-i-f-field msg args)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(values #f #f))))
|
|
|
|
|
|
|
|
(define really-send-input-field
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-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-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (insert-char input-i-f-field
|
|
|
|
(if (= msg 13)
|
|
|
|
#\newline
|
|
|
|
(ascii->char msg)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'move-prev-line)
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (move-prev-line input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'move-next-line)
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (move-next-line input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'move-left)
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (move-left input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'move-right)
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (move-right input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'delete-right)
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (delete-right input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'move-forward)
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (move-forward input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'move-backward)
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (move-backward input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'delete-left)
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (delete-left input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'delete-all-right)
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (delete-all-right input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'delete-all-left)
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (delete-all-left input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'delete-line)
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (delete-line input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'goto-begin-of-line)
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (goto-begin-of-line input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'goto-end-of-line)
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (goto-end-of-line input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'goto-begin-of-first-line)
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (goto-begin-of-first-line input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'goto-begin-of-last-line)
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (goto-begin-of-last-line input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'goto-begin-of-word-forward)
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (goto-begin-of-word-forward input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'goto-begin-of-word-backward)
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (goto-begin-of-word-backward input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'goto-end-of-word-forward)
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (goto-begin-of-word-forward input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'goto-end-of-word-backward)
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-refresh input-i-f-field (goto-begin-of-word-backward input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
; ((eq? msg 'input-field-move-up)
|
2006-03-28 04:37:38 -05:00
|
|
|
; (input-if-field-refresh input-i-f-field (input-field-move-up input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
; ((eq? msg 'input-field-move-down)
|
2006-03-28 04:37:38 -05:00
|
|
|
; (input-if-field-refresh input-i-f-field (input-field-move-down input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
; ((eq? msg 'input-field-move-left)
|
2006-03-28 04:37:38 -05:00
|
|
|
; (input-if-field-refresh input-i-f-field (input-field-move-left input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
; ((eq? msg 'input-field-move-right)
|
2006-03-28 04:37:38 -05:00
|
|
|
; (input-if-field-refresh input-i-f-field (input-field-move-right input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'refresh-all)
|
2006-03-28 04:37:38 -05:00
|
|
|
(refresh-all input-i-f-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'toggle-insert)
|
2006-03-28 04:37:38 -05:00
|
|
|
(toggle-insert input-i-f-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
((eq? msg 'restore)
|
2006-03-28 04:37:38 -05:00
|
|
|
(restore-input-field input-i-f-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
((list? msg)
|
|
|
|
(for-each (lambda (msg-single)
|
2006-03-28 04:37:38 -05:00
|
|
|
(send-input-field input-i-f-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-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field msg)
|
|
|
|
(let loop ((behavior (input-if-field-behavior input-i-f-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-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(if (first-line? input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f
|
|
|
|
(begin
|
2006-03-28 04:37:38 -05:00
|
|
|
(set-input-if-field-y-edit-pos! input-i-f-field (- (input-if-field-y-edit-pos input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
1))
|
2006-03-28 04:37:38 -05:00
|
|
|
(prompt-pos-check input-i-f-field)
|
|
|
|
(sync-input-if-field-edit-pos input-i-f-field)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define move-next-line
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(if (last-line? input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f
|
|
|
|
(begin
|
2006-03-28 04:37:38 -05:00
|
|
|
(set-input-if-field-y-edit-pos! input-i-f-field (+ (input-if-field-y-edit-pos input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
1))
|
2006-03-28 04:37:38 -05:00
|
|
|
(sync-input-if-field-edit-pos input-i-f-field)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define move-left
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(if (begin-of-line? input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f
|
|
|
|
(begin
|
2006-03-28 04:37:38 -05:00
|
|
|
(set-input-if-field-x-edit-pos! input-i-f-field (- (input-if-field-x-edit-pos input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
1))
|
2006-03-28 04:37:38 -05:00
|
|
|
(prompt-pos-check input-i-f-field)
|
|
|
|
(sync-input-if-field-edit-pos input-i-f-field)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define move-right
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(if (or (end-of-line? input-i-f-field)
|
|
|
|
(and (right-border? input-i-f-field)
|
|
|
|
(lower-border? input-i-f-field)
|
|
|
|
(not (input-if-field-y-scroll input-i-f-field))
|
|
|
|
(not (input-if-field-x-scroll input-i-f-field))))
|
2005-11-11 03:01:07 -05:00
|
|
|
#f
|
|
|
|
(begin
|
2006-03-28 04:37:38 -05:00
|
|
|
(set-input-if-field-x-edit-pos! input-i-f-field (+ (input-if-field-x-edit-pos input-i-f-field)
|
|
|
|
1))
|
|
|
|
(sync-input-if-field-edit-pos input-i-f-field)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define move-forward
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(if (move-right input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#t
|
2006-03-28 04:37:38 -05:00
|
|
|
(if (move-next-line input-i-f-field)
|
|
|
|
(goto-begin-of-line input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f))))
|
|
|
|
|
|
|
|
(define move-backward
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(if (move-left input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#t
|
2006-03-28 04:37:38 -05:00
|
|
|
(if (move-prev-line input-i-f-field)
|
|
|
|
(goto-end-of-line input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f))))
|
|
|
|
|
2006-03-28 04:37:38 -05:00
|
|
|
(define sync-input-if-field-edit-pos
|
|
|
|
(lambda (input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(call-with-values
|
|
|
|
(lambda ()
|
2006-03-28 04:37:38 -05:00
|
|
|
(edit-pos->input-if-field-pos input-i-f-field
|
|
|
|
(input-if-field-x-edit-pos input-i-f-field)
|
|
|
|
(input-if-field-y-edit-pos input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(lambda (x-pos y-pos)
|
2006-03-28 04:37:38 -05:00
|
|
|
(set-input-if-field-x-pos! input-i-f-field (- x-pos (input-if-field-x-offset input-i-f-field)))
|
|
|
|
(set-input-if-field-y-pos! input-i-f-field (- y-pos (input-if-field-y-offset input-i-f-field)))))
|
|
|
|
(legalize-position input-i-f-field)
|
|
|
|
(if (not (legal-offsets? input-i-f-field))
|
|
|
|
(legalize-offsets input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#t)))
|
|
|
|
|
|
|
|
;; move END
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; scroll
|
|
|
|
|
|
|
|
(define scroll-up
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(set-input-if-field-y-offset! input-i-f-field
|
|
|
|
(- (input-if-field-y-offset input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
1))
|
|
|
|
#t))
|
|
|
|
|
|
|
|
(define scroll-down
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(set-input-if-field-y-offset! input-i-f-field
|
|
|
|
(+ (input-if-field-y-offset input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
1))
|
|
|
|
#t))
|
|
|
|
|
|
|
|
(define scroll-left
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(set-input-if-field-x-offset! input-i-f-field
|
|
|
|
(- (input-if-field-x-offset input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
1))
|
|
|
|
#t))
|
|
|
|
|
|
|
|
(define scroll-right
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(set-input-if-field-x-offset! input-i-f-field
|
|
|
|
(+ (input-if-field-x-offset input-i-f-field)
|
|
|
|
1))
|
|
|
|
#t))
|
2005-11-11 03:01:07 -05:00
|
|
|
;; scroll END
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; insert
|
|
|
|
|
|
|
|
(define insert-char
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field char)
|
|
|
|
(let* ((y-edit-pos (input-if-field-y-edit-pos input-i-f-field))
|
|
|
|
(edit-lines (input-if-field-edit-lines input-i-f-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-03-28 04:37:38 -05:00
|
|
|
(input-if-field-insert-active input-i-f-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
insert
|
|
|
|
replace)
|
|
|
|
current-line
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-x-edit-pos input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
char))))
|
|
|
|
(new-lines (if (and (= (+ y-edit-pos 1)
|
|
|
|
(length edit-lines))
|
2006-03-28 04:37:38 -05:00
|
|
|
(end-of-line? input-i-f-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-03-28 04:37:38 -05:00
|
|
|
(if (or (input-if-field-y-scroll input-i-f-field)
|
|
|
|
(= (length (edit-lines->input-if-field-lines input-i-f-field new-lines))
|
|
|
|
(length (edit-line->input-if-field-lines input-i-f-field current-line)))
|
|
|
|
(<= (length (edit-lines->input-if-field-lines input-i-f-field new-edit-lines))
|
|
|
|
(input-if-field-y-dim input-i-f-field)))
|
|
|
|
(begin (set-input-if-field-edit-lines! input-i-f-field new-edit-lines)
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (char=? char #\newline)
|
2006-03-28 04:37:38 -05:00
|
|
|
(begin (set-input-if-field-x-edit-pos! input-i-f-field 0)
|
|
|
|
(set-input-if-field-y-edit-pos! input-i-f-field (+ (input-if-field-y-edit-pos input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
1))
|
2006-03-28 04:37:38 -05:00
|
|
|
(sync-input-if-field-edit-pos input-i-f-field))
|
|
|
|
(move-right input-i-f-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
#t)
|
2006-03-28 04:37:38 -05:00
|
|
|
'buffer-full))))
|
|
|
|
; (signal 'buffer-full
|
|
|
|
; (input-if-field-x-edit-pos input-i-f-field)
|
|
|
|
; (input-if-field-y-edit-pos input-i-f-field))))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
;; insert END
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; delete
|
|
|
|
|
|
|
|
(define delete-right
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let* ((x-edit-pos (input-if-field-x-edit-pos input-i-f-field))
|
|
|
|
(y-edit-pos (input-if-field-y-edit-pos input-i-f-field))
|
|
|
|
(edit-lines (input-if-field-edit-lines input-i-f-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-03-28 04:37:38 -05:00
|
|
|
(set-input-if-field-edit-lines! input-i-f-field (replace edit-lines
|
2005-11-11 03:01:07 -05:00
|
|
|
y-edit-pos
|
|
|
|
new-line))
|
|
|
|
#t)
|
|
|
|
#f))))
|
|
|
|
|
|
|
|
(define delete-left
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(if (move-left input-i-f-field)
|
|
|
|
(delete-right input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f)))
|
|
|
|
|
|
|
|
(define delete-all-left
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let* ((x-edit-pos (input-if-field-x-edit-pos input-i-f-field))
|
|
|
|
(y-edit-pos (input-if-field-y-edit-pos input-i-f-field))
|
|
|
|
(edit-lines (input-if-field-edit-lines input-i-f-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-03-28 04:37:38 -05:00
|
|
|
(set-input-if-field-edit-lines! input-i-f-field (replace edit-lines
|
2005-11-11 03:01:07 -05:00
|
|
|
y-edit-pos
|
|
|
|
(drop current-line
|
|
|
|
x-edit-pos)))
|
2006-03-28 04:37:38 -05:00
|
|
|
(set-input-if-field-x-edit-pos! input-i-f-field 0)
|
|
|
|
(sync-input-if-field-edit-pos input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#t)
|
|
|
|
#f))))
|
|
|
|
|
|
|
|
(define delete-all-right
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let* ((x-edit-pos (input-if-field-x-edit-pos input-i-f-field))
|
|
|
|
(y-edit-pos (input-if-field-y-edit-pos input-i-f-field))
|
|
|
|
(edit-lines (input-if-field-edit-lines input-i-f-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
(current-line (list-ref edit-lines
|
|
|
|
y-edit-pos)))
|
2006-03-28 04:37:38 -05:00
|
|
|
(if (and (end-of-line? input-i-f-field)
|
|
|
|
(not (last-line? input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(begin
|
2006-03-28 04:37:38 -05:00
|
|
|
(set-input-if-field-edit-lines! input-i-f-field
|
2005-11-11 03:01:07 -05:00
|
|
|
(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))))
|
|
|
|
#t)
|
|
|
|
(begin
|
2006-03-28 04:37:38 -05:00
|
|
|
(set-input-if-field-edit-lines! input-i-f-field
|
2005-11-11 03:01:07 -05:00
|
|
|
(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))))
|
|
|
|
#t)))))
|
|
|
|
|
|
|
|
(define delete-line
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let* ((x-edit-pos (input-if-field-x-edit-pos input-i-f-field))
|
|
|
|
(y-edit-pos (input-if-field-y-edit-pos input-i-f-field))
|
|
|
|
(edit-lines (input-if-field-edit-lines input-i-f-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-03-28 04:37:38 -05:00
|
|
|
(set-input-if-field-edit-lines! input-i-f-field '(()))
|
|
|
|
(set-input-if-field-x-edit-pos! input-i-f-field 0)
|
|
|
|
(sync-input-if-field-edit-pos input-i-f-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
(begin
|
2006-03-28 04:37:38 -05:00
|
|
|
(set-input-if-field-edit-lines! input-i-f-field (remove edit-lines
|
2005-11-11 03:01:07 -05:00
|
|
|
y-edit-pos))
|
2006-03-28 04:37:38 -05:00
|
|
|
(set-input-if-field-x-edit-pos! input-i-f-field 0)
|
|
|
|
(set-input-if-field-y-edit-pos! input-i-f-field (min y-edit-pos
|
2005-11-11 03:01:07 -05:00
|
|
|
(- edit-lines-len 2)))
|
2006-03-28 04:37:38 -05:00
|
|
|
(sync-input-if-field-edit-pos input-i-f-field))))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
;; delete END
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; goto
|
|
|
|
|
|
|
|
;; TODOO - fertig machen... (siehe #f)
|
|
|
|
|
|
|
|
(define goto-begin-of-word-forward
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(goto-next-forward input-i-f-field #\space #\newline)
|
|
|
|
(goto-next-not-forward input-i-f-field #\space #\newline)
|
2005-11-11 03:01:07 -05:00
|
|
|
#t))
|
|
|
|
|
|
|
|
|
|
|
|
(define goto-end-of-word-forward
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f))
|
|
|
|
|
|
|
|
|
|
|
|
(define goto-begin-of-word-backward
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(if (and (goto-next-not-backward input-i-f-field #\space #\newline)
|
|
|
|
(goto-next-backward input-i-f-field #\space #\newline))
|
|
|
|
(move-forward input-i-f-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
#t))
|
|
|
|
|
|
|
|
(define goto-end-of-word-backward
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f))
|
|
|
|
|
|
|
|
(define goto-begin-of-line
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(set-input-if-field-x-edit-pos! input-i-f-field 0)
|
|
|
|
(prompt-pos-check input-i-f-field)
|
|
|
|
(sync-input-if-field-edit-pos input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define goto-end-of-line
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let ((x-edit-pos (input-if-field-x-edit-pos input-i-f-field))
|
|
|
|
(y-edit-pos (input-if-field-y-edit-pos input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(call-with-values
|
|
|
|
(lambda ()
|
2006-03-28 04:37:38 -05:00
|
|
|
(let* ((current-line (list-ref (input-if-field-edit-lines input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
y-edit-pos)))
|
|
|
|
(if (null? current-line)
|
2006-03-28 04:37:38 -05:00
|
|
|
(set-input-if-field-x-edit-pos! input-i-f-field 0)
|
2005-11-11 03:01:07 -05:00
|
|
|
(let ((len (length current-line))
|
|
|
|
(end-char (last current-line)))
|
2006-03-28 04:37:38 -05:00
|
|
|
(set-input-if-field-x-edit-pos! input-i-f-field (if (char=? end-char #\newline)
|
2005-11-11 03:01:07 -05:00
|
|
|
(- len 1)
|
|
|
|
len))))
|
2006-03-28 04:37:38 -05:00
|
|
|
(edit-pos->input-if-field-pos input-i-f-field
|
|
|
|
(input-if-field-x-edit-pos input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
y-edit-pos)))
|
|
|
|
(lambda (x-pos y-pos)
|
2006-03-28 04:37:38 -05:00
|
|
|
(set-input-if-field-x-pos! input-i-f-field (- x-pos (input-if-field-x-offset input-i-f-field)))
|
|
|
|
(set-input-if-field-y-pos! input-i-f-field (- y-pos (input-if-field-y-offset input-i-f-field)))
|
|
|
|
(sync-input-if-field-edit-pos input-i-f-field))))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define goto-begin-of-first-line
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(set-input-if-field-x-edit-pos! input-i-f-field 0)
|
|
|
|
(set-input-if-field-y-edit-pos! input-i-f-field 0)
|
|
|
|
(prompt-pos-check input-i-f-field)
|
|
|
|
(sync-input-if-field-edit-pos input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define goto-end-of-first-line
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f))
|
|
|
|
|
|
|
|
(define goto-begin-of-last-line
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(set-input-if-field-x-edit-pos! input-i-f-field 0)
|
|
|
|
(set-input-if-field-y-edit-pos! input-i-f-field (- (length (input-if-field-edit-lines input-i-f-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
1))
|
2006-03-28 04:37:38 -05:00
|
|
|
(prompt-pos-check input-i-f-field)
|
|
|
|
(sync-input-if-field-edit-pos input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define goto-end-of-last-line
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f))
|
|
|
|
|
|
|
|
;; ------------------------------------------------------------------
|
|
|
|
; wozu eigentlich?
|
2006-03-28 04:37:38 -05:00
|
|
|
;(define goto-end-of-input-if-field-line
|
|
|
|
; (lambda (input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
; #f))
|
|
|
|
|
|
|
|
;; ------------------------------------------------------------------
|
|
|
|
|
|
|
|
(define goto-next-forward
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field . chars)
|
|
|
|
(if (move-forward input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(let loop ()
|
2006-03-28 04:37:38 -05:00
|
|
|
(let ((sign (sign-under-cursor input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (and sign
|
|
|
|
(memq sign chars))
|
|
|
|
#t
|
2006-03-28 04:37:38 -05:00
|
|
|
(if (move-forward input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(loop)
|
|
|
|
#f))))
|
|
|
|
#f)))
|
|
|
|
|
|
|
|
(define goto-next-not-forward
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field . chars)
|
|
|
|
(if (move-forward input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(let loop ()
|
2006-03-28 04:37:38 -05:00
|
|
|
(let ((sign (sign-under-cursor input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (and sign
|
|
|
|
(not (memq sign chars)))
|
|
|
|
#t
|
2006-03-28 04:37:38 -05:00
|
|
|
(if (move-forward input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(loop)
|
|
|
|
#f))))
|
|
|
|
#f)))
|
|
|
|
|
|
|
|
(define goto-next-backward
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field . chars)
|
|
|
|
(if (move-backward input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(let loop ()
|
2006-03-28 04:37:38 -05:00
|
|
|
(let ((sign (sign-under-cursor input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (and sign
|
|
|
|
(memq sign chars))
|
2006-03-28 04:37:38 -05:00
|
|
|
(begin
|
|
|
|
(prompt-pos-check input-i-f-field)
|
|
|
|
#t)
|
|
|
|
(if (move-backward input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(loop)
|
2006-03-28 04:37:38 -05:00
|
|
|
(begin
|
|
|
|
(prompt-pos-check input-i-f-field)
|
|
|
|
#f)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
#f)))
|
|
|
|
|
|
|
|
(define goto-next-not-backward
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field . chars)
|
|
|
|
(if (move-backward input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(let loop ()
|
2006-03-28 04:37:38 -05:00
|
|
|
(let ((sign (sign-under-cursor input-i-f-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
|
|
|
|
(prompt-pos-check input-i-f-field)
|
|
|
|
#t)
|
|
|
|
(if (move-backward input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(loop)
|
2006-03-28 04:37:38 -05:00
|
|
|
(begin
|
|
|
|
(prompt-pos-check input-i-f-field)
|
|
|
|
#f)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
#f)))
|
|
|
|
|
|
|
|
;; goto END
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; others
|
|
|
|
(define toggle-insert
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(set-input-if-field-insert-active! input-i-f-field
|
|
|
|
(not (input-if-field-insert-active input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(values #t #f)))
|
|
|
|
;; others END
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; behavior methods END
|
|
|
|
;;===============================================================================
|
|
|
|
|
|
|
|
;;===============================================================================
|
|
|
|
;; "mutate" functions and few others
|
|
|
|
|
|
|
|
(define input-field-refresh
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(really-send-input-field input-i-f-field 'refresh-all)))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
;(define input-field-move-up
|
2006-03-28 04:37:38 -05:00
|
|
|
; (lambda (input-i-f-field)
|
|
|
|
; (let ((y-loc (input-if-field-y-loc input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
; (if (> y-loc 1)
|
|
|
|
; (begin
|
2006-03-28 04:37:38 -05:00
|
|
|
; (paint-black input-i-f-field)
|
|
|
|
; (set-input-if-field-y-loc! input-i-f-field (- y-loc
|
2005-11-11 03:01:07 -05:00
|
|
|
; 1))
|
|
|
|
; #t)
|
|
|
|
; #f))))
|
|
|
|
|
|
|
|
;(define input-field-move-down
|
2006-03-28 04:37:38 -05:00
|
|
|
; (lambda (input-i-f-field)
|
|
|
|
; (let ((y-loc (input-if-field-y-loc input-i-f-field)))
|
|
|
|
; (if (< (+ y-loc (input-if-field-y-dim input-i-f-field))
|
|
|
|
; (- (getmaxy (input-if-field-window input-i-f-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
; 1))
|
|
|
|
; (begin
|
2006-03-28 04:37:38 -05:00
|
|
|
; (paint-black input-i-f-field)
|
|
|
|
; (set-input-if-field-y-loc! input-i-f-field (+ y-loc
|
2005-11-11 03:01:07 -05:00
|
|
|
; 1))
|
|
|
|
; #t)
|
|
|
|
; #f))))
|
|
|
|
|
|
|
|
;(define input-field-move-left
|
2006-03-28 04:37:38 -05:00
|
|
|
; (lambda (input-i-f-field)
|
|
|
|
; (let ((x-loc (input-if-field-x-loc input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
; (if (> x-loc 1)
|
|
|
|
; (begin
|
2006-03-28 04:37:38 -05:00
|
|
|
; (paint-black input-i-f-field)
|
|
|
|
; (set-input-if-field-x-loc! input-i-f-field (- x-loc
|
2005-11-11 03:01:07 -05:00
|
|
|
; 1))
|
|
|
|
; #t)
|
|
|
|
; #f))))
|
|
|
|
|
|
|
|
;(define input-field-move-right
|
2006-03-28 04:37:38 -05:00
|
|
|
; (lambda (input-i-f-field)
|
|
|
|
; (let ((x-loc (input-if-field-x-loc input-i-f-field)))
|
|
|
|
; (if (< (+ x-loc (input-if-field-x-dim input-i-f-field))
|
|
|
|
; (- (getmaxx (input-if-field-window input-i-f-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
; 1))
|
|
|
|
; (begin
|
2006-03-28 04:37:38 -05:00
|
|
|
; (paint-black input-i-f-field)
|
|
|
|
; (set-input-if-field-x-loc! input-i-f-field (+ x-loc
|
2005-11-11 03:01:07 -05:00
|
|
|
; 1))
|
|
|
|
; #t)
|
|
|
|
; #f))))
|
|
|
|
|
|
|
|
(define input-field-move
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field x y)
|
|
|
|
(let ((win (input-if-field-window input-i-f-field)))
|
|
|
|
;(report win " move!")
|
|
|
|
(if (and (>= x 0)
|
|
|
|
(>= y 0)
|
|
|
|
(<= (+ x (input-if-field-x-dim input-i-f-field)); (input-if-field-x-loc input-i-f-field)) ;; + x-loc
|
|
|
|
(getmaxx win))
|
|
|
|
(<= (+ y (input-if-field-y-dim input-i-f-field)); (input-if-field-y-loc input-i-f-field)) ;; + y-loc
|
|
|
|
(getmaxy win)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(begin
|
2006-03-28 04:37:38 -05:00
|
|
|
;(report win "move yes!")
|
|
|
|
(paint-black input-i-f-field)
|
|
|
|
(set-input-if-field-x-loc! input-i-f-field x)
|
|
|
|
(set-input-if-field-y-loc! input-i-f-field y)
|
|
|
|
(refresh-all input-i-f-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
#f))))
|
|
|
|
|
|
|
|
(define input-field-resize
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field x y)
|
|
|
|
(let ((win (input-if-field-window input-i-f-field)))
|
|
|
|
;(report win "resize!")
|
|
|
|
(if (and (>= x 0)
|
|
|
|
(>= y 0)
|
|
|
|
(<= (+ x (input-if-field-x-loc input-i-f-field)); (input-if-field-x-dim input-i-f-field)) ;; + x-dim
|
|
|
|
(getmaxx win))
|
|
|
|
(<= (+ y (input-if-field-y-loc input-i-f-field)); (input-if-field-y-dim input-i-f-field)) ;; + y-dim
|
|
|
|
(getmaxy win)))
|
|
|
|
(let* ((prompt (input-if-field-prompt input-i-f-field))
|
|
|
|
(x-pos (if prompt
|
|
|
|
(string-length prompt)
|
|
|
|
0)))
|
|
|
|
;(report win "resize!")
|
|
|
|
(paint-black input-i-f-field)
|
|
|
|
; (set-input-if-field-x-offset! input-i-f-field 0)
|
|
|
|
; (set-input-if-field-y-offset! input-i-f-field 0)
|
|
|
|
; (set-input-if-field-x-pos! input-i-f-field x-pos)
|
|
|
|
; (set-input-if-field-y-pos! input-i-f-field 0)
|
|
|
|
; (set-input-if-field-x-edit-pos! input-i-f-field x-pos)
|
|
|
|
; (set-input-if-field-y-edit-pos! input-i-f-field 0)
|
|
|
|
(set-input-if-field-x-dim! input-i-f-field x)
|
|
|
|
(set-input-if-field-y-dim! input-i-f-field y)
|
|
|
|
(set-input-if-field-edit-lines! input-i-f-field
|
|
|
|
(string->input-if-field-edit-lines input-i-f-field
|
|
|
|
(input-field-text-wp input-i-f-field)))
|
|
|
|
(sync-input-if-field-edit-pos input-i-f-field)
|
|
|
|
(legalize-position input-i-f-field)
|
|
|
|
(if (not (legal-offsets? input-i-f-field))
|
|
|
|
(legalize-offsets input-i-f-field))
|
|
|
|
(refresh-all input-i-f-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
#f))))
|
|
|
|
|
|
|
|
(define input-field-toggle-x-scroll
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let* ((prompt (input-if-field-prompt input-i-f-field))
|
|
|
|
(x-pos (if prompt
|
|
|
|
(string-length prompt)
|
|
|
|
0)))
|
|
|
|
(paint-black input-i-f-field)
|
|
|
|
; (set-input-if-field-x-offset! input-i-f-field 0)
|
|
|
|
; (set-input-if-field-y-offset! input-i-f-field 0)
|
|
|
|
; (set-input-if-field-x-pos! input-i-f-field x-pos)
|
|
|
|
; (set-input-if-field-y-pos! input-i-f-field 0)
|
|
|
|
; (set-input-if-field-x-edit-pos! input-i-f-field x-pos)
|
|
|
|
; (set-input-if-field-y-edit-pos! input-i-f-field 0)
|
|
|
|
(set-input-if-field-x-scroll! input-i-f-field (not (input-if-field-x-scroll input-i-f-field)))
|
|
|
|
(set-input-if-field-edit-lines! input-i-f-field
|
|
|
|
(string->input-if-field-edit-lines input-i-f-field
|
|
|
|
(input-field-text-wp input-i-f-field)))
|
|
|
|
(sync-input-if-field-edit-pos input-i-f-field)
|
|
|
|
(legalize-position input-i-f-field)
|
|
|
|
(if (not (legal-offsets? input-i-f-field))
|
|
|
|
(legalize-offsets input-i-f-field))
|
|
|
|
(refresh-all input-i-f-field))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define input-field-toggle-y-scroll
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let* ((prompt (input-if-field-prompt input-i-f-field))
|
|
|
|
(x-pos (if prompt
|
|
|
|
(string-length prompt)
|
|
|
|
0)))
|
|
|
|
(paint-black input-i-f-field)
|
|
|
|
;(set-input-if-field-x-offset! input-i-f-field 0)
|
|
|
|
;(set-input-if-field-y-offset! input-i-f-field 0)
|
|
|
|
;(set-input-if-field-x-pos! input-i-f-field x-pos)
|
|
|
|
;(set-input-if-field-y-pos! input-i-f-field 0)
|
|
|
|
;(set-input-if-field-x-edit-pos! input-i-f-field x-pos)
|
|
|
|
;(set-input-if-field-y-edit-pos! input-i-f-field 0)
|
|
|
|
(set-input-if-field-y-scroll! input-i-f-field (not (input-if-field-y-scroll input-i-f-field)))
|
|
|
|
(set-input-if-field-edit-lines! input-i-f-field
|
|
|
|
(string->input-if-field-edit-lines input-i-f-field
|
|
|
|
(input-field-text-wp input-i-f-field)))
|
|
|
|
(sync-input-if-field-edit-pos input-i-f-field)
|
|
|
|
(legalize-position input-i-f-field)
|
|
|
|
(if (not (legal-offsets? input-i-f-field))
|
|
|
|
(legalize-offsets input-i-f-field))
|
|
|
|
(refresh-all input-i-f-field))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define restore-input-field
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(set-input-if-field-edit-lines! input-i-f-field
|
|
|
|
(string->input-if-field-edit-lines input-i-f-field
|
|
|
|
(input-field-text-wp input-i-f-field)))
|
|
|
|
(sync-input-if-field-edit-pos input-i-f-field)
|
|
|
|
(refresh-all input-i-f-field)))
|
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-03-28 04:37:38 -05:00
|
|
|
(define edit-line->input-if-field-lines
|
|
|
|
(lambda (input-i-f-field edit-line)
|
|
|
|
(let ((x-dim (input-if-field-x-dim input-i-f-field))
|
|
|
|
(x-scroll (input-if-field-x-scroll input-i-f-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-03-28 04:37:38 -05:00
|
|
|
(split-input-if-field-line-from-edit-line x-dim edit-line))
|
|
|
|
(lambda (input-if-field-line edit-line)
|
|
|
|
(cons input-if-field-line
|
2005-11-11 03:01:07 -05:00
|
|
|
(loop edit-line))))))))))
|
|
|
|
|
2006-03-28 04:37:38 -05:00
|
|
|
(define edit-lines->input-if-field-lines
|
|
|
|
(lambda (input-i-f-field edit-lines)
|
2005-11-11 03:01:07 -05:00
|
|
|
(cat (map (lambda (edit-line)
|
2006-03-28 04:37:38 -05:00
|
|
|
(edit-line->input-if-field-lines input-i-f-field edit-line))
|
2005-11-11 03:01:07 -05:00
|
|
|
edit-lines))))
|
|
|
|
|
2006-03-28 04:37:38 -05:00
|
|
|
(define split-input-if-field-line-from-edit-line
|
2005-11-11 03:01:07 -05:00
|
|
|
(lambda (x-dim edit-line)
|
2006-03-28 04:37:38 -05:00
|
|
|
(let loop ((input-if-field-line '())
|
2005-11-11 03:01:07 -05:00
|
|
|
(rest edit-line)
|
|
|
|
(space-left x-dim))
|
|
|
|
(if (null? rest)
|
2006-03-28 04:37:38 -05:00
|
|
|
(values (reverse input-if-field-line)
|
2005-11-11 03:01:07 -05:00
|
|
|
rest)
|
|
|
|
(let ((char (car rest)))
|
|
|
|
(cond ((char=? char #\newline)
|
|
|
|
(values (reverse (cons char
|
2006-03-28 04:37:38 -05:00
|
|
|
input-if-field-line))
|
2005-11-11 03:01:07 -05:00
|
|
|
(cdr rest)))
|
|
|
|
((zero? space-left)
|
2006-03-28 04:37:38 -05:00
|
|
|
(values (reverse input-if-field-line)
|
2005-11-11 03:01:07 -05:00
|
|
|
rest))
|
|
|
|
(else
|
2006-03-28 04:37:38 -05:00
|
|
|
(loop (cons char input-if-field-line)
|
2005-11-11 03:01:07 -05:00
|
|
|
(cdr rest)
|
|
|
|
(- space-left 1)))))))))
|
|
|
|
|
2006-03-28 04:37:38 -05:00
|
|
|
(define input-if-field-lines->edit-lines
|
|
|
|
(lambda (input-if-field-lines)
|
|
|
|
(let loop ((rest input-if-field-lines))
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (null? rest)
|
|
|
|
'()
|
|
|
|
(call-with-values
|
|
|
|
(lambda ()
|
2006-03-28 04:37:38 -05:00
|
|
|
(split-edit-line-from-input-if-field-lines rest))
|
2005-11-11 03:01:07 -05:00
|
|
|
(lambda (edit-line rest)
|
|
|
|
(cons edit-line
|
|
|
|
(loop rest))))))))
|
|
|
|
|
2006-03-28 04:37:38 -05:00
|
|
|
(define split-edit-line-from-input-if-field-lines
|
|
|
|
(lambda (input-if-field-lines)
|
2005-11-11 03:01:07 -05:00
|
|
|
(let loop ((edit-line '())
|
2006-03-28 04:37:38 -05:00
|
|
|
(rest input-if-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-03-28 04:37:38 -05:00
|
|
|
(define string->input-if-field-edit-lines
|
|
|
|
(lambda (input-i-f-field string)
|
2005-11-11 03:01:07 -05:00
|
|
|
(let* ((edit-lines (string->edit-lines-with-null string))
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-lines (edit-lines->input-if-field-lines input-i-f-field edit-lines))
|
|
|
|
(input-if-field-lines-cut (if (input-if-field-y-scroll input-i-f-field)
|
|
|
|
input-if-field-lines
|
|
|
|
(take input-if-field-lines
|
|
|
|
(input-if-field-y-dim input-i-f-field)))))
|
|
|
|
(input-if-field-lines->edit-lines input-if-field-lines-cut))))
|
|
|
|
|
|
|
|
(define input-if-field->edit-pos
|
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let ((x-pos (+ (input-if-field-x-offset input-i-f-field)
|
|
|
|
(input-if-field-x-pos input-i-f-field)))
|
|
|
|
(y-pos (+ (input-if-field-y-offset input-i-f-field)
|
|
|
|
(input-if-field-y-pos input-i-f-field)))
|
|
|
|
(x-scroll (input-if-field-x-scroll input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(if x-scroll
|
|
|
|
(values x-pos y-pos)
|
2006-03-28 04:37:38 -05:00
|
|
|
(let loop ((edit-lines (input-if-field-edit-lines input-i-f-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-03-28 04:37:38 -05:00
|
|
|
(values (length (list-ref (input-if-field-edit-lines input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
y-edit-pos))
|
|
|
|
y-edit-pos))
|
|
|
|
(let* ((edit-line (car edit-lines))
|
2006-03-28 04:37:38 -05:00
|
|
|
(num-input-if-field-lines (length
|
|
|
|
(edit-line->input-if-field-lines input-i-f-field edit-line))))
|
|
|
|
(if (< y-pos num-input-if-field-lines)
|
2005-11-11 03:01:07 -05:00
|
|
|
(values (+ (* y-pos
|
2006-03-28 04:37:38 -05:00
|
|
|
(input-if-field-x-dim input-i-f-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
x-pos)
|
|
|
|
y-edit-pos)
|
|
|
|
(loop (cdr edit-lines)
|
|
|
|
(+ y-edit-pos 1)
|
2006-03-28 04:37:38 -05:00
|
|
|
(- y-pos num-input-if-field-lines))))))))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
2006-03-28 04:37:38 -05:00
|
|
|
(define edit-pos->input-if-field-pos
|
|
|
|
(lambda (input-i-f-field x-edit-pos y-edit-pos)
|
|
|
|
(if (input-if-field-x-scroll input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
(values x-edit-pos y-edit-pos)
|
2006-03-28 04:37:38 -05:00
|
|
|
(let loop ((edit-lines (input-if-field-edit-lines input-i-f-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
(y-edit-pos y-edit-pos)
|
|
|
|
(y-pos 0))
|
|
|
|
(if (null? edit-lines)
|
2006-03-28 04:37:38 -05:00
|
|
|
'error--edit-pos->input-if-field-pos
|
2005-11-11 03:01:07 -05:00
|
|
|
(if (zero? y-edit-pos)
|
2006-03-28 04:37:38 -05:00
|
|
|
(let ((x-dim (input-if-field-x-dim input-i-f-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-03-28 04:37:38 -05:00
|
|
|
(edit-line->input-if-field-lines input-i-f-field
|
2005-11-11 03:01:07 -05:00
|
|
|
(car edit-lines)))))))))))
|
|
|
|
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; legalize-position
|
|
|
|
(define legalize-position
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let* ((x-edit-pos (input-if-field-x-edit-pos input-i-f-field))
|
|
|
|
(y-edit-pos (input-if-field-y-edit-pos input-i-f-field))
|
|
|
|
(current-line (list-ref (input-if-field-edit-lines input-i-f-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-03-28 04:37:38 -05:00
|
|
|
(goto-end-of-line input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
#t))
|
|
|
|
|
2006-03-28 04:37:38 -05:00
|
|
|
(define prompt-pos-check
|
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(if (zero? (input-if-field-y-edit-pos input-i-f-field))
|
|
|
|
(let ((prompt (input-if-field-prompt input-i-f-field)))
|
|
|
|
(if prompt
|
|
|
|
(let ((prompt-length (string-length prompt)))
|
|
|
|
(if (< (input-if-field-x-edit-pos input-i-f-field)
|
|
|
|
prompt-length)
|
|
|
|
(set-input-if-field-x-edit-pos! input-i-f-field prompt-length))))))))
|
|
|
|
|
2005-11-11 03:01:07 -05:00
|
|
|
(define legal-offsets?
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let ((x (input-if-field-x-pos input-i-f-field))
|
|
|
|
(y (input-if-field-y-pos input-i-f-field)))
|
2005-11-11 03:01:07 -05:00
|
|
|
(and (>= x 0)
|
2006-03-28 04:37:38 -05:00
|
|
|
(< x (input-if-field-x-dim input-i-f-field))
|
2005-11-11 03:01:07 -05:00
|
|
|
(>= y 0)
|
2006-03-28 04:37:38 -05:00
|
|
|
(< y (input-if-field-y-dim input-i-f-field))))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
|
|
|
|
(define legalize-offsets
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let ((x-pos (input-if-field-x-pos input-i-f-field))
|
|
|
|
(x-offset (input-if-field-x-offset input-i-f-field))
|
|
|
|
(x-dim (input-if-field-x-dim input-i-f-field))
|
|
|
|
(y-pos (input-if-field-y-pos input-i-f-field))
|
|
|
|
(y-offset (input-if-field-y-offset input-i-f-field))
|
|
|
|
(y-dim (input-if-field-y-dim input-i-f-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-03-28 04:37:38 -05:00
|
|
|
(set-input-if-field-x-pos! input-i-f-field x-pos)
|
|
|
|
(set-input-if-field-x-offset! input-i-f-field x-offset)
|
|
|
|
(set-input-if-field-y-pos! input-i-f-field y-pos)
|
|
|
|
(set-input-if-field-y-offset! input-i-f-field y-offset)
|
2005-11-11 03:01:07 -05:00
|
|
|
#t)))
|
|
|
|
;; legalize-position END
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; predicates
|
|
|
|
|
|
|
|
(define first-line?
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(zero? (input-if-field-y-edit-pos input-i-f-field))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define last-line?
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(= (+ (input-if-field-y-edit-pos input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
1)
|
2006-03-28 04:37:38 -05:00
|
|
|
(length (input-if-field-edit-lines input-i-f-field)))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define begin-of-line?
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(zero? (input-if-field-x-edit-pos input-i-f-field))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define end-of-line?
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let* ((x-edit-pos (input-if-field-x-edit-pos input-i-f-field))
|
|
|
|
(y-edit-pos (input-if-field-y-edit-pos input-i-f-field))
|
|
|
|
(edit-line (list-ref (input-if-field-edit-lines input-i-f-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)))))
|
|
|
|
|
|
|
|
(define left-border?
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(= (input-if-field-x-pos input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
0)))
|
|
|
|
|
|
|
|
(define right-border?
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(= (input-if-field-x-pos input-i-f-field)
|
|
|
|
(- (input-if-field-x-dim input-i-f-field) 1))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define lower-border?
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(= (input-if-field-y-pos input-i-f-field)
|
|
|
|
(- (input-if-field-y-dim input-i-f-field) 1))))
|
2005-11-11 03:01:07 -05:00
|
|
|
|
|
|
|
(define upper-border?
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(= (input-if-field-y-pos input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
0)))
|
|
|
|
;; predicates END
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; selectors
|
|
|
|
(define sign-at-xy
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field x y)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f))
|
|
|
|
|
|
|
|
(define sign-under-cursor
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
|
|
|
(let* ((x-edit-pos (input-if-field-x-edit-pos input-i-f-field))
|
|
|
|
(y-edit-pos (input-if-field-y-edit-pos input-i-f-field))
|
|
|
|
(current-line (list-ref (input-if-field-edit-lines input-i-f-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))))
|
|
|
|
|
|
|
|
(define sign-before-cursor
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f))
|
|
|
|
|
|
|
|
(define sign-behind-cursor
|
2006-03-28 04:37:38 -05:00
|
|
|
(lambda (input-i-f-field)
|
2005-11-11 03:01:07 -05:00
|
|
|
#f))
|
|
|
|
|
|
|
|
;; selectors END
|
|
|
|
;; ----------------------------------------------------------------------------
|
|
|
|
;; helpfunctions END
|
|
|
|
;;===============================================================================
|
|
|
|
|
|
|
|
;;===============================================================================
|
|
|
|
;; "primitives"
|
|
|
|
|
|
|
|
(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)
|
|
|
|
'error--fill-up
|
|
|
|
(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)))))
|
|
|
|
|
|
|
|
(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)))))
|
|
|
|
|
|
|
|
|
|
|
|
;; "primitives" END
|
|
|
|
;;===============================================================================
|
2006-03-28 04:37:38 -05:00
|
|
|
|
|
|
|
;;======================================================================
|
|
|
|
;; debug-stuff
|
|
|
|
(define report
|
|
|
|
(lambda (win str)
|
|
|
|
(let ((win (init-screen))
|
|
|
|
(x (getx win));
|
|
|
|
(y (gety win)))
|
|
|
|
(mvwaddstr win 0 0 str)
|
|
|
|
(wmove win y x)
|
|
|
|
(wrefresh win))))
|
|
|
|
|