8192979: jshell tool: Online help text for commands is confusing
Reviewed-by: jlahoda
--- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java Mon Dec 04 17:15:38 2017 -0800
+++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java Tue Dec 05 11:04:42 2017 -0800
@@ -227,6 +227,8 @@
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 @@
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 @@
.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 @@
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()) {
--- a/test/langtools/jdk/jshell/ToolSimpleTest.java Mon Dec 04 17:15:38 2017 -0800
+++ b/test/langtools/jdk/jshell/ToolSimpleTest.java Tue Dec 05 11:04:42 2017 -0800
@@ -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
@@ -370,6 +370,20 @@
}
@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(
(a) -> assertCommandCheckOutput(a, "/help", s -> {