GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - fusesource/jansi: Jansi is a small java library that allows you to use ANSI escape sequences to format your console output which works even on windows.

BranchesTags
Open more actions menu

Latest commit

 

History

507 Commits
507 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
docker
docker
 
 
src
src
 
 
.gitignore
.gitignore
 
 
KEYS
KEYS
 
 
Makefile
Makefile
 
 
Makefile.common
Makefile.common
 
 
changelog.md
changelog.md
 
 
license.txt
license.txt
 
 
pom.xml
pom.xml
 
 
readme.md
readme.md
 
 

Repository files navigation

Jansi

⚠️ WARNING This library is no longer maintained. It has been merged into org.jline:jansi. Please update your dependencies to use org.jline:jansi instead.

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:

  • Kernel32 and WindowsSupport for ANSI support on Windows
  • CLibrary for POSIX tty functions on Unix and Windows

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

  • Project Home
  • Release Downloads
  • GitHub
  • Issue Tracker

About

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

fusesource.github.io/jansi/

Resources

Readme
Apache-2.0 license
Activity
Custom properties

Stars

1.2k stars

Watchers

31 watching

Forks

158 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.