Skip to content
Commits on Source (3)
......@@ -2,9 +2,43 @@
<!-- git log --pretty=format:'* [`%h`](https://github.com/fusesource/jansi/commit/%H) %s' -->
## [Jansi 1.17.1][1_17_1],
## [Jansi 1.18][1_18], released 2019-04-02
[1_18]: https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.18
* [`d52d37d`](https://github.com/fusesource/hawtjni/commit/d52d37df44a7262240cd1e3d471025ca255ce7f9) Switch to hawtjni 1.17
* [`bbd72d6`](https://github.com/fusesource/hawtjni/commit/bbd72d6e26f4e70a20a5736a496f9cb9d354ca3f) Fix error messages, #134
* [`3101eeb`](https://github.com/fusesource/hawtjni/commit/3101eeb7208d190f171a6fbded45bd984f0606dd) Provide an alternative way to get jansi version
* [`5a5e8cb`](https://github.com/fusesource/hawtjni/commit/5a5e8cbfae657900bd7d1caa55e2978086394e5d) #130 added Automatic-Module-Name to manifest for Java 9 auto-module
* [`1c4b015`](https://github.com/fusesource/hawtjni/commit/1c4b015d16432295e786dc4f806cdd077c85043e) Merge branch 'master' of https://github.com/fusesource/jansi.git
* [`70ff98d`](https://github.com/fusesource/hawtjni/commit/70ff98d5cbd5fb005d8a44ed31050388b256f9c6) switch to 1.18-SNAPSHOT # Conflicts: # example/pom.xml # jansi/pom.xml # pom.xml
* [`d5f60ed`](https://github.com/fusesource/hawtjni/commit/d5f60edf0f8c15c0c888e2aa5980c023ef1c8c9e) updated changelog for 1.17.1 release
* [`44b1ebf`](https://github.com/fusesource/hawtjni/commit/44b1ebf7c877f6b14aaa31f55b8e4ee47350d991) added Maven central icon
* [`b1ef765`](https://github.com/fusesource/hawtjni/commit/b1ef7659b711e5c94272b3802d9e0ed6feebda62) #98 added link to HawtJNI Runtime Library class documentation
* [`0507042`](https://github.com/fusesource/hawtjni/commit/0507042f44562316339b27fe997ad6456e674cf4) fixed compiler warning
* [`7ae726d`](https://github.com/fusesource/hawtjni/commit/7ae726d549de8d78cf425b1a3d2c022eb1b1cd75) improved javadoc
* [`272f395`](https://github.com/fusesource/hawtjni/commit/272f395e5eb7a38f075ec0a125d75f8c19795ca4) added details on redirection to a file
* [`e2ac629`](https://github.com/fusesource/hawtjni/commit/e2ac629b77614be325c6603ce804578ddb11749c) #124 detect console handle from stderr separately from stdout
* [`3a9c8fb`](https://github.com/fusesource/hawtjni/commit/3a9c8fbeae40b18268af3d4d87fb81084233ff9f) switch to 1.18-SNAPSHOT
* [`bca4c36`](https://github.com/fusesource/hawtjni/commit/bca4c365eaa8492297e9d0fc02c6abc1fdd5d4b1) updated changelog for 1.17.1 release
* [`b602f13`](https://github.com/fusesource/hawtjni/commit/b602f1301073cc22e60348d89807f37313bd5454) added Maven central icon
* [`a463253`](https://github.com/fusesource/hawtjni/commit/a46325307f51194ca7dd007d2042dc38bc61af0d) #98 added link to HawtJNI Runtime Library class documentation
* [`6af32f4`](https://github.com/fusesource/hawtjni/commit/6af32f434126611cbe8f362bca2488e4f5e72859) fixed compiler warning
* [`49e8293`](https://github.com/fusesource/hawtjni/commit/49e829380f599f79b8c82b3c8ea7aae56918ba02) improved javadoc
* [`3302b8f`](https://github.com/fusesource/hawtjni/commit/3302b8f4d9276d0f1c1f3698bc5f6440d5dab5a8) added details on redirection to a file
* [`9338527`](https://github.com/fusesource/hawtjni/commit/93385273035124d3541e90e3a15568371aa2f474) #124 detect console handle from stderr separately from stdout
## [Jansi 1.17.1][1_17_1], released 2018-04-16
[1_17_1]: https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.17.1
* [`2a505ba`](https://github.com/fusesource/jansi/commit/2a505ba1494f0768311ecc80aef963e7076daaf5) improved javadoc to link to Jansi native
* [`1e0f706`](https://github.com/fusesource/jansi/commit/1e0f7068465dddf4c18fa282923b06df52d705d7) Revert "Fix Thread test to run test in additional threads"
* [`8918099`](https://github.com/fusesource/jansi/commit/89180993494a176ea8c7dfbb1250f81d693637cb) Fix Thread test to run test in additional threads
* [`8329e31`](https://github.com/fusesource/jansi/commit/8329e31c722e726f59a73654b8425b8ef5015760) Update documentation about cursor move
* [`27c99e1`](https://github.com/fusesource/jansi/commit/27c99e10add97ae49e464cc8279eead19e76df9d) fixed invalid buffer size when copying to PrintStream
* [`0728c6d`](https://github.com/fusesource/jansi/commit/0728c6dbc9b3124bd6a9c63b6b642346a6339e79) fixed incorrect implementation in case of ansi.strip
* [`2142202`](https://github.com/fusesource/jansi/commit/21422020a424d229db83f4d32fa77c55dc51a352) added explanations on results expected for specific situations
* [`1a77e3c`](https://github.com/fusesource/jansi/commit/1a77e3cb816ff366e6ec811c3fb27a36a5a72916) #119 detect Git bash with TERM=xterm since BASH is not visible
* [`abe94bf`](https://github.com/fusesource/jansi/commit/abe94bf243ddb3a43fe173c8e08d105451b03efc) #114 prepare 1.17.1 release
* [`73c621f`](https://github.com/fusesource/jansi/commit/73c621ff7f2d0fd8c7e5c23a814359c34fdab012) on MSYSTEM=MINGW, only BASH is natively ANSI aware, not Git CMD #119
* [`48b0be5`](https://github.com/fusesource/jansi/commit/48b0be5eaa8a0b2cb8d27173d902d1da5f3ba9d6) improved diagnostic output
* [`68c5810`](https://github.com/fusesource/jansi/commit/68c5810336c606e938c0b70409276c3f53e3b568) Javadoc quick fix for warnings and errors
......
jansi (1.18-1) unstable; urgency=medium
* Team upload.
* New upstream release
-- Emmanuel Bourg <ebourg@apache.org> Thu, 11 Jul 2019 23:50:48 +0200
jansi (1.17.1-1) unstable; urgency=medium
* Team upload.
......
......@@ -3,7 +3,7 @@
<parent>
<artifactId>jansi-project</artifactId>
<groupId>org.fusesource.jansi</groupId>
<version>1.17.1</version>
<version>1.18</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -20,7 +20,7 @@
<parent>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi-project</artifactId>
<version>1.17.1</version>
<version>1.18</version>
</parent>
<artifactId>jansi</artifactId>
......@@ -32,7 +32,7 @@
<dependency>
<groupId>org.fusesource.hawtjni</groupId>
<artifactId>hawtjni-runtime</artifactId>
<version>1.16</version>
<version>1.17</version>
</dependency>
<dependency>
......@@ -90,7 +90,18 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>org.fusesource.jansi</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
<!-- the older clean plugin has trouble deleting directories with symlinks in them -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
......
......@@ -19,7 +19,8 @@ import java.util.ArrayList;
import java.util.concurrent.Callable;
/**
* Provides a fluent API for generating ANSI escape sequences.
* Provides a fluent API for generating
* <a href="https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences">ANSI escape sequences</a>.
*
* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
* @since 1.0
......@@ -29,6 +30,9 @@ public class Ansi {
private static final char FIRST_ESC_CHAR = 27;
private static final char SECOND_ESC_CHAR = '[';
/**
* <a href="https://en.wikipedia.org/wiki/ANSI_escape_code#Colors">ANSI 8 colors</a> for fluent API
*/
public enum Color {
BLACK(0, "BLACK"),
RED(1, "RED"),
......@@ -74,6 +78,11 @@ public class Ansi {
}
}
/**
* Display attributes, also know as
* <a href="https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters">SGR
* (Select Graphic Rendition) parameters</a>.
*/
public enum Attribute {
RESET(0, "RESET"),
INTENSITY_BOLD(1, "INTENSITY_BOLD"),
......@@ -113,6 +122,12 @@ public class Ansi {
}
/**
* ED (Erase in Display) / EL (Erase in Line) parameter (see
* <a href="https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences">CSI sequence J and K</a>)
* @see Ansi#eraseScreen(Erase)
* @see Ansi#eraseLine(Erase)
*/
public enum Erase {
FORWARD(0, "FORWARD"),
BACKWARD(1, "BACKWARD"),
......
......@@ -28,12 +28,15 @@ import java.util.Locale;
/**
* Provides consistent access to an ANSI aware console PrintStream or an ANSI codes stripping PrintStream
* if not on a terminal (see
* <a href="http://fusesource.github.io/jansi/documentation/native-api/index.html?org/fusesource/jansi/internal/CLibrary.html">Jansi native isatty(int)</a>).
* <a href="http://fusesource.github.io/jansi/documentation/native-api/index.html?org/fusesource/jansi/internal/CLibrary.html">Jansi native
* CLibrary isatty(int)</a>).
* <p>The native library used is named <code>jansi</code> and is loaded using <a href="http://fusesource.github.io/hawtjni/">HawtJNI</a> Runtime
* <a href="http://fusesource.github.io/hawtjni/documentation/api/index.html?org/fusesource/hawtjni/runtime/Library.html"><code>Library</code></a>
*
* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
* @since 1.0
* @see #systemInstall()
* @see #wrapPrintStream(PrintStream, int) wrapPrintStream(PrintStream, int) for more details on ANSI mode selection
* @see #wrapPrintStream(PrintStream, int) wrapPrintStream(PrintStream, int) for more details on ANSI mode selection
*/
public class AnsiConsole {
......@@ -126,7 +129,7 @@ public class AnsiConsole {
// On windows we know the console does not interpret ANSI codes..
try {
jansiOutputType = JansiOutputType.WINDOWS;
return new WindowsAnsiOutputStream(stream);
return new WindowsAnsiOutputStream(stream, fileno == STDOUT_FILENO);
} catch (Throwable ignore) {
// this happens when JNA is not in the path.. or
// this happens when the stdout is being redirected to a file.
......@@ -204,7 +207,7 @@ public class AnsiConsole {
// On windows we know the console does not interpret ANSI codes..
try {
jansiOutputType = JansiOutputType.WINDOWS;
return new WindowsAnsiPrintStream(ps);
return new WindowsAnsiPrintStream(ps, fileno == STDOUT_FILENO);
} catch (Throwable ignore) {
// this happens when JNA is not in the path.. or
// this happens when the stdout is being redirected to a file.
......
......@@ -40,10 +40,13 @@ import static org.fusesource.jansi.internal.CLibrary.isatty;
* support natively ANSI escape sequences like any Unix terminal,</li>
* <li>on Windows, cmd.exe, PowerShell or Git-cmd terminals should get <code>WINDOWS</code> mode.</li>
* </ul>
* The results will vary if you play with <code>jansi.passthrough</code>, <code>jansi.strip</code> or
* If stdout is redirected to a file (<code>&gt; out.txt</code>), System.out should switch to <code>STRIP_ANSI</code>.
* Same for stderr redirection (<code>2&gt; err.txt</code>) which should affect System.err mode.
* <p>The results will vary if you play with <code>jansi.passthrough</code>, <code>jansi.strip</code> or
* <code>jansi.force</code> system property, or if you redirect output to a file.
* <p>If you have a specific situation that is not covered, please report precise conditions to reproduce
* the issue and ideas on how to detect precisely the affected situation.
* @see AnsiConsole
*/
public class AnsiMain {
public static void main(String... args) throws IOException {
......
......@@ -219,19 +219,16 @@ public class AnsiRenderer {
BOLD(Attribute.INTENSITY_BOLD),
FAINT(Attribute.INTENSITY_FAINT),;
@SuppressWarnings("unchecked")
private final Enum n;
private final Enum<?> n;
private final boolean background;
@SuppressWarnings("unchecked")
Code(final Enum n, boolean background) {
Code(final Enum<?> n, boolean background) {
this.n = n;
this.background = background;
}
@SuppressWarnings("unchecked")
Code(final Enum n) {
Code(final Enum<?> n) {
this(n, false);
}
......
......@@ -24,6 +24,7 @@ import java.io.PrintStream;
*
* @author Hervé Boutemy
* @since 1.17
* @see #filter(int)
*/
public class FilterPrintStream extends PrintStream
{
......
......@@ -29,6 +29,7 @@ import static org.fusesource.jansi.internal.Kernel32.FillConsoleOutputCharacterW
import static org.fusesource.jansi.internal.Kernel32.GetConsoleScreenBufferInfo;
import static org.fusesource.jansi.internal.Kernel32.GetStdHandle;
import static org.fusesource.jansi.internal.Kernel32.SMALL_RECT;
import static org.fusesource.jansi.internal.Kernel32.STD_ERROR_HANDLE;
import static org.fusesource.jansi.internal.Kernel32.STD_OUTPUT_HANDLE;
import static org.fusesource.jansi.internal.Kernel32.ScrollConsoleScreenBuffer;
import static org.fusesource.jansi.internal.Kernel32.SetConsoleCursorPosition;
......@@ -38,7 +39,6 @@ import static org.fusesource.jansi.internal.Kernel32.SetConsoleTitle;
import java.io.IOException;
import java.io.OutputStream; // expected diff with WindowsAnsiPrintStream.java
import org.fusesource.jansi.internal.WindowsSupport;
import org.fusesource.jansi.internal.Kernel32.CONSOLE_SCREEN_BUFFER_INFO;
import org.fusesource.jansi.internal.Kernel32.COORD;
......@@ -54,7 +54,9 @@ import org.fusesource.jansi.internal.Kernel32.COORD;
*/
public final class WindowsAnsiOutputStream extends AnsiOutputStream { // expected diff with WindowsAnsiPrintStream.java
private static final long console = GetStdHandle(STD_OUTPUT_HANDLE);
private static final long stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
private static final long stderr_handle = GetStdHandle(STD_ERROR_HANDLE);
private final long console;
private static final short FOREGROUND_BLACK = 0;
private static final short FOREGROUND_YELLOW = (short) (FOREGROUND_RED | FOREGROUND_GREEN);
......@@ -97,12 +99,17 @@ public final class WindowsAnsiOutputStream extends AnsiOutputStream { // expecte
private short savedX = -1;
private short savedY = -1;
public WindowsAnsiOutputStream(OutputStream os) throws IOException { // expected diff with WindowsAnsiPrintStream.java
public WindowsAnsiOutputStream(OutputStream os, boolean stdout) throws IOException { // expected diff with WindowsAnsiPrintStream.java
super(os); // expected diff with WindowsAnsiPrintStream.java
this.console = stdout ? stdout_handle : stderr_handle;
getConsoleInfo();
originalColors = info.attributes;
}
public WindowsAnsiOutputStream(OutputStream os) throws IOException { // expected diff with WindowsAnsiPrintStream.java
this(os, true); // expected diff with WindowsAnsiPrintStream.java
}
private void getConsoleInfo() throws IOException {
out.flush(); // expected diff with WindowsAnsiPrintStream.java
if (GetConsoleScreenBufferInfo(console, info) == 0) {
......
......@@ -30,6 +30,7 @@ import static org.fusesource.jansi.internal.Kernel32.GetConsoleScreenBufferInfo;
import static org.fusesource.jansi.internal.Kernel32.GetStdHandle;
import static org.fusesource.jansi.internal.Kernel32.SMALL_RECT;
import static org.fusesource.jansi.internal.Kernel32.STD_OUTPUT_HANDLE;
import static org.fusesource.jansi.internal.Kernel32.STD_ERROR_HANDLE;
import static org.fusesource.jansi.internal.Kernel32.ScrollConsoleScreenBuffer;
import static org.fusesource.jansi.internal.Kernel32.SetConsoleCursorPosition;
import static org.fusesource.jansi.internal.Kernel32.SetConsoleTextAttribute;
......@@ -38,7 +39,6 @@ import static org.fusesource.jansi.internal.Kernel32.SetConsoleTitle;
import java.io.IOException;
import java.io.PrintStream; // expected diff with WindowsAnsiOutputStream.java
import org.fusesource.jansi.internal.WindowsSupport;
import org.fusesource.jansi.internal.Kernel32.CONSOLE_SCREEN_BUFFER_INFO;
import org.fusesource.jansi.internal.Kernel32.COORD;
......@@ -46,6 +46,8 @@ import org.fusesource.jansi.internal.Kernel32.COORD;
* A Windows ANSI escape processor, that uses JNA to access native platform
* API's to change the console attributes (see
* <a href="http://fusesource.github.io/jansi/documentation/native-api/index.html?org/fusesource/jansi/internal/Kernel32.html">Jansi native Kernel32</a>).
* <p>The native library used is named <code>jansi</code> and is loaded using <a href="http://fusesource.github.io/hawtjni/">HawtJNI</a> Runtime
* <a href="http://fusesource.github.io/hawtjni/documentation/api/index.html?org/fusesource/hawtjni/runtime/Library.html"><code>Library</code></a>
*
* @since 1.7
* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
......@@ -54,7 +56,9 @@ import org.fusesource.jansi.internal.Kernel32.COORD;
*/
public final class WindowsAnsiPrintStream extends AnsiPrintStream { // expected diff with WindowsAnsiOutputStream.java
private static final long console = GetStdHandle(STD_OUTPUT_HANDLE);
private static final long stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
private static final long stderr_handle = GetStdHandle(STD_ERROR_HANDLE);
private final long console;
private static final short FOREGROUND_BLACK = 0;
private static final short FOREGROUND_YELLOW = (short) (FOREGROUND_RED | FOREGROUND_GREEN);
......@@ -97,12 +101,17 @@ public final class WindowsAnsiPrintStream extends AnsiPrintStream { // expected
private short savedX = -1;
private short savedY = -1;
public WindowsAnsiPrintStream(PrintStream ps) throws IOException { // expected diff with WindowsAnsiOutputStream.java
public WindowsAnsiPrintStream(PrintStream ps, boolean stdout) throws IOException { // expected diff with WindowsAnsiOutputStream.java
super(ps); // expected diff with WindowsAnsiOutputStream.java
this.console = stdout ? stdout_handle : stderr_handle;
getConsoleInfo();
originalColors = info.attributes;
}
public WindowsAnsiPrintStream(PrintStream ps) throws IOException { // expected diff with WindowsAnsiOutputStream.java
this(ps, true); // expected diff with WindowsAnsiOutputStream.java
}
private void getConsoleInfo() throws IOException {
ps.flush(); // expected diff with WindowsAnsiOutputStream.java
if (GetConsoleScreenBufferInfo(console, info) == 0) {
......
/*
* Copyright (C) 2009-2019 the original author(s).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.fusesource.jansi;
import java.io.UnsupportedEncodingException;
import static org.fusesource.jansi.internal.Kernel32.FORMAT_MESSAGE_FROM_SYSTEM;
import static org.fusesource.jansi.internal.Kernel32.FormatMessageW;
import static org.fusesource.jansi.internal.Kernel32.GetLastError;
public class WindowsSupport {
public static String getLastErrorMessage() {
int errorCode = GetLastError();
return getErrorMessage(errorCode);
}
public static String getErrorMessage(int errorCode) {
int bufferSize = 160;
byte data[] = new byte[bufferSize];
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, 0, errorCode, 0, data, bufferSize, null);
try {
return new String(data, "UTF-16LE").trim();
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}
}
/*
* Copyright (C) 2009-2019 the original author(s).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.fusesource.jansi;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeTrue;
public class WindowsSupportTest {
@Test
public void testErrorMessage() {
assumeTrue(AnsiConsole.IS_WINDOWS);
String msg = WindowsSupport.getErrorMessage(500);
assertEquals(msg, "User profile cannot be loaded.");
}
}
......@@ -25,7 +25,7 @@
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi-project</artifactId>
<version>1.17.1</version>
<version>1.18</version>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
......@@ -82,7 +82,7 @@
<connection>scm:git:https://github.com/fusesource/${forge-project-id}.git</connection>
<developerConnection>scm:git:https://github.com/fusesource/${forge-project-id}.git</developerConnection>
<url>https://github.com/fusesource/${forge-project-id}/tree/${project.scm.tag}</url>
<tag>jansi-project-1.17.1</tag>
<tag>jansi-project-1.18</tag>
</scm>
<distributionManagement>
......@@ -176,6 +176,18 @@
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</pluginManagement>
......
......@@ -6,6 +6,8 @@
[Jansi][Jansi] is a small java library that allows you to use [ANSI escape
codes][ansi] to format your console output which works even on windows.
[![Maven Central](https://img.shields.io/maven-central/v/org.fusesource.jansi/jansi.svg?label=Maven%20Central)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.fusesource.jansi%22%20a%3A%22jansi%22)
[Jansi]: http://fusesource.github.io/jansi/
[ansi]: http://en.wikipedia.org/wiki/ANSI_escape_code "Wikipedia"
......