From d109e95185a91b2421bbec831b95fdee6f78781c Mon Sep 17 00:00:00 2001 From: frazze-jobb Date: Wed, 2 Oct 2024 13:50:45 +0200 Subject: [PATCH] stdlib: added key command to shell to improve help pressing ^[h once, give you 7 lines of help text, pressing ^[h again, gives you as many lines that fits the current window height --- lib/kernel/src/group.erl | 19 ++++++++++++------- lib/kernel/test/interactive_shell_SUITE.erl | 21 ++++++++++++++------- lib/stdlib/src/edlin.erl | 8 +++++++- lib/stdlib/src/edlin_key.erl | 1 + 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/lib/kernel/src/group.erl b/lib/kernel/src/group.erl index f256b2fd2d50..0a6a5afdfe0b 100644 --- a/lib/kernel/src/group.erl +++ b/lib/kernel/src/group.erl @@ -700,8 +700,13 @@ get_line1({search,Cs,Cont,Rs}, Drv, Shell, Ls, Encoding) -> {more_chars,Ncont,_Nrs} = edlin:start(Pbs, {search,none}), put(search, new_search), get_line1(edlin:edit_line1(Cs, Ncont), Drv, Shell, Ls, Encoding); -get_line1({help, Before, Cs0, Cont, Rs}, Drv, Shell, Ls0, Encoding) -> +get_line1({Help, Before, Cs0, Cont, Rs}, Drv, Shell, Ls0, Encoding) + when Help =:= help; Help =:= help_full -> send_drv_reqs(Drv, Rs), + NLines = case Help of + help -> 7; + help_full -> 0 + end, {_,Word,_} = edlin:over_word(Before, [], 0), {R,Docs} = case edlin_context:get_context(Before) of {function, Mod} when Word =/= [] -> try @@ -727,13 +732,13 @@ get_line1({help, Before, Cs0, Cont, Rs}, Drv, Shell, Ls0, Encoding) -> case {R, Docs} of {_, {error, _}} -> send_drv(Drv, beep); {module, _} -> - Docs1 = " "++string:trim(lists:nthtail(3, Docs),both), - send_drv(Drv, {put_expand, unicode, - [unicode:characters_to_binary(Docs1)], 7}); + Docs1 = " "++string:trim(lists:nthtail(3, Docs),both), + send_drv(Drv, {put_expand, unicode, + [unicode:characters_to_binary(Docs1)], NLines}); {function, _} -> - Docs1 = " "++string:trim(Docs,both), - send_drv(Drv, {put_expand, unicode, - [unicode:characters_to_binary(Docs1)], 7}) + Docs1 = " "++string:trim(Docs,both), + send_drv(Drv, {put_expand, unicode, + [unicode:characters_to_binary(Docs1)], NLines}) end, get_line1(edlin:edit_line(Cs0, Cont), Drv, Shell, Ls0, Encoding); get_line1({Expand, Before, Cs0, Cont,Rs}, Drv, Shell, Ls0, Encoding) diff --git a/lib/kernel/test/interactive_shell_SUITE.erl b/lib/kernel/test/interactive_shell_SUITE.erl index 1f23f05e72a6..3a4a7e31554e 100644 --- a/lib/kernel/test/interactive_shell_SUITE.erl +++ b/lib/kernel/test/interactive_shell_SUITE.erl @@ -60,7 +60,7 @@ shell_update_window_unicode_wrap/1, shell_receive_standard_out/1, shell_standard_error_nlcr/1, shell_clear/1, - shell_format/1, + shell_format/1, shell_help/1, remsh_basic/1, remsh_error/1, remsh_longnames/1, remsh_no_epmd/1, remsh_expand_compatibility_25/1, remsh_expand_compatibility_later_version/1, external_editor/1, external_editor_visual/1, @@ -132,7 +132,7 @@ groups() -> {tty_latin1,[],[{group,tty_tests}]}, {tty_tests, [parallel], [shell_navigation, shell_multiline_navigation, shell_multiline_prompt, - shell_xnfix, shell_delete, shell_format, + shell_xnfix, shell_delete, shell_format, shell_help, shell_transpose, shell_search, shell_insert, shell_update_window, shell_small_window_multiline_navigation, shell_huge_input, shell_support_ansi_input, @@ -1292,12 +1292,19 @@ shell_expand_location_above(Config) -> shell_help(Config) -> Term = start_tty(Config), try - send_stdin(Term, "lists"), - send_stdin(Term, "\^[h"), + send_tty(Term, "application:put_env(kernel, shell_docs_ansi, false).\n"), + send_tty(Term, "lists"), + send_tty(Term, "\^[h"), + %% Check we can see the first line check_content(Term, "List processing functions."), - send_stdin(Term, ":all"), - send_stdin(Term, "\^[h"), - check_content(Term, "-spec all(Pred, List) -> boolean()"), + check_not_in_content(Term, "less than or equal to"), + %% Expand the help area to take up the whole buffer. + send_tty(Term, "\^[h"), + %% Check that we can see the last line (lists help should fit in the window) + check_content(Term, "less than or equal to"), + send_tty(Term, ":all"), + send_tty(Term, "\^[h"), + check_content(Term, ~S"all\(Pred, List\)"), ok after stop_tty(Term), diff --git a/lib/stdlib/src/edlin.erl b/lib/stdlib/src/edlin.erl index 8ff8f5ecdc20..567e47835b54 100644 --- a/lib/stdlib/src/edlin.erl +++ b/lib/stdlib/src/edlin.erl @@ -109,6 +109,9 @@ supports multiple lines. - **`help`** - Display help for the module or function closest on the left of the cursor. +- **`help_full`** - Display the whole help text for the module or function closest on the left of + the cursor. + - **`history_down`** - Move to the next item in the history. - **`history_up`** - Move to the previous item in the history. @@ -260,7 +263,7 @@ keymap() -> {done, continuation(), Rest :: unicode:chardata(), [user_drv:request()]} | {open_editor | format_expression | history_up | history_down | search, Cs :: unicode:chardata(), continuation(), [user_drv:request()]} | - {help | expand | expand_full, + {help | help_full | expand | expand_full, Before :: unicode:chardata(), Cs :: unicode:chardata(), continuation(), [user_drv:request()]} | @@ -382,6 +385,9 @@ edit(Buf, P, {LB, {Bef,Aft}, LA}=MultiLine, {ShellMode1, EscapePrefix}, Rs0) -> help -> {help, chars_before(MultiLine), Cs,{line, P, MultiLine, {help, none}}, reverse(Rs0)}; + help_full -> + {help_full, chars_before(MultiLine), Cs,{line, P, MultiLine, {help, none}}, + reverse(Rs0)}; tab_expand -> {expand, chars_before(MultiLine), Cs, {line, P, MultiLine, {tab_expand, none}}, diff --git a/lib/stdlib/src/edlin_key.erl b/lib/stdlib/src/edlin_key.erl index eecf44ab2e93..504859883179 100644 --- a/lib/stdlib/src/edlin_key.erl +++ b/lib/stdlib/src/edlin_key.erl @@ -188,6 +188,7 @@ key_map() -> #{ "\^[[B" => move_expand_down, "\^[[6~" => scroll_expand_down, "\^[[5~" => scroll_expand_up, + "\^[h" => help_full, default => tab_expand_quit %% go to normal mode and evaluate key input again } }.