Skip to content

Commit

Permalink
Merge pull request #50 from sschuberth/master
Browse files Browse the repository at this point in the history
Add the example project from the README to quickly test out JAnsi
  • Loading branch information
chirino authored Jun 15, 2016
2 parents 08fc17a + e180ab1 commit 55c3817
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
43 changes: 43 additions & 0 deletions example/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>jansi-project</artifactId>
<groupId>org.fusesource.jansi</groupId>
<version>1.13-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>example</artifactId>

<dependencies>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<configuration>
<mainClass>org.fusesource.jansi.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>

</project>
12 changes: 12 additions & 0 deletions example/src/main/java/org/fusesource/jansi/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.fusesource.jansi;

import static org.fusesource.jansi.Ansi.*;
import static org.fusesource.jansi.Ansi.Color.*;

public class Main {
public static void main(String[] args) {
AnsiConsole.systemInstall();
System.out.println( ansi().eraseScreen().fg(RED).a("Hello").fg(GREEN).a(" World").reset() );
AnsiConsole.systemUninstall();
}
}
9 changes: 4 additions & 5 deletions jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static OutputStream wrapOutputStream(final OutputStream stream, int filen
}

String os = System.getProperty("os.name");
if (os.startsWith("Windows") && !isCygwin()) {
if (os.startsWith("Windows") && !isXterm()) {

// On windows we know the console does not interpret ANSI codes..
try {
Expand All @@ -107,7 +107,7 @@ public static OutputStream wrapOutputStream(final OutputStream stream, int filen
// If we can detect that stdout is not a tty.. then setup
// to strip the ANSI sequences..
int rc = isatty(fileno);
if (!isCygwin() && !forceColored && rc == 0) {
if (!isXterm() && !forceColored && rc == 0) {
return new AnsiOutputStream(stream);
}

Expand All @@ -129,9 +129,8 @@ public void close() throws IOException {
};
}

private static boolean isCygwin() {
String term = System.getenv("TERM");
return term != null && term.equals("xterm");
private static boolean isXterm() {
return "xterm".equals(System.getenv("TERM"));
}

/**
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@

<modules>
<module>jansi</module>
<module>example</module>
<!--
<module>jansi-website</module>
-->
Expand Down

0 comments on commit 55c3817

Please sign in to comment.