8192979: jshell tool: Online help text for commands is confusing
Reviewed-by: jlahoda
This commit is contained in:
parent
3d3780d2e8
commit
5252da0f37
src/jdk.jshell/share/classes/jdk/internal/jshell/tool
test/langtools/jdk/jshell
@ -227,6 +227,8 @@ public class JShellTool implements MessageHandler {
|
||||
static final String BUILTIN_FILE_PATH_FORMAT = "/jdk/jshell/tool/resources/%s.jsh";
|
||||
static final String INT_PREFIX = "int $$exit$$ = ";
|
||||
|
||||
static final int OUTPUT_WIDTH = 72;
|
||||
|
||||
// match anything followed by whitespace
|
||||
private static final Pattern OPTION_PRE_PATTERN =
|
||||
Pattern.compile("\\s*(\\S+\\s+)*?");
|
||||
@ -2347,17 +2349,14 @@ public class JShellTool implements MessageHandler {
|
||||
return false;
|
||||
}
|
||||
if (!which.equals("_blank")) {
|
||||
hardrb("help.set." + which);
|
||||
printHelp("/set " + which, "help.set." + which);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (matches.length > 0) {
|
||||
for (Command c : matches) {
|
||||
hard("");
|
||||
hard("%s", c.command);
|
||||
hard("");
|
||||
hardrb(c.helpKey);
|
||||
printHelp(c.command, c.helpKey);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
@ -2368,8 +2367,7 @@ public class JShellTool implements MessageHandler {
|
||||
.toArray(String[]::new);
|
||||
if (subs.length > 0) {
|
||||
for (String sub : subs) {
|
||||
hardrb("help.set." + sub);
|
||||
hard("");
|
||||
printHelp("/set " + sub, "help.set." + sub);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -2391,6 +2389,16 @@ public class JShellTool implements MessageHandler {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void printHelp(String name, String key) {
|
||||
int len = name.length();
|
||||
String centered = "%" + ((OUTPUT_WIDTH + len) / 2) + "s";
|
||||
hard("");
|
||||
hard(centered, name);
|
||||
hard(centered, Stream.generate(() -> "=").limit(len).collect(Collectors.joining()));
|
||||
hard("");
|
||||
hardrb(key);
|
||||
}
|
||||
|
||||
private boolean cmdHistory() {
|
||||
cmdout.println();
|
||||
for (String s : input.currentSessionHistory()) {
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024 8160089 8153897 8167128 8154513 8170015 8170368 8172102 8172103 8165405 8173073 8173848 8174041 8173916 8174028 8174262 8174797 8177079 8180508 8177466 8172154
|
||||
* @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024 8160089 8153897 8167128 8154513 8170015 8170368 8172102 8172103 8165405 8173073 8173848 8174041 8173916 8174028 8174262 8174797 8177079 8180508 8177466 8172154 8192979
|
||||
* @summary Simple jshell tool tests
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.main
|
||||
@ -369,6 +369,20 @@ public class ToolSimpleTest extends ReplToolTesting {
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHelpStart() {
|
||||
test(
|
||||
(a) -> assertCommandCheckOutput(a, "/help /exit",
|
||||
s -> assertTrue(s.replaceAll("\\r\\n?", "\n").startsWith(
|
||||
"| \n" +
|
||||
"| /exit\n" +
|
||||
"| =====\n" +
|
||||
"| "
|
||||
))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHelpFormat() {
|
||||
test(
|
||||
|
Loading…
x
Reference in New Issue
Block a user