Skip to content

Commit

Permalink
Update documentation about cursor move
Browse files Browse the repository at this point in the history
Fixes #115
  • Loading branch information
slachiewicz authored and hboutemy committed Apr 15, 2018
1 parent 27c99e1 commit 8329e31
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
15 changes: 12 additions & 3 deletions jansi/src/main/java/org/fusesource/jansi/Ansi.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public Ansi a(Attribute attribute) {
}

@Override
public Ansi cursor(int x, int y) {
public Ansi cursor(int row, int column) {
return this;
}

Expand Down Expand Up @@ -494,8 +494,17 @@ public Ansi a(Attribute attribute) {
return this;
}

public Ansi cursor(final int x, final int y) {
return appendEscapeSequence('H', x, y);
/**
* Moves the cursor to row n, column m.
* The values are 1-based, and default to 1 (top left corner) if omitted.
* A sequence such as CSI ;5H is a synonym for CSI 1;5H as well as CSI 17;H is the same as CSI 17H and CSI 17;1H
*
* @param row row (1-based) from top
* @param column column (1 based) from left
* @return Ansi
*/
public Ansi cursor(final int row, final int column) {
return appendEscapeSequence('H', row, column);
}

public Ansi cursorToColumn(final int x) {
Expand Down
10 changes: 8 additions & 2 deletions jansi/src/test/java/org/fusesource/jansi/AnsiStringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,23 @@
*/
public class AnsiStringTest {
@Test
public void testNotEncoded() throws Exception {
public void testNotEncoded() {
AnsiString as = new AnsiString("foo");
assertEquals("foo", as.getEncoded());
assertEquals("foo", as.getPlain());
assertEquals(3, as.length());
}

@Test
public void testEncoded() throws Exception {
public void testEncoded() {
AnsiString as = new AnsiString(Ansi.ansi().a(Ansi.Attribute.INTENSITY_BOLD).a("foo").reset().toString());
assertEquals("foo", as.getPlain());
assertEquals(3, as.length());
}

@Test
public void testCursorPosition() {
Ansi ansi = Ansi.ansi().cursor( 3, 6 ).reset();
assertEquals("\u001B[3;6H\u001B[m", ansi.toString());
}
}

0 comments on commit 8329e31

Please sign in to comment.