Skip to content

Commit

Permalink
Support providing default values for line reader variables using syst…
Browse files Browse the repository at this point in the history
…em properties (#821)
  • Loading branch information
gnodet committed Oct 24, 2023
1 parent 8da980b commit 7cbba19
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion reader/src/main/java/org/jline/reader/LineReader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2021, the original author(s).
* Copyright (c) 2002-2023, the original author(s).
*
* This software is distributable under the BSD license. See the terms of the
* BSD license in the documentation provided with this software.
Expand Down Expand Up @@ -411,6 +411,11 @@ public interface LineReader {
*/
String INPUT_RC_FILE_NAME = "input-rc-file-name";

/**
* Prefix to automatically delegate variables to system properties
*/
String SYSTEM_PROPERTY_PREFIX = "system-property-prefix";

Map<String, KeyMap<Binding>> defaultKeyMaps();

enum Option {
Expand Down
12 changes: 12 additions & 0 deletions reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public class LineReaderImpl implements LineReader, Flushable {
public static final int DEFAULT_INDENTATION = 0;
public static final int DEFAULT_FEATURES_MAX_BUFFER_SIZE = 1000;
public static final int DEFAULT_SUGGESTIONS_MIN_BUFFER_SIZE = 1;
public static final String DEFAULT_SYSTEM_PROPERTY_PREFIX = "org.jline.reader.props.";

private static final int MIN_ROWS = 3;

Expand Down Expand Up @@ -314,6 +315,17 @@ public LineReaderImpl(Terminal terminal, String appName, Map<String, Object> var
} else {
this.variables = new HashMap<>();
}
String prefix = getString(SYSTEM_PROPERTY_PREFIX, DEFAULT_SYSTEM_PROPERTY_PREFIX);
if (prefix != null) {
Properties sysProps = System.getProperties();
for (String s : sysProps.stringPropertyNames()) {
if (s.startsWith(prefix)) {
String key = s.substring(prefix.length());
InputRC.setVar(this, key, sysProps.getProperty(s));
}
}
}

this.keyMaps = defaultKeyMaps();
if (!Boolean.getBoolean(PROP_DISABLE_ALTERNATE_CHARSET)) {
this.alternateIn = Curses.tputs(terminal.getStringCapability(Capability.enter_alt_charset_mode));
Expand Down

0 comments on commit 7cbba19

Please sign in to comment.