File 1961-shell-Print-hints-for-when-shell-is-stuck.patch of Package erlang

From f28b570ea3d3c1229d098287c657397e398c973f Mon Sep 17 00:00:00 2001
From: Lukas Larsson <lukas@erlang.org>
Date: Fri, 30 Aug 2024 14:44:19 +0200
Subject: [PATCH 1/2] shell: Print hints for when shell is stuck

---
 lib/kernel/src/user_drv.erl                 | 15 +++++++++------
 lib/kernel/test/interactive_shell_SUITE.erl |  2 ++
 lib/stdlib/src/shell.erl                    |  7 +++++--
 3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/lib/kernel/src/user_drv.erl b/lib/kernel/src/user_drv.erl
index d6666acd69..d90bb8cb69 100644
--- a/lib/kernel/src/user_drv.erl
+++ b/lib/kernel/src/user_drv.erl
@@ -608,7 +608,7 @@ switch_loop(internal, init, State) ->
                           groups = gr_add_cur(Gr1, NewGroup, {shell,start,[]})}};
 	jcl ->
             NewTTYState =
-                io_requests([{insert_chars,unicode,<<"\nUser switch command (type h for help)\n">>}],
+                io_requests([{insert_chars,unicode,<<"\nUser switch command (enter 'h' for help)\n">>}],
                             State#state.tty),
 	    %% init edlin used by switch command and have it copy the
 	    %% text buffer from current group process
@@ -708,11 +708,14 @@ switch_cmd({c, I}, Gr0, _Dumb) ->
     end;
 switch_cmd({i, I}, Gr) ->
     case gr_get_num(Gr, I) of
-	{pid,Pid} ->
-	    exit(Pid, interrupt),
-	    {retry, []};
-	undefined ->
-	    unknown_group()
+        {pid,Pid} ->
+            exit(Pid, interrupt),
+
+            {retry, [{put_chars, unicode,
+                      unicode:characters_to_binary(
+                        io_lib:format("Interrupted job ~p, enter 'c' to resume.~n",[I]))}]};
+        undefined ->
+            unknown_group()
     end;
 switch_cmd({k, I}, Gr) ->
     case gr_get_num(Gr, I) of
diff --git a/lib/kernel/test/interactive_shell_SUITE.erl b/lib/kernel/test/interactive_shell_SUITE.erl
index f48f2d397b..8247bfc1f1 100644
--- a/lib/kernel/test/interactive_shell_SUITE.erl
+++ b/lib/kernel/test/interactive_shell_SUITE.erl
@@ -2389,6 +2389,8 @@ job_control_local(Config) when is_list(Config) ->
                {expect,  "\r\n35\r\n"},
                {expect,  "2> $"},
                {putline, "receive M -> M end.\r\n"},
+               {sleep, 6000},
+               {expect, "Command is taking a long time"},
                {putline, "\^g"},
                {expect,  "--> $"},
                {putline, "i 3"},
diff --git a/lib/stdlib/src/shell.erl b/lib/stdlib/src/shell.erl
index 20bdce94bf..86015896a8 100644
--- a/lib/stdlib/src/shell.erl
+++ b/lib/stdlib/src/shell.erl
@@ -728,6 +728,8 @@ shell_cmd(Es, Eval, Bs, RT, FT, Ds, W) ->
     shell_rep(Eval, Bs, RT, FT, Ds).
 
 shell_rep(Ev, Bs0, RT, FT, Ds0) ->
+    shell_rep(Ev, Bs0, RT, FT, Ds0, 5000).
+shell_rep(Ev, Bs0, RT, FT, Ds0, Timeout) ->
     receive
         {shell_rep,Ev,{value,V,Bs,Ds}} ->
             {V,Ev,Bs,Ds};
@@ -774,6 +776,9 @@ shell_rep(Ev, Bs0, RT, FT, Ds0) ->
         _Other ->                               % Ignore everything else
             io:format("Throwing ~p~n", [_Other]),
             shell_rep(Ev, Bs0, RT, FT, Ds0)
+        after Timeout ->
+            io:format("Command is taking a long time, type Ctrl+G, then enter 'i' to interrupt~n"),
+            shell_rep(Ev, Bs0, RT, FT, Ds0, infinity)
     end.
 
 nocatch(throw, {Term,Stack}) ->
-- 
2.43.0

openSUSE Build Service is sponsored by