Skip to content

Commit

Permalink
console-ui crash when header exceeds size of the terminal, fixes #1025
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Jun 25, 2024
1 parent 276cf24 commit 3950384
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ public AbstractPrompt(
ConsolePrompt.UiConfig cfg) {
this.terminal = terminal;
this.bindingReader = new BindingReader(terminal.reader());
this.header = header;
this.size.copy(terminal.getSize());
int listSpace = Math.min(size.getRows(), 10);
this.header = header.size() > size.getRows() - listSpace
? header.subList(header.size() - size.getRows() + listSpace, header.size())
: header;
this.message = message;
this.items = items;
this.firstItemRow = header.size() + 1;
this.firstItemRow = this.header.size() + 1;
this.config = cfg;
}

Expand Down Expand Up @@ -148,7 +152,7 @@ private List<AttributedString> displayLines(
asb.append(buffer);
out.add(asb.toAttributedString());
int listStart;
if (cursorRow - firstItemRow >= 0) {
if (cursorRow - firstItemRow >= 0 && !candidates.isEmpty() && cursorRow - firstItemRow < candidates.size()) {
String dc = candidates.get(cursorRow - firstItemRow).displ();
listStart = candidatesColumn
+ buffer.columnLength()
Expand All @@ -165,6 +169,9 @@ private List<AttributedString> displayLines(
.orElse(20),
20);
for (int i = range.first; i < range.last - 1; i++) {
if (candidates.isEmpty() || i > candidates.size() - 1) {
break;
}
Candidate c = candidates.get(i);
asb = new AttributedStringBuilder();
AttributedStringBuilder tmp = new AttributedStringBuilder();
Expand Down Expand Up @@ -199,6 +206,9 @@ private List<AttributedString> displayLines(int cursorRow, Set<String> selected)
asb.append(message);
out.add(asb.toAttributedString());
for (int i = range.first; i < range.last - 1; i++) {
if (items.isEmpty() || i > items.size() - 1) {
break;
}
ConsoleUIItemIF s = items.get(i);
asb = new AttributedStringBuilder();
if (s.isSelectable()) {
Expand Down

0 comments on commit 3950384

Please sign in to comment.