Skip to content

Commit

Permalink
Merge pull request #2 from bamcgill/SQLCL-4749-SUPPORT-LINE-NUMBERING…
Browse files Browse the repository at this point in the history
…-AND-CURRENT-LINE

Sqlcl 4749 support line numbering and current line
  • Loading branch information
bamcgill authored Jan 14, 2025
2 parents 91033e6 + 225600a commit 096ac10
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,7 @@ protected enum BellType {

protected String alternateIn;
protected String alternateOut;

protected int numOfSecondaryPromptLines;
protected List<AttributedString> currentLines;

public LineReaderImpl(Terminal terminal) throws IOException {
this(terminal, terminal.getName(), null);
Expand Down Expand Up @@ -4182,7 +4181,7 @@ private AttributedString expandPromptPattern(String pattern, int padToWidth, Str
sb.append(getInt(LINE_OFFSET, 0) + (line + 1));
break decode;
case '*':
if (this.numOfSecondaryPromptLines == line + 1) {
if (getCurrentLineNo(this.currentLines) == line) {
sb.append("*");
} else {
sb.append(" ");
Expand Down Expand Up @@ -4243,6 +4242,21 @@ private AttributedString expandPromptPattern(String pattern, int padToWidth, Str
return AttributedString.join(null, parts);
}

private int getCurrentLineNo(List<AttributedString> lines) {
int currentLine = -1;
int cursor = buf.cursor();
int start = 0;
for (int l = 0; l < lines.size(); l++) {
int end = start + lines.get(l).length();
if (cursor >= start && cursor <= end) {
currentLine = l;
break;
}
start = end + 1;
}
return currentLine;
}

private AttributedString fromAnsi(String str) {
return AttributedString.fromAnsi(str, Collections.singletonList(0), alternateIn, alternateOut);
}
Expand Down Expand Up @@ -4289,7 +4303,7 @@ private AttributedString insertSecondaryPrompts(
buf.setLength(0);
}
int line = 0;
this.numOfSecondaryPromptLines = lines.size();
this.currentLines = lines;
while (line < lines.size() - 1) {
sb.append(lines.get(line)).append("\n");
buf.append(lines.get(line)).append("\n");
Expand Down

0 comments on commit 096ac10

Please sign in to comment.