Skip to content

Commit 8329e31

Browse files
slachiewiczhboutemy
authored andcommitted
Update documentation about cursor move
Fixes #115
1 parent 27c99e1 commit 8329e31

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

jansi/src/main/java/org/fusesource/jansi/Ansi.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public Ansi a(Attribute attribute) {
236236
}
237237

238238
@Override
239-
public Ansi cursor(int x, int y) {
239+
public Ansi cursor(int row, int column) {
240240
return this;
241241
}
242242

@@ -494,8 +494,17 @@ public Ansi a(Attribute attribute) {
494494
return this;
495495
}
496496

497-
public Ansi cursor(final int x, final int y) {
498-
return appendEscapeSequence('H', x, y);
497+
/**
498+
* Moves the cursor to row n, column m.
499+
* The values are 1-based, and default to 1 (top left corner) if omitted.
500+
* 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
501+
*
502+
* @param row row (1-based) from top
503+
* @param column column (1 based) from left
504+
* @return Ansi
505+
*/
506+
public Ansi cursor(final int row, final int column) {
507+
return appendEscapeSequence('H', row, column);
499508
}
500509

501510
public Ansi cursorToColumn(final int x) {

jansi/src/test/java/org/fusesource/jansi/AnsiStringTest.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,23 @@
2626
*/
2727
public class AnsiStringTest {
2828
@Test
29-
public void testNotEncoded() throws Exception {
29+
public void testNotEncoded() {
3030
AnsiString as = new AnsiString("foo");
3131
assertEquals("foo", as.getEncoded());
3232
assertEquals("foo", as.getPlain());
3333
assertEquals(3, as.length());
3434
}
3535

3636
@Test
37-
public void testEncoded() throws Exception {
37+
public void testEncoded() {
3838
AnsiString as = new AnsiString(Ansi.ansi().a(Ansi.Attribute.INTENSITY_BOLD).a("foo").reset().toString());
3939
assertEquals("foo", as.getPlain());
4040
assertEquals(3, as.length());
4141
}
42+
43+
@Test
44+
public void testCursorPosition() {
45+
Ansi ansi = Ansi.ansi().cursor( 3, 6 ).reset();
46+
assertEquals("\u001B[3;6H\u001B[m", ansi.toString());
47+
}
4248
}

0 commit comments

Comments
 (0)