/** Convenience method that associates the specified {@code width} and {@code height} with the keys {@value PropertiesConstants#PROP_PANE_WIDTH} and {@value PropertiesConstants#PROP_PANE_HEIGHT}*/ public void setPaneDimension(int width, int height) { put(PROP_PANE_WIDTH, width); put(PROP_PANE_HEIGHT, height); } }
/** Convenience method that calls {@link #withPropertiesConfigurator(Consumer)} * with a configurator that takes all terminal properties with the given prefix * and applies them after stripping the prefix from their keys. * <br>For example, if {@code textio.properties} contains: * <pre> * textio.prompt.color = green * textio.input.color = yellow * textio.warn.prompt.color = red * textio.warn.input.color = orange * </pre> * then the following statement: * <pre> * textIO.newBooleanInputReader() * .withPropertiesPrefix("warn") * .read("Erase all data?"); * </pre> * will display the question in red and the user input in orange. **/ @SuppressWarnings("unchecked") public B withPropertiesPrefix(String prefix) { return withPropertiesConfigurator(t -> { Set<String> keys = t.getMatchingKeys(key -> key.startsWith(prefix + ".")); int len = prefix.length() + 1; keys.forEach(key -> { String baseKey = key.substring(len); t.put(baseKey, t.getString(key)); }); }); }
props.addStringListener(PROP_USER_INTERRUPT_KEY, null, (term, newVal) -> setUserInterruptKey(newVal)); props.addStringListener(PROP_PANE_WIDTH, null, (term, newVal) -> updateScrollPaneSize(true)); props.addStringListener(PROP_PANE_HEIGHT, null, (term, newVal) -> updateScrollPaneSize(true)); props.addStringListener(PROP_PANE_BGCOLOR, null, (term, newVal) -> setPaneBackgroundColor(newVal)); props.addStringListener(PROP_PANE_TITLE, null, (term, newVal) -> setPaneTitle(newVal)); props.addStringListener(PROP_PANE_ICON_URL, null, (term, newVal) -> setPaneIconUrl(newVal)); props.addStringListener(PROP_PANE_ICON_FILE, null, (term, newVal) -> setPaneIconFile(newVal)); props.addStringListener(PROP_PANE_ICON_RESOURCE, null, (term, newVal) -> setPaneIconResource(newVal)); props.addStringListener(PROP_PROMPT_COLOR, null, (term, newVal) -> setPromptColor(newVal)); props.addStringListener(PROP_PROMPT_BGCOLOR, null, (term, newVal) -> setPromptBackgroundColor(newVal)); props.addStringListener(PROP_PROMPT_FONT_FAMILY, null, (term, newVal) -> setPromptFontFamily(newVal)); props.addIntListener(PROP_PROMPT_FONT_SIZE, DEFAULT_FONT_SIZE, (term, newVal) -> setPromptFontSize(newVal)); props.addBooleanListener(PROP_PROMPT_BOLD, false, (term, newVal) -> setPromptBold(newVal)); props.addBooleanListener(PROP_PROMPT_ITALIC, false, (term, newVal) -> setPromptItalic(newVal)); props.addBooleanListener(PROP_PROMPT_UNDERLINE, false, (term, newVal) -> setPromptUnderline(newVal)); props.addBooleanListener(PROP_PROMPT_SUBSCRIPT, false, (term, newVal) -> setPromptSubscript(newVal)); props.addBooleanListener(PROP_PROMPT_SUPERSCRIPT, false, (term, newVal) -> setPromptSuperscript(newVal)); props.addStringListener(PROP_INPUT_COLOR, null, (term, newVal) -> setInputColor(newVal)); props.addStringListener(PROP_INPUT_BGCOLOR, null, (term, newVal) -> setInputBackgroundColor(newVal)); props.addStringListener(PROP_INPUT_FONT_FAMILY, null, (term, newVal) -> setInputFontFamily(newVal)); props.addIntListener(PROP_INPUT_FONT_SIZE, DEFAULT_FONT_SIZE, (term, newVal) -> setInputFontSize(newVal)); props.addBooleanListener(PROP_INPUT_BOLD, false, (term, newVal) -> setInputBold(newVal)); props.addBooleanListener(PROP_INPUT_ITALIC, false, (term, newVal) -> setInputItalic(newVal)); props.addBooleanListener(PROP_INPUT_UNDERLINE, false, (term, newVal) -> setInputUnderline(newVal)); props.addBooleanListener(PROP_INPUT_SUBSCRIPT, false, (term, newVal) -> setInputSubscript(newVal)); props.addBooleanListener(PROP_INPUT_SUPERSCRIPT, false, (term, newVal) -> setInputSuperscript(newVal));
public WebTextTerminal() { TerminalProperties<WebTextTerminal> props = getProperties(); props.addStringListener(PROP_USER_INTERRUPT_KEY, null, (term, newVal) -> setUserInterruptKey(newVal)); props.addStringListener(PROP_PROMPT_STYLE_CLASS, null, (term, newVal) -> addSetting("promptStyleClass", newVal)); props.addStringListener(PROP_PROMPT_COLOR, null, (term, newVal) -> addSetting("promptColor", newVal)); props.addStringListener(PROP_PROMPT_BGCOLOR, null, (term, newVal) -> addSetting("promptBackgroundColor", newVal)); props.addBooleanListener(PROP_PROMPT_BOLD, false, (term, newVal) -> addSetting("promptBold", newVal)); props.addBooleanListener(PROP_PROMPT_ITALIC, false, (term, newVal) -> addSetting("promptItalic", newVal)); props.addBooleanListener(PROP_PROMPT_UNDERLINE, false, (term, newVal) -> addSetting("promptUnderline", newVal)); props.addStringListener(PROP_INPUT_STYLE_CLASS, null, (term, newVal) -> addSetting("inputStyleClass", newVal)); props.addStringListener(PROP_INPUT_COLOR, null, (term, newVal) -> addSetting("inputColor", newVal)); props.addStringListener(PROP_INPUT_BGCOLOR, null, (term, newVal) -> addSetting("inputBackgroundColor", newVal)); props.addBooleanListener(PROP_INPUT_BOLD, false, (term, newVal) -> addSetting("inputBold", newVal)); props.addBooleanListener(PROP_INPUT_ITALIC, false, (term, newVal) -> addSetting("inputItalic", newVal)); props.addBooleanListener(PROP_INPUT_UNDERLINE, false, (term, newVal) -> addSetting("inputUnderline", newVal)); props.addStringListener(PROP_PANE_BGCOLOR, null, (term, newVal) -> addSetting("paneBackgroundColor", newVal)); props.addStringListener(PROP_PANE_STYLE_CLASS, null, (term, newVal) -> addSetting("paneStyleClass", newVal)); }
TerminalProperties<?> props = getProperties(); if(propertiesConfigurator != null) { props.addListener(listener); propertiesConfigurator.accept(props); } finally { if(propertiesConfigurator != null) { props.removeListener(listener); toRestore.forEach(pair -> props.put(pair[0], pair[1]));
this.doubleInputReaderSupplier = () -> textIO.newDoubleInputReader(); this.backKeyStroke = terminal.getProperties().getString("custom.back.key", "ctrl U");
public Set<String> getMatchingKeys(String regex) { return getMatchingKeys(key -> key.matches(regex)); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public AbstractTextTerminal() { this.properties = new TerminalProperties(this); addDefaultProperty(PropertiesConstants.PROP_USER_INTERRUPT_KEY, DEFAULT_USER_INTERRUPT_KEY); }
public WebTextTerminal createCopy() { WebTextTerminal copy = new WebTextTerminal(); copy.setOnDispose(this.onDispose); copy.setOnAbort(this.onAbort); TerminalProperties<WebTextTerminal> props = copy.getProperties(); List<TerminalProperties.ExtendedChangeListener<WebTextTerminal>> listeners = getProperties().getListeners(); listeners.forEach(props::addListener); copy.setTimeoutNotEmpty(this.timeoutNotEmpty); copy.setTimeoutHasAction(this.timeoutHasAction); copy.setUserInterruptKey(this.userInterruptKeyCode, this.userInterruptKeyCtrl, this.userInterruptKeyShift, this.userInterruptKeyAlt); copy.registerUserInterruptHandler(this.userInterruptHandler, abortRead); copy.init(); return copy; }
/** * A convenience method that calls {@link #executeWithPropertiesConfigurator(Consumer, Consumer)} * with a configurator that takes all terminal properties with the given prefix * and applies them after stripping the prefix from their keys. * <br>For example, if {@code textio.properties contains}: * <pre> * textio.prompt.color = green * textio.error.prompt.color = red * </pre> * then the following statement: * <pre> * textTerminal.executeWithPropertiesPrefix("error", t -> t.println("Connection failed.")); * </pre> * will display the message in red. * @param prefix the prefix of the terminal properties whose values will be temporarily used. * @param action the action to be performed on the TextTerminal. */ default void executeWithPropertiesPrefix(String prefix, Consumer<TextTerminal<T>> action) { executeWithPropertiesConfigurator(t -> { Set<String> keys = t.getMatchingKeys(key -> key.startsWith(prefix + ".")); int len = prefix.length() + 1; keys.forEach(key -> { String baseKey = key.substring(len); t.put(baseKey, t.getString(key)); }); }, action); } }
public JLineTextTerminal(ConsoleReader reader) { if(reader == null) throw new IllegalArgumentException("reader is null"); reader.setHandleUserInterrupt(true); this.reader = reader; TerminalProperties<JLineTextTerminal> props = getProperties(); props.addStringListener(PROP_PROMPT_COLOR, null, (term, newVal) -> setPromptColor(newVal)); props.addStringListener(PROP_PROMPT_BGCOLOR, null, (term, newVal) -> setPromptBackgroundColor(newVal)); props.addBooleanListener(PROP_PROMPT_BOLD, false, (term, newVal) -> setPromptBold(newVal)); props.addBooleanListener(PROP_PROMPT_ITALIC, false, (term, newVal) -> setPromptItalic(newVal)); props.addBooleanListener(PROP_PROMPT_UNDERLINE, false, (term, newVal) -> setPromptUnderline(newVal)); props.addStringListener(PROP_INPUT_COLOR, null, (term, newVal) -> setInputColor(newVal)); props.addStringListener(PROP_INPUT_BGCOLOR, null, (term, newVal) -> setInputBackgroundColor(newVal)); props.addBooleanListener(PROP_INPUT_BOLD, false, (term, newVal) -> setInputBold(newVal)); props.addBooleanListener(PROP_INPUT_ITALIC, false, (term, newVal) -> setInputItalic(newVal)); props.addBooleanListener(PROP_INPUT_UNDERLINE, false, (term, newVal) -> setInputUnderline(newVal)); props.addStringListener(PROP_ANSI_COLOR_MODE, AnsiColorMode.STANDARD.toString(), (term, newVal) -> setAnsiColorMode(newVal)); }
/** Convenience method that associates the specified {@code bgcolor} with the key {@value PropertiesConstants#PROP_PANE_BGCOLOR} */ public void setPaneBackgroundColor(String bgcolor) { put(PROP_PANE_BGCOLOR, bgcolor); } /** Convenience method that associates the hex representation of the specified {@code bgcolor} with the key {@value PropertiesConstants#PROP_PANE_BGCOLOR} */
/** Convenience method that associates the specified {@code width} with the key {@value PropertiesConstants#PROP_PANE_WIDTH} */ public void setPaneWidth(int width) { put(PROP_PANE_WIDTH, width); } /** Convenience method that associates the specified {@code height} with the key {@value PropertiesConstants#PROP_PANE_HEIGHT} */
/** Convenience method that associates the specified {@code height} with the key {@value PropertiesConstants#PROP_PANE_HEIGHT} */ public void setPaneHeight(int height) { put(PROP_PANE_HEIGHT, height); } /** Convenience method that associates the specified {@code width} and {@code height} with the keys {@value PropertiesConstants#PROP_PANE_WIDTH} and {@value PropertiesConstants#PROP_PANE_HEIGHT}*/