Skip to content

Commit

Permalink
Fix off-by-one problems with right prompts.
Browse files Browse the repository at this point in the history
  • Loading branch information
PerBothner committed Nov 21, 2016
1 parent f5ad557 commit ac55a63
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main/java/org/jline/reader/impl/LineReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3445,12 +3445,15 @@ private AttributedString insertSecondaryPrompts(AttributedString strAtt, List<At

private AttributedString addRightPrompt(AttributedString prompt, AttributedString line) {
int width = prompt.columnLength();
int nb = size.getColumns() - width - line.columnLength() - 3;
if (nb >= 0) {
boolean endsWithNl = line.length() > 0
&& line.charAt(line.length() - 1) == '\n';
// columnLength counts -1 for the final newline; adjust for that
int nb = size.getColumns() - width
- (line.columnLength() + (endsWithNl ? 1 : 0));
if (nb >= 3) {
AttributedStringBuilder sb = new AttributedStringBuilder(size.getColumns());
boolean endsWithNl = line.charAt(line.length() - 1) == '\n';
sb.append(line, 0, endsWithNl ? line.length() - 1 : line.length());
for (int j = 0; j < nb + 2; j++) {
for (int j = 0; j < nb; j++) {
sb.append(' ');
}
sb.append(prompt);
Expand Down

0 comments on commit ac55a63

Please sign in to comment.