Skip to content

Commit

Permalink
Jline3 always removes backslash from readline, fixes #296
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jul 26, 2018
1 parent 50749f8 commit 5a58d01
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions reader/src/main/java/org/jline/reader/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ default ParsedLine parse(String line, int cursor) throws SyntaxError {
return parse(line, cursor, ParseContext.UNSPECIFIED);
}

default boolean isEscapeChar(char ch) {
return ch == '\\';
}

enum ParseContext {
UNSPECIFIED,

Expand Down
22 changes: 14 additions & 8 deletions reader/src/main/java/org/jline/reader/impl/DefaultParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ public boolean isQuoteChar(final CharSequence buffer, final int pos) {
return false;
}

@Override
public boolean isEscapeChar(char ch) {
if (escapeChars != null) {
for (char e : escapeChars) {
if (e == ch) {
return true;
}
}
}
return false;
}

/**
* Check if this character is a valid escape char (i.e. one that has not been escaped)
*
Expand All @@ -216,14 +228,8 @@ public boolean isEscapeChar(final CharSequence buffer, final int pos) {
if (pos < 0) {
return false;
}
if (escapeChars != null) {
for (char e : escapeChars) {
if (e == buffer.charAt(pos)) {
return !isEscaped(buffer, pos);
}
}
}
return false;
char ch = buffer.charAt(pos);
return isEscapeChar(ch) && !isEscaped(buffer, pos);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ protected String finishBuffer() {
if (ch != '\n') {
sb.append(ch);
}
} else if (ch == '\\') {
} else if (parser.isEscapeChar(ch)) {
escaped = true;
} else {
sb.append(ch);
Expand Down

0 comments on commit 5a58d01

Please sign in to comment.