From 8ab934287cc010e38e3ec30590805e4ef78404bd Mon Sep 17 00:00:00 2001 From: frazze-jobb Date: Thu, 4 Jul 2024 16:01:02 +0200 Subject: [PATCH] kernel: "overwrite prompt" setting adds a setting -stdlib shell_bgmsg_location (above|below) where above means output bg processes io:format above the prompt and below means output bg processes io:format on the prompt, disturbing the current line, requiring a redraw to see the whole prompt also removing code from prim_tty which was a redundant implementation of what group does when receiving "io_request" during a get_line --- lib/kernel/src/group.erl | 14 +++++++++++--- lib/kernel/src/prim_tty.erl | 14 ++------------ lib/kernel/test/interactive_shell_SUITE.erl | 13 +++++++++++++ 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/lib/kernel/src/group.erl b/lib/kernel/src/group.erl index 1792ffe2fb25..138a9f51fa0c 100644 --- a/lib/kernel/src/group.erl +++ b/lib/kernel/src/group.erl @@ -818,9 +818,17 @@ more_data(What, Cont0, Drv, Shell, Ls, Encoding) -> get_line1(edlin:edit_line(eof, Cont0), Drv, Shell, Ls, Encoding); {io_request,From,ReplyAs,Req} when is_pid(From) -> {more_chars,Cont,_More} = edlin:edit_line([], Cont0), - send_drv_reqs(Drv, edlin:erase_line()), - io_request(Req, From, ReplyAs, Drv, Shell, []), %WRONG!!! - send_drv_reqs(Drv, edlin:redraw_line(Cont)), + Location = application:get_env(stdlib, + shell_bgmsg_location, + above), + case Location of + above -> + send_drv_reqs(Drv, edlin:erase_line()), + io_request(Req, From, ReplyAs, Drv, Shell, []), %WRONG!!! + send_drv_reqs(Drv, edlin:redraw_line(Cont)); + _ -> + io_request(Req, From, ReplyAs, Drv, Shell, []) + end, get_line1({more_chars,Cont,[]}, Drv, Shell, Ls, Encoding); {reply,{From,ReplyAs},Reply} -> %% We take care of replies from puts here as well diff --git a/lib/kernel/src/prim_tty.erl b/lib/kernel/src/prim_tty.erl index 5b402c0236e6..cfab2d22d6e9 100644 --- a/lib/kernel/src/prim_tty.erl +++ b/lib/kernel/src/prim_tty.erl @@ -633,18 +633,8 @@ handle_request(State, {expand_with_trim, Binary}) -> %% putc prints Binary and overwrites any existing characters handle_request(State = #state{ unicode = U }, {putc, Binary}) -> %% Todo should handle invalid unicode? - %% print above the prompt if we have a prompt. - %% otherwise print on the current line. - case {State#state.lines_before,{State#state.buffer_before, State#state.buffer_after}, State#state.lines_after} of - {[],{[],[]},[]} -> - {PutBuffer, _} = insert_buf(State, Binary), - {[encode(PutBuffer, U)], State}; - _ -> - {Delete, DeletedState} = handle_request(State, delete_line), - {PutBuffer, _} = insert_buf(DeletedState, Binary), - {Redraw, _} = handle_request(State, redraw_prompt_pre_deleted), - {[Delete, encode(PutBuffer, U), Redraw], State} - end; + {PutBuffer, _} = insert_buf(State, Binary), + {[encode(PutBuffer, U)], State}; handle_request(State = #state{}, delete_after_cursor) -> {[State#state.delete_after_cursor], State#state{buffer_after = [], diff --git a/lib/kernel/test/interactive_shell_SUITE.erl b/lib/kernel/test/interactive_shell_SUITE.erl index c3a685622b7e..30ef9afa6d27 100644 --- a/lib/kernel/test/interactive_shell_SUITE.erl +++ b/lib/kernel/test/interactive_shell_SUITE.erl @@ -976,6 +976,7 @@ shell_huge_input(Config) -> after stop_tty(Term) end. + shell_receive_standard_out(Config) -> Term = start_tty(Config), try @@ -987,7 +988,19 @@ shell_receive_standard_out(Config) -> ok after stop_tty(Term) + end, + Term2 = start_tty([{args,["-stdlib","shell_bgmsg_location","below"]}|Config]), + try + send_tty(Term2,"my_fun(5) -> ok; my_fun(N) -> receive after 100 -> io:format(\"~p\\n\", [N]), my_fun(N+1) end.\n"), + send_tty(Term2, "spawn(shell_default, my_fun, [0]). ABC\n"), + timer:sleep(1000), + check_location(Term2, {0,-18}), %% Check that we are at the same location relative to the start. + check_content(Term2, "..0\\s+1\\s+2\\s+3\\s+4"), + ok + after + stop_tty(Term2) end. + %% Test that the shell works when invalid utf-8 (aka latin1) is sent to it shell_invalid_unicode(Config) -> Term = start_tty(Config),