Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #337 from danielpetisme/fix/ansi-cursor
Browse files Browse the repository at this point in the history
Fix cursor movement
  • Loading branch information
jponge committed Dec 29, 2015
2 parents cf52565 + 871f40b commit b80a793
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/golo/ansicodes.golo
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ function cursor_position = |line, column| -> print("\u001B[" + line + ";" + col
function cursor_save_position = -> print("\u001B[s")
function cursor_restore_position = -> print("\u001B[u")

function cursor_up = |lines| -> println("\u001B[" + lines + "A")
function cursor_down = |lines| -> println("\u001B[" + lines + "B")
function cursor_forward = |columns| -> println("\u001B[" + columns + "C")
function cursor_backward = |columns| -> println("\u001B[" + columns + "D")
function cursor_up = |lines| -> print("\u001B[" + lines + "A")
function cursor_down = |lines| -> print("\u001B[" + lines + "B")
function cursor_forward = |columns| -> print("\u001B[" + columns + "C")
function cursor_backward = |columns| -> print("\u001B[" + columns + "D")

function erase_display = -> print("\u001B[2J")
function erase_line = -> print("\u001B[K")
Expand Down
64 changes: 64 additions & 0 deletions src/test/java/gololang/AnsiCodesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2012-2015 Institut National des Sciences Appliquées de Lyon (INSA-Lyon)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package gololang;

import org.hamcrest.Matchers;
import org.testng.SkipException;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.reflect.Method;

import static org.eclipse.golo.internal.testing.TestUtils.compileAndLoadGoloModule;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

public class AnsiCodesTest {

private static final String SRC = "src/test/resources/for-test/";
private Class<?> moduleClass;

private StringOutputStream out;

public static class StringOutputStream extends OutputStream {

private StringBuilder buffer = new StringBuilder();

@Override
public void write(int b) throws IOException {
buffer.append((char)b);
}

public String getString() {
return buffer.toString();
}
}

@BeforeMethod
public void load_module() throws Throwable {
if (System.getenv("golo.bootstrapped") == null) {
throw new SkipException("Golo is in a bootstrap build execution");
}
moduleClass = compileAndLoadGoloModule(SRC, "ansicodes.golo");
out = new StringOutputStream();
System.setOut(new PrintStream(out));
}

@Test
public void cursor_movement() throws Throwable {
Method cursor_movement = moduleClass.getMethod("cursor_movement");
cursor_movement.invoke(null);
assertThat(out.getString(), is("\u001B[2C\u001B[10A\u001B[5D\u001B[3B"));
}
}
14 changes: 14 additions & 0 deletions src/test/resources/for-test/ansicodes.golo
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ............................................................................................... #

module golo.test.bootstrapped.JSON

import gololang.AnsiCodes

# ............................................................................................... #

function cursor_movement = {
cursor_forward(2)
cursor_up(10)
cursor_backward(5)
cursor_down(3)
}

0 comments on commit b80a793

Please sign in to comment.