Skip to content

Commit

Permalink
Fix infinite loop bug (#252)
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
Co-authored-by: Guillaume Nodet <gnodet@gmail.com>
  • Loading branch information
arthurscchan and gnodet committed Aug 25, 2023
1 parent 58260c6 commit c3ac54f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/org/fusesource/jansi/Ansi.java
Original file line number Diff line number Diff line change
Expand Up @@ -703,10 +703,16 @@ public Ansi eraseLine(final Erase kind) {
}

public Ansi scrollUp(final int rows) {
if (rows == Integer.MIN_VALUE) {
return scrollDown(Integer.MAX_VALUE);
}
return rows > 0 ? appendEscapeSequence('S', rows) : rows < 0 ? scrollDown(-rows) : this;
}

public Ansi scrollDown(final int rows) {
if (rows == Integer.MIN_VALUE) {
return scrollUp(Integer.MAX_VALUE);
}
return rows > 0 ? appendEscapeSequence('T', rows) : rows < 0 ? scrollUp(-rows) : this;
}

Expand Down
18 changes: 18 additions & 0 deletions src/test/java/org/fusesource/jansi/AnsiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ public void apply(Ansi ansi) {
.toString());
}

@ParameterizedTest
@CsvSource({
"-2147483648,ESC[2147483647T", "2147483647,ESC[2147483647S",
"-100000,ESC[100000T", "100000,ESC[100000S"
})
public void testScrollUp(int x, String expected) {
assertAnsi(expected, Ansi.ansi().scrollUp(x));
}

@ParameterizedTest
@CsvSource({
"-2147483648,ESC[2147483647S", "2147483647,ESC[2147483647T",
"-100000,ESC[100000S", "100000,ESC[100000T"
})
public void testScrollDown(int x, String expected) {
assertAnsi(expected, Ansi.ansi().scrollDown(x));
}

@ParameterizedTest
@CsvSource({
"-1,-1,ESC[1;1H", "-1,0,ESC[1;1H", "-1,1,ESC[1;1H", "-1,2,ESC[1;2H",
Expand Down

0 comments on commit c3ac54f

Please sign in to comment.