Skip to content

Commit

Permalink
Merge remote-tracking branch 'mattirn/multiline-editing'
Browse files Browse the repository at this point in the history
# Conflicts:
#	terminal/src/main/java/org/jline/utils/Status.java
  • Loading branch information
gnodet committed Jul 4, 2019
2 parents b4f594e + 062d25c commit 4e87ebc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
39 changes: 38 additions & 1 deletion reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3718,6 +3718,8 @@ protected void redisplay(boolean flush) {
}

int cursorPos = -1;
int cursorNewLinesId = -1;
int cursorColPos = -1;
if (size.getColumns() > 0) {
AttributedStringBuilder sb = new AttributedStringBuilder().tabs(TAB_WIDTH);
sb.append(prompt);
Expand All @@ -3728,12 +3730,47 @@ protected void redisplay(boolean flush) {
sb.append(insertSecondaryPrompts(new AttributedString(buffer), secondaryPrompts, false));
List<AttributedString> promptLines = sb.columnSplitLength(size.getColumns(), false, display.delayLineWrap());
if (!promptLines.isEmpty()) {
cursorNewLinesId = promptLines.size() - 1;
cursorColPos = promptLines.get(promptLines.size() - 1).columnLength();
cursorPos = size.cursorPos(promptLines.size() - 1,
promptLines.get(promptLines.size() - 1).columnLength());
}
}

display.update(newLines, cursorPos, flush);
List<AttributedString> newLinesToDisplay = new ArrayList<>();
int displaySize = size.getRows() - Status.getStatus(terminal).size();
if (newLines.size() > displaySize) {
StringBuilder sb = new StringBuilder(">....");
// blanks are needed when displaying command completion candidate list
for (int i = sb.toString().length(); i < size.getColumns(); i++) {
sb.append(" ");
}
AttributedString partialCommandInfo = new AttributedString(sb.toString());
int lineId = newLines.size() - displaySize + 1;
int endId = displaySize;
int startId = 1;
if (lineId > cursorNewLinesId) {
lineId = cursorNewLinesId;
endId = displaySize - 1;
startId = 0;
} else {
newLinesToDisplay.add(partialCommandInfo);
}
int cursorRowPos = 0;
for (int i = startId; i < endId; i++) {
if (cursorNewLinesId == lineId) {
cursorRowPos = i;
}
newLinesToDisplay.add(newLines.get(lineId++));
}
if (startId == 0) {
newLinesToDisplay.add(partialCommandInfo);
}
cursorPos = size.cursorPos(cursorRowPos, cursorColPos);
} else {
newLinesToDisplay = newLines;
}
display.update(newLinesToDisplay, cursorPos, flush);
} finally {
lock.unlock();
}
Expand Down
4 changes: 4 additions & 0 deletions terminal/src/main/java/org/jline/utils/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,8 @@ public void restore() {
linesToRestore = Collections.emptyList();
}

public int size() {
return oldLines.size();
}

}

0 comments on commit 4e87ebc

Please sign in to comment.