• Stars
    star
    1,034
  • Rank 44,573 (Top 0.9 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 15 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Jansi is a small java library that allows you to use ANSI escape sequences to format your console output which works even on windows.

Jansi

Description

Jansi is a small java library that allows you to use ANSI escape codes to format your console output which works even on Windows.

It also provides the required JNI libraries:

Maven Central

Features

  • Implements ANSI escape colorization/handling that is missing on the Windows platform, using integrated JNI library.
  • Strips ANSI escape codes if process output is is being redirected and not attached to a terminal.
  • Easy to use Ansi escape sequence builder API.
  • JNI access to low-level console features.

Synopsis

Most unix terminals support rendering ANSI escape codes when Java sends them via System.out, but when this is done on Windows, they don't get interpreted and you get garbage on the console.

Furthermore, even when on Unix, when process output is being redirected to a file, you typically don't want to output escape codes to the file since most file viewers and editors will not properly display the escape codes.

Jansi detects and abstracts the ANSI support provided by the attached terminal. When your Java application uses Jansi, it can always assume that standard out and error streams support ANSI sequences. Depending on the platform and if the application output is attached to a real terminal, Jansi will do one of the following with the ANSI escape codes that it receives:

  • Pass them through untouched
  • Filter them out
  • Use platform specific APIs to implement the terminal commands represented by the escape sequence

Example Usage

Enabling the Jansi ANSI support into your application is as simple as doing a simple static method call:

import org.fusesource.jansi.AnsiConsole;
...
AnsiConsole.systemInstall();

Disabling it is also done via a static method:

AnsiConsole.systemUninstall();

It is safe to call those methods multiple times, they keep track of how many times systemInstall() has been called and only uninstalls when the systemUninstall() method is called a corresponding number of times.

Using the Ansi escape sequence builder:

import static org.fusesource.jansi.Ansi.*;
import static org.fusesource.jansi.Ansi.Color.*;
...
System.out.println( ansi().eraseScreen().fg(RED).a("Hello").fg(GREEN).a(" World").reset() );

The above will clear the screen, write Hello in red and World in green, then reset the color attributes so that subsequent data printed to the stream uses the default colors.

But there is an even simpler way to accomplish the above using the render method:

System.out.println( ansi().eraseScreen().render("@|red Hello|@ @|green World|@") );

Project Links

More Repositories

1

mqtt-client

A Java MQTT Client
Java
1,260
star
2

leveldbjni

A Java Native Interface to LevelDB
Shell
532
star
3

hawtdispatch

The libdispatch style API for Java and Scala
Java
184
star
4

hawtjni

A JNI code generator based on the JNI generator used by the eclipse SWT project
Java
156
star
5

rocksdbjni

A Java JNI driver to rocksdb
Shell
61
star
6

hawtjournal

A variable length record, checksumming, append only rotating log implementation with graceful recovery
Java
55
star
7

stompjms

The JMS interface to STOMP
Java
46
star
8

fuse-extra

Fuse Extra: A collection of addons and plugins for the open source projects FuseSource support'
Java
34
star
9

coffeebar

The CoffeScript based Web Framework for Rapid Application Development.
JavaScript
31
star
10

jansi-native

Builds the JNI libraries for the jansi project
Java
31
star
11

coffeejade

CoffeeScript version of Jade
JavaScript
24
star
12

sap-quickstarts

Java
11
star
13

jmspool

JMS Connection Pool
Java
10
star
14

hudsongen

Generates FuseSource hudson configuration using Scalate
Scala
8
star
15

rrd4j

RRD4J is a high performance data logging and graphing system for time series data
Java
7
star
16

jdbm

Git mirror of the JDBM2 project
Java
6
star
17

jvmassert

Integrates Scala assertions with the JVM assertion framework
Scala
6
star
18

hawtjms

Multi-Protocol JMS v1.1 client
Java
5
star
19

fusemq-c

C client to FuseMQ and ActiveMQ
C++
4
star
20

fuse-console

A web console for Fuse
JavaScript
3
star
21

fabric

Old repo for Fuse Fabric: its now moved to https://github.com/fusesource/fuse
Java
3
star
22

joram-jms-tests

A mavenized distribution of the Joram JMS tests
Java
2
star
23

build-scripts

A collection of handy scripts for developing code with maven, git, java etc
Ruby
2
star
24

crowdmysql

MySQL based user store for Crowd
Java
2
star
25

hudson-results

Java
2
star
26

fuse-rhq-bundles

RHQ bundles for JBoss Fuse
1
star
27

sap-certification-tests

Java
1
star