From 8329e31c722e726f59a73654b8425b8ef5015760 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 15 Apr 2018 01:38:16 +0200 Subject: [PATCH] Update documentation about cursor move Fixes #115 --- .../src/main/java/org/fusesource/jansi/Ansi.java | 15 ++++++++++++--- .../java/org/fusesource/jansi/AnsiStringTest.java | 10 ++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/jansi/src/main/java/org/fusesource/jansi/Ansi.java b/jansi/src/main/java/org/fusesource/jansi/Ansi.java index 658362ab..9f595e7a 100644 --- a/jansi/src/main/java/org/fusesource/jansi/Ansi.java +++ b/jansi/src/main/java/org/fusesource/jansi/Ansi.java @@ -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; } @@ -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) { diff --git a/jansi/src/test/java/org/fusesource/jansi/AnsiStringTest.java b/jansi/src/test/java/org/fusesource/jansi/AnsiStringTest.java index 992892a0..0818a8e5 100644 --- a/jansi/src/test/java/org/fusesource/jansi/AnsiStringTest.java +++ b/jansi/src/test/java/org/fusesource/jansi/AnsiStringTest.java @@ -26,7 +26,7 @@ */ 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()); @@ -34,9 +34,15 @@ public void testNotEncoded() throws Exception { } @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()); + } } \ No newline at end of file