From c75fe78598c2a2e8a044fba29b07db5f99f4f468 Mon Sep 17 00:00:00 2001
From: Mario Domenech Goulart <mario@parenteses.org>
Date: Wed, 4 Nov 2020 22:03:23 +0100
Subject: [PATCH 2/2] Adapt Kooda's change on top of mine

This is the meat of
https://www.upyum.com/cgit.cgi/forks/parley/commit/?id=66f30dd9f227e5a253f5149de269c875db69a0c0

Seems to work for both C4 and C5 (very quickly tested).
---
 parley.scm | 73 +++++++++++++++++++++++++++-----------------------------------
 1 file changed, 32 insertions(+), 41 deletions(-)

diff --git a/parley.scm b/parley.scm
index 53d0d3e..7f6482b 100644
--- a/parley.scm
+++ b/parley.scm
@@ -717,47 +717,38 @@
                      (##sys#user-interrupt-hook)))
       (set-signal-handler! signal/int handle)
 
-      (let* ((class
-              (vector
-               (lambda (p)              ; read-char
-                 (parameterize ((history (##sys#slot p 11)))
-                               (let ([last (##sys#slot p 10)])
-                                 (cond [last
-                                        (##sys#setislot p 10 #f)
-                                        last]
-                                       [else (get-next-char!)] ) )) )
-               (lambda (p)              ; peek-char
-                 (parameterize ((history (##sys#slot p 11)))
-                               (let ([last (##sys#slot p 10)])
-                                 (if last
-                                     last
-                                     (let ([last (get-next-char!)])
-                                       (##sys#setslot p 10 last)
-                                       last)  ) )))
-               #f                       ; write-char
-               #f                       ; write-string
-               (lambda (p)              ; close
-                                        ; reset handler to the user one if it exists
-                 (set-signal-handler! signal/int (##sys#user-interrupt-hook))
-                 (unless (##sys#slot p 8) (flush-history p))
-                 (##sys#setislot p 8 #t))
-               #f                       ; flush-output
-               (lambda (p)              ; char-ready?
-                 (parley-char-ready?) )
-               #f                       ; read-string!
-               #f                       ; read-line
-               #f))                     ; read-buffered
-             (data (vector #f))
-             (port (##sys#make-port #t class "(parley)" 'custom)) )
-        (##sys#set-port-data! port data)
-        (parameterize
-         ((history #f))
-         (if (and history-file
-                  (file-exists? history-file)
-                  (file-readable? history-file))
-             (history-from-file history-file)
-             (history-init!))
-         (##sys#setslot port 11 (history)))
+      (letrec ((port
+                (make-input-port
+                 (lambda ()              ; read-char
+                   (parameterize ((history (##sys#slot port 11)))
+                     (let ([last (##sys#slot port 10)])
+                       (cond [last
+                              (##sys#setislot port 10 #f)
+                              last]
+                             [else (get-next-char!)] ) )) )
+                 (lambda () ; char-ready?
+                   (parley-char-ready?) )
+                 (lambda () ; close XXX Really disable the
+                            ; signal handler here? What if the user installed one before or after
+                            ; us? This is broken
+                   (set-signal-handler! signal/int #f)
+                   (unless (##sys#slot port 8) (flush-history port))
+                   (##sys#setislot port 8 #t))
+                 (lambda ()               ; peek-char
+                   (parameterize ((history (##sys#slot port 11)))
+                     (let ([last (##sys#slot port 10)])
+                       (if last
+                           last
+                           (let ([last (get-next-char!)])
+                             (##sys#setslot port 10 last)
+                             last)  ) ))))))
+        (parameterize ((history #f))
+          (if (and history-file
+                   (file-exists? history-file)
+                   (file-readable? history-file))
+              (history-from-file history-file)
+              (history-init!))
+          (##sys#setslot port 11 (history)))
         (set-finalizer! port flush-history)
         (on-exit (lambda ()
                    (flush-history port)))
-- 
2.11.0

