/** * Prints a message that possibly contains line separators and subsequently prints a line separator. */ default void println(String message) { print(message); println(); }
/** * Prints a formatted string using the specified locale, format string and arguments. * @param l The {@linkplain java.util.Locale locale} to apply during formatting. If {@code l} is {@code null} then no localization is applied. * @param format A format string as described in {@link java.util.Formatter}. * @param args Arguments referenced by the format specifiers in the format string. */ default void printf(Locale l, String format, Object... args) { print(String.format(l, format, args)); }
/** * Prints each message in the list, inserting the line separator string between messages. * A separator string is also printed after the last message. * The messages in the list may contain line separators. */ default void println(List<String> messages) { print(messages); println(); }
/** * Prints a formatted string using the default locale and the specified format string and arguments. * @param format A format string as described in {@link java.util.Formatter}. * @param args Arguments referenced by the format specifiers in the format string. */ default void printf(String format, Object... args) { print(String.format(format, args)); }
/** * Prints each message in the list in its raw form, inserting the line separator string between messages. * No separator string is printed after the last message. * The behavior is undefined if one or more strings in the list contain line separators. */ default void rawPrint(List<String> messages) { if(messages != null && !messages.isEmpty()) { rawPrint(messages.get(0)); messages.subList(1, messages.size()).forEach(msg -> { println(); print(msg); }); } }
public static void clearScreen(TextTerminal<?> terminal) { if (terminal instanceof JLineTextTerminal) { terminal.print("\033[H\033[2J"); } else if (terminal instanceof SwingTextTerminal) { ((SwingTextTerminal) terminal).resetToOffset(0); } }
private T getValueFromIndex(String sVal, TextTerminal<?> textTerminal) { try { int optIndex = Integer.parseInt(sVal); if(optIndex > 0 && optIndex <= possibleValues.size()) { return possibleValues.get(optIndex - 1); } } catch (NumberFormatException e) { // Continue the execution. The next statement will print the error message. } textTerminal.executeWithPropertiesPrefix(PROPS_PREFIX_ERROR_MESSAGE, t -> { textTerminal.print(getDefaultErrorMessage(sVal)); textTerminal.println(" Enter a value between 1 and " + possibleValues.size() + "."); }); textTerminal.println(); return null; }
public static void clearScreen(TextTerminal<?> terminal) { if (terminal instanceof JLineTextTerminal) { terminal.print("\033[H\033[2J"); } else if (terminal instanceof SwingTextTerminal) { ((SwingTextTerminal) terminal).resetToOffset(0); } }
textTerminal.print(prompt); boolean useColon = false; if(promptAdjustments && prompt != null && !prompt.isEmpty()) { if(promptAdjustments && defaultValue != null) textTerminal.print(" [" + valueFormatter.apply(defaultValue) + "]: "); else textTerminal.print(useColon ? ": " : " "); } else if(promptAdjustments) { int optionCount = possibleValues.size(); }) .collect(Collectors.joining(", ", " (", "): ")); textTerminal.print(sValues); } else { textTerminal.println(useColon ? ":" : ""); textTerminal.print(valueListMode ? "Enter your choices as comma-separated values: " : "Enter your choice: ");
public void setUpCountryKey() { String keyCountries = "ctrl O"; boolean isKeyCountries = terminal.registerHandler(keyCountries, t -> { terminal.executeWithPropertiesPrefix("country", tt -> { tt.print(System.lineSeparator() + System.lineSeparator() + " ---------------------- Country Listing ----------------------" + System.lineSeparator() + System.lineSeparator()); List<String> countries = UnitManager.getCountryList(); tt.print(printList(countries)); } ); return new ReadHandlerData(ReadInterruptionStrategy.Action.RESTART).withRedrawRequired(true); }); if (isKeyCountries) { terminal.println("Press Ctrl-O to show a list of countries."); } }
private T getValueFromString(String sVal, TextTerminal<?> textTerminal) { ParseResult<T> result = parseAndCheck(sVal); List<String> errMessages = result.getErrorMessages(); if(errMessages == null) { Optional<T> value = getPossibleValue(result.getValue()); if(value.isPresent()) return value.get(); textTerminal.executeWithPropertiesPrefix(PROPS_PREFIX_ERROR_MESSAGE, t -> { t.print(getDefaultErrorMessage(sVal)); if(inlinePossibleValues) { String options = possibleValues.stream() .map(val -> "'" + valueFormatter.apply(val) + "'") .collect(Collectors.joining(", ")); t.println(" Please enter one of: " + options + "."); } else { t.println(" Please enter one of the displayed values."); } }); textTerminal.println(); } else { textTerminal.executeWithPropertiesPrefix(PROPS_PREFIX_ERROR_MESSAGE, t -> t.println(errMessages)); textTerminal.println(); } return null; }
public void setUpJobKey() { String keyJobs = "ctrl J"; boolean isKeyJobs = terminal.registerHandler(keyJobs, t -> { terminal.executeWithPropertiesPrefix("job", tt -> { tt.print(System.lineSeparator() + System.lineSeparator() + " ----------------------- Job Listing -----------------------" + System.lineSeparator() + System.lineSeparator()); List<String> jobs = JobType.getEditedList(); tt.print(printList(jobs)); } ); return new ReadHandlerData(ReadInterruptionStrategy.Action.RESTART).withRedrawRequired(true); }); if (isKeyJobs) { terminal.println("Press Ctrl-J to show a list of jobs."); } }
tt -> tt.print("\n\nType the name of a product to be included in your shopping list.")); return new ReadHandlerData(ReadInterruptionStrategy.Action.RESTART).withRedrawRequired(true); });
@Override public void accept(TextIO textIO, RunnerData runnerData) { TextTerminal<?> terminal = textIO.getTextTerminal(); String initData = (runnerData == null) ? null : runnerData.getInitData(); AppUtil.printGsonMessage(terminal, initData); terminal.executeWithPropertiesPrefix("custom.title", t -> t.print("Cuboid dimensions: ")); terminal.println(); double length = textIO.newDoubleInputReader() .withMinVal(0.0) .withPropertiesPrefix("custom.length") .read("Length"); double width = textIO.newDoubleInputReader() .withMinVal(0.0) .withPropertiesPrefix("custom.width") .read("Width"); double height = textIO.newDoubleInputReader() .withMinVal(0.0) .withPropertiesPrefix("custom.height") .read("Height"); terminal.executeWithPropertiesPrefix("custom.title", t -> t.print("The volume of your cuboid is: " + length * width * height)); terminal.println(); textIO.newStringInputReader() .withMinLength(0) .withPropertiesPrefix("custom.neutral") .read("\nPress enter to terminate..."); textIO.dispose(); }