]> git.eshelyaron.com Git - sweep.git/commitdiff
Set Prolog flag 'tty_control' to 'true' when using pty
authorEshel Yaron <me@eshelyaron.com>
Fri, 20 Oct 2023 14:51:15 +0000 (17:51 +0300)
committerEshel Yaron <me@eshelyaron.com>
Fri, 20 Oct 2023 15:47:09 +0000 (17:47 +0200)
When 'sweeprolog-top-level-use-pty' is non-nil, let the Prolog
top-level thread know that it controls the tty.  This affects some
aspects of the top-level interaction, namely in the presence of choice
points.  A significant benefit is that Prolog ensures that the tty
does not echo input, so we can stop setting 'comint-process-echoes'
which had the adverse effect of blocking Emacs when output stalls on
non-echoing terminals.

* sweep.pl (sweep_top_level_client/3): Become
'sweep_top_level_client/4'.  New argument says whether the top-level
controls the tty.
(sweep_top_level_pty_client/1,sweep_top_level_server_loop_/2): Adjust.
* sweeprolog.el (sweeprolog-top-level-buffer): Stop setting
'comint-process-echoes'.
(sweeprolog-top-level--post-self-insert-function): When using a tty,
send single character responses directly and assume that the top-level
echoes them back.

sweep.pl
sweeprolog.el

index 62151512a2f5fbfb621d0eefa75ea5f02df5e807..220c187dc8cd11c6502b59306ca0ed35c739f9c3 100644 (file)
--- a/sweep.pl
+++ b/sweep.pl
@@ -781,7 +781,7 @@ sweep_top_level_start_pty(Name, Id) :-
 sweep_top_level_pty_client(Name) :-
     open(Name, read, InStream, [eof_action(reset)]),
     open(Name, write, OutStream),
-    sweep_top_level_client(InStream, OutStream, ip(127,0,0,1)).
+    sweep_top_level_client(InStream, OutStream, ip(127, 0, 0, 1), true).
 
 sweep_top_level_server(_, Port) :-
     tcp_socket(ServerSocket),
@@ -808,17 +808,17 @@ sweep_top_level_server_loop_(accept(From), ServerSocket) :-
     tcp_open_socket(Slave, InStream, OutStream),
     set_stream(InStream, close_on_abort(false)),
     set_stream(OutStream, close_on_abort(false)),
-    sweep_create_thread(sweep_top_level_client(InStream, OutStream, Peer), T),
+    sweep_create_thread(sweep_top_level_client(InStream, OutStream, Peer, false), T),
     thread_property(T, id(Id)),
     thread_send_message(From, client(Id)),
     sweep_top_level_server_loop(ServerSocket).
 sweep_top_level_server_loop_(_, _).
 
-sweep_top_level_client(InStream, OutStream, ip(127,0,0,1)) :-
+sweep_top_level_client(InStream, OutStream, ip(127, 0, 0, 1), TC) :-
     !,
     set_prolog_IO(InStream, OutStream, OutStream),
     set_stream(InStream, tty(true)),
-    set_prolog_flag(tty_control, false),
+    set_prolog_flag(tty_control, TC),
     current_prolog_flag(encoding, Enc),
     set_stream(user_input, encoding(Enc)),
     set_stream(user_output, encoding(Enc)),
@@ -832,7 +832,7 @@ sweep_top_level_client(InStream, OutStream, ip(127,0,0,1)) :-
                      close(OutStream, [force(true)])
                    )),
     prolog.
-sweep_top_level_client(InStream, OutStream, _) :-
+sweep_top_level_client(InStream, OutStream, _, _) :-
     close(InStream),
     close(OutStream).
 
index a90baeb2b14c07f69b5b8daf4bc73edd22f4a3dc..68e66a352c0916be81a650cffa9a198a241e82fc 100644 (file)
@@ -3241,7 +3241,6 @@ top-level."
               (if sweeprolog-top-level-use-pty
                   (progn
                     (make-comint-in-buffer "sweeprolog-top-level" buf nil)
-                    (setq-local comint-process-echoes t)
                     (process-send-eof (get-buffer-process buf))
                     (sweeprolog--query-once "sweep" "sweep_top_level_start_pty"
                                             (process-tty-name (get-buffer-process buf))))
@@ -3251,7 +3250,6 @@ top-level."
                                        buf
                                        (cons "localhost"
                                              sweeprolog-prolog-server-port))
-                (setq-local comint-process-echoes nil)
                 (sweeprolog--query-once "sweep" "sweep_accept_top_level_client" nil)))
         (let ((proc (get-buffer-process buf)))
           (set-process-filter proc
@@ -3335,7 +3333,12 @@ appropriate buffer."
                                                   (- pend pstart))))
                  (not (string= "|: "   prompt))
                  (not (string= "|    " prompt)))
-        (comint-send-input)))))
+        (let ((proc (get-buffer-process (current-buffer))))
+          (if (eq (process-type proc) 'network)
+              (comint-send-input)
+            (delete-char -1)
+            (process-send-string (get-buffer-process (current-buffer))
+                                 (char-to-string last-command-event))))))))
 
 (defun sweeprolog-signal-thread (tid goal)
   (sweeprolog--query-once "sweep" "sweep_thread_signal"