Skip to content

Commit

Permalink
fix: clear screen moves scroll up (instead of adding new lines)
Browse files Browse the repository at this point in the history
Fixes #68
  • Loading branch information
dialex committed May 8, 2022
1 parent 46d8724 commit 0187cd8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/diogonunes/jcolor/Command.java
Expand Up @@ -20,7 +20,8 @@ public class Command {
* @return Clears the terminal's text, e.g. just like the command-line `clear`.
*/
public static Command CLEAR_SCREEN() {
return new Command("2J");
// Covers https://github.com/dialex/JColor/issues/68
return new Command("H\\033[2J\"");
}

@Override
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/com/diogonunes/jcolor/tests/unit/TestAnsi.java
Expand Up @@ -6,6 +6,9 @@
import com.diogonunes.jcolor.Command;
import org.junit.jupiter.api.Test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.diogonunes.jcolor.Ansi.*;
import static com.diogonunes.jcolor.Attribute.*;
import static com.diogonunes.jcolor.tests.unit.DataGenerator.*;
Expand Down Expand Up @@ -58,6 +61,22 @@ public void GenerateCode_OneCommand() {
assertThat(code, equalTo(expectedCode));
}

@Test // Covers https://github.com/dialex/JColor/issues/68
public void GenerateCode_ComplexCommand() {
// ARRANGE
int totalCommands = 0;
Command command = Command.CLEAR_SCREEN();

// ACT
String code = generateCode(command);

// ASSERT
Matcher prefix = (Pattern.compile("\\[")).matcher(code);
while (prefix.find())
totalCommands++;
assertThat(totalCommands, equalTo(2));
}

@Test // Covers https://github.com/dialex/JColor/issues/6
public void GenerateCode_OneAttribute_Simple() {
// ARRANGE
Expand Down
Expand Up @@ -20,7 +20,7 @@ public void Attribute_AnsiCode_ClearScreen() {
String code = command.toString();

// ASSERT
String expectedAnsiCode = "2J";
String expectedAnsiCode = "H\\033[2J\"";
assertThat(code, equalTo(expectedAnsiCode));
}

Expand Down

0 comments on commit 0187cd8

Please sign in to comment.