Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the example project from the README to quickly test out JAnsi #50

Merged
merged 2 commits into from
Jun 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is not about example
but it seems a good change: yes, given the implementation, this method should be renamed!
+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's unrelated to the global topic of the PR, but then again that's why it's a separate commit. As it's such a small change I did not bother to explicitly mention it in the PR's description.

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