Skip to content

Commit

Permalink
Fix issue-311: Multiline editing breaks if input has more lines than
Browse files Browse the repository at this point in the history
terminal
  • Loading branch information
mattirn committed May 19, 2019
1 parent db70837 commit 062d25c
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 @@ -100,4 +100,8 @@ public void update(List<AttributedString> lines) {
oldLines = new ArrayList<>(lines);
force = false;
}

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

0 comments on commit 062d25c

Please sign in to comment.