(define (interact p)
(let ((child (car p))
(in (cadr p))
(out (caddr p)))
(run (stty raw -echo))
(& (begin (exec-epf (cat) (= 1 ,out))))
(exec-epf (cat) (= 0 ,in))))
(define-syntax bg
(syntax-rules ()
((_ cmd)
(call-with-values
(lambda () (fork-pty-session (lambda () (exec-epf cmd))))
list))))
(define-syntax expect
(syntax-rules ()
((_ cmd proc)
(let* ((p (bg cmd))
(in (cadr p)))
(let l ((b ""))
(l (string-append (proc p b) (string (read-char in)))))))))
(define (handled m b r)
(let ((e (+ m (string-length r))))
(display (substring b 0 e))
(substring b e (string-length b))))
(define-syntax expect-cond
(syntax-rules (=>)
((_ b (r => a ...) c ...)
(let ((m (string-contains b r)))
(if m
(begin a ... (handled m b r))
(expect-cond b c ...))))
((_ b) b)))
(expect
(.. cmd ..)
(lambda (p b)
(let ((po (caddr p)))
(expect-cond
b
("assword: " => (display "pwpw\n" po))))))