Unbuffered input and ANSI output support for Linux, MacOS, or Windows for Java 6+
Go to file
2016-05-31 01:40:08 +02:00
src Fixed issues when running in IDE in windows for ANSI detection 2016-05-31 01:40:08 +02:00
test/com/dorkbox/console Cleaned up example 2016-05-31 01:07:02 +02:00
.gitignore Basic setup + adding libraries 2014-10-24 20:38:16 +02:00
Console.iml Code polish, added comments/javadocs. Added copyright/authors 2016-05-29 20:51:19 +02:00
LICENSE Updated version 2016-04-03 21:03:24 +02:00
LICENSE.Apachev2 Updated utils, updated license 2014-12-18 20:27:10 +01:00
LICENSE.BSD2 Updated version 2016-04-03 21:03:24 +02:00
LICENSE.MIT Updated dist, changed from included src in jar, to separate file 2014-12-30 00:30:31 +01:00
README.md Updated readme to reflect name change + ANSI functionality 2016-05-30 11:22:26 +02:00

Console

Unbuffered input and ANSI output support in consoles for linux, mac, windows. Java 6+

This library is a optimized combination of JLine and JAnsi. While it is very similar in functionality to what these libraries provide, there are several things that are significantly different.

  1. JNA direct-mapping instead of custom JNI/shell execution which is slightly slower than JNI but significantly easier to read, modify, debug, and provide support for non-intel architectures.
  2. Complete implementation of common ANSI escape codes
  3. Automatically hooks into System.err/out for seamless integration in Java environments
  4. Automatically detects when an IDE is in use (and prevents issues with console corruption)
  5. Provides buffered and unbuffered input for windows/linux/mac
  6. Backspace functionality for line input is preserved (if ANSI is enabled).
  7. Controls ECHO on/off in the console
  8. Controls Ctrl-C (SIGINT) on/off in the console
  9. Supports unsupported terminals (for example, while in an IDE ), in.read() will still return (a line is split into chars, then fed to consumer) but the enter key must still be pressed.
  10. Multi-threaded, intelligent buffering of command input for simultaneous input readers on different threads
  • This is for cross-platform use, specifically - linux arm/32/64, mac 32/64, and windows 32/64. Java 6+
Customization parameters:
Console.ENABLE_ANSI   (type boolean, default value 'true')
 - If true, allows an ANSI output stream to be created on System.out/err, otherwise it will provide an ANSI aware PrintStream which strips out the ANSI escape sequences.


Console.FORCE_ENABLE_ANSI   (type boolean, default value 'false')
 - If true, then we always force the raw ANSI output stream to be enabled (even if the output stream is not aware of ANSI commands).   
   This can be used to obtain the raw ANSI escape codes for other color aware programs (ie: less -r)
        
        
Console.ENABLE_ECHO   (type boolean, default value 'true')
 - Enables or disables character echo to stdout in the console, should call Console.setEchoEnabled(boolean) after initialization.
        
        
Console.ENABLE_INTERRUPT   (type boolean, default value 'false')
 - Enables or disables CTRL-C behavior in the console, should call Console.setInterruptEnabled(boolean) after initialization.
        
        
Console.ENABLE_BACKSPACE   (type boolean, default value 'true')
 - Enables the backspace key to delete characters in the line buffer and (if ANSI is enabled) from the screen.
        
        
        
Console.INPUT_CONSOLE_TYPE   (type String, default value 'AUTO')
 - Used to determine what console to use/hook when AUTO is not correctly working.  
   Valid options are:
     - AUTO - automatically determine which OS/console type to use
     - UNIX - try to control a UNIX console
     - WINDOWS - try to control a WINDOWS console
     - NONE - do not try to control anything, only line input is supported 
        
Note: This project was inspired (and some parts heavily modified) by the excellent 
      JLine and JAnsi libraries. Many thanks to their hard work.

We now release to maven!

There is a hard dependency in the POM file for the utilities library, which is an extremely small subset of a much larger library; including only what is necessary for this particular project to function.

This project is kept in sync with the utilities library, so "jar hell" is not an issue. Please note that the util library (in it's entirety) is not added since there are many dependencies that are not necessary for this project. No reason to require a massive amount of dependencies for one or two classes/methods.

<dependency>
  <groupId>com.dorkbox</groupId>
  <artifactId>Console</artifactId>
  <version>2.9</version>
</dependency>

Or if you don't want to use Maven, you can access the files directly here:
https://oss.sonatype.org/content/repositories/releases/com/dorkbox/Console/
https://oss.sonatype.org/content/repositories/releases/com/dorkbox/Console-Dorkbox-Util/

https://oss.sonatype.org/content/repositories/releases/com/dorkbox/ObjectPool/

https://repo1.maven.org/maven2/net/java/dev/jna/jna/
https://repo1.maven.org/maven2/net/java/dev/jna/jna-platform/
https://repo1.maven.org/maven2/org/slf4j/slf4j-api/

License

This project is © 2010 dorkbox llc, and is distributed under the terms of the Apache v2.0 License. See file "LICENSE" for further references.