Skip to content

Commit

Permalink
Make setters chainable, fixes #187
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Dec 19, 2017
1 parent 152cf8f commit c74bc3b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions reader/src/main/java/org/jline/reader/LineReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,14 @@ enum RegionType {
*/
String readLine(String prompt, String rightPrompt, MaskingCallback maskingCallback, String buffer) throws UserInterruptException, EndOfFileException;

//
// Chainable setters
//

LineReader variable(String name, Object value);

LineReader option(Option option, boolean value);

void callWidget(String name);

Map<String, Object> getVariables();
Expand Down
28 changes: 28 additions & 0 deletions reader/src/main/java/org/jline/reader/impl/DefaultParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,34 @@ public class DefaultParser implements Parser {

private boolean eofOnEscapedNewLine;

//
// Chainable setters
//

public DefaultParser quoteChars(final char[] chars) {
this.quoteChars = chars;
return this;
}

public DefaultParser escapeChars(final char[] chars) {
this.escapeChars = chars;
return this;
}

public DefaultParser eofOnUnclosedQuote(boolean eofOnUnclosedQuote) {
this.eofOnUnclosedQuote = eofOnUnclosedQuote;
return this;
}

public DefaultParser eofOnEscapedNewLine(boolean eofOnEscapedNewLine) {
this.eofOnEscapedNewLine = eofOnEscapedNewLine;
return this;
}

//
// Java bean getters and setters
//

public void setQuoteChars(final char[] chars) {
this.quoteChars = chars;
}
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 @@ -796,6 +796,12 @@ public String getKeyMap() {
return keyMap;
}

@Override
public LineReader variable(String name, Object value) {
variables.put(name, value);
return this;
}

@Override
public Map<String, Object> getVariables() {
return variables;
Expand All @@ -811,6 +817,12 @@ public void setVariable(String name, Object value) {
variables.put(name, value);
}

@Override
public LineReader option(Option option, boolean value) {
options.put(option, value);
return this;
}

@Override
public boolean isSet(Option option) {
Boolean b = options.get(option);
Expand Down

0 comments on commit c74bc3b

Please sign in to comment.