1187 }
1188 return true;
1189 }
1190
1191 private boolean cmdExit() {
1192 regenerateOnDeath = false;
1193 live = false;
1194 if (!replayableHistory.isEmpty()) {
1195 // Prevent history overflow by calculating what will fit, starting
1196 // with must recent
1197 int sepLen = RECORD_SEPARATOR.length();
1198 int length = 0;
1199 int first = replayableHistory.size();
1200 while(length < Preferences.MAX_VALUE_LENGTH && --first >= 0) {
1201 length += replayableHistory.get(first).length() + sepLen;
1202 }
1203 String hist = replayableHistory
1204 .subList(first + 1, replayableHistory.size())
1205 .stream()
1206 .reduce( (a, b) -> a + RECORD_SEPARATOR + b)
1207 .get();
1208 prefs.put(REPLAY_RESTORE_KEY, hist);
1209 }
1210 fluffmsg("jshell.msg.goodbye");
1211 return true;
1212 }
1213
1214 boolean cmdHelp(String arg) {
1215 ArgTokenizer at = new ArgTokenizer(arg);
1216 String subject = at.next();
1217 if (subject != null) {
1218 Command[] matches = commands.values().stream()
1219 .filter(c -> c.command.startsWith(subject))
1220 .toArray(size -> new Command[size]);
1221 at.mark();
1222 String sub = at.next();
1223 if (sub != null && matches.length == 1 && matches[0].command.equals("/set")) {
1224 at.rewind();
1225 return printSetHelp(at);
1226 }
1227 if (matches.length > 0) {
|
1187 }
1188 return true;
1189 }
1190
1191 private boolean cmdExit() {
1192 regenerateOnDeath = false;
1193 live = false;
1194 if (!replayableHistory.isEmpty()) {
1195 // Prevent history overflow by calculating what will fit, starting
1196 // with must recent
1197 int sepLen = RECORD_SEPARATOR.length();
1198 int length = 0;
1199 int first = replayableHistory.size();
1200 while(length < Preferences.MAX_VALUE_LENGTH && --first >= 0) {
1201 length += replayableHistory.get(first).length() + sepLen;
1202 }
1203 String hist = replayableHistory
1204 .subList(first + 1, replayableHistory.size())
1205 .stream()
1206 .reduce( (a, b) -> a + RECORD_SEPARATOR + b)
1207 .getWhenPresent();
1208 prefs.put(REPLAY_RESTORE_KEY, hist);
1209 }
1210 fluffmsg("jshell.msg.goodbye");
1211 return true;
1212 }
1213
1214 boolean cmdHelp(String arg) {
1215 ArgTokenizer at = new ArgTokenizer(arg);
1216 String subject = at.next();
1217 if (subject != null) {
1218 Command[] matches = commands.values().stream()
1219 .filter(c -> c.command.startsWith(subject))
1220 .toArray(size -> new Command[size]);
1221 at.mark();
1222 String sub = at.next();
1223 if (sub != null && matches.length == 1 && matches[0].command.equals("/set")) {
1224 at.rewind();
1225 return printSetHelp(at);
1226 }
1227 if (matches.length > 0) {
|