Skip to content

Commit

Permalink
Merge branch 'frazze/stdlib/shell_improved_help_expand2/OTP-19260' in…
Browse files Browse the repository at this point in the history
…to maint

* frazze/stdlib/shell_improved_help_expand2/OTP-19260:
  stdlib: added key command to shell to improve help

OTP-19260
  • Loading branch information
frazze-jobb committed Nov 1, 2024
2 parents da9010d + d109e95 commit ab86dab
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
19 changes: 12 additions & 7 deletions lib/kernel/src/group.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
21 changes: 14 additions & 7 deletions lib/kernel/test/interactive_shell_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
8 changes: 7 additions & 1 deletion lib/stdlib/src/edlin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()]} |
Expand Down Expand Up @@ -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}},
Expand Down
1 change: 1 addition & 0 deletions lib/stdlib/src/edlin_key.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}.
Expand Down

0 comments on commit ab86dab

Please sign in to comment.