Skip to content
Commits on Source (10)
# ![Jansi](http://fusesource.github.io/jansi/images/project-logo.png)
## [Jansi 1.16][1_16], released 2017-05-xx
[1_16]: http://repo.fusesource.com/nexus/content/groups/public/org/fusesource/jansi/jansi/1.16
<!-- git log --pretty=format:'* [`%h`](https://github.com/fusesource/jansi/commit/%H) %s' -->
## [Jansi 1.17.1][1_17_1],
[1_17_1]: https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.17.1
* [`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
* [`e45e466`](https://github.com/fusesource/jansi/commit/e45e4665538ba9234f5ee5d7b06d78d6a03deda3) Synchronization to protect against problems while analyzing Ansi codes resulting from multithreading
* [`0645365`](https://github.com/fusesource/jansi/commit/06453651594188403f28614097c8598c3bf387e6) update changelog.md for 1.17 release
* [`cd34211`](https://github.com/fusesource/jansi/commit/cd342119ced2e348245d6cb59990401f382ffbe6) Pass RESET_CODE via filter while closing PrintStream
* [`14b601c`](https://github.com/fusesource/jansi/commit/14b601ccaa4a24a5554407a8bc7faf45b43b622f) prepare Jansi 1.17 site
## [Jansi 1.17][1_17], released 2018-02-02
[1_17]: https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.17
* [`74c300d`](https://github.com/fusesource/jansi/commit/74c300d4d14d18d33876f4daca937adec91f5e13) Upgrade to hawtjni 1.16
* [`3f47f7e`](https://github.com/fusesource/jansi/commit/3f47f7e36d49c4a42d51d04a682382f8450fefdc) Upgrade to jansi-native 1.8
* [`2964a2f`](https://github.com/fusesource/jansi/commit/2964a2fbb50525cf8571a5a04e8363c8f131015d) deprecated WindowsAnsiOutputStream: use WindowsAnsiPrintStream
* [`8447fda`](https://github.com/fusesource/jansi/commit/8447fdafb0426a02cc1f9117ff34d7f80bd81ab1) optimization: use valueOf instead of constructor
* [`6251669`](https://github.com/fusesource/jansi/commit/62516698e86e0c6d55f3f9174c93f4943f1aed2f) added info on native library location and auto-extract
* [`007b935`](https://github.com/fusesource/jansi/commit/007b93526da79a6601107e1f6270d8e2cbb0c3a4) fixed typos
* [`346b788`](https://github.com/fusesource/jansi/commit/346b788d7f6d57f29319161157ceb481d72cfe70) added jansi-native API docs
* [`259700a`](https://github.com/fusesource/jansi/commit/259700a4daf9859a42bedf76c4df1159955c8a5f) 3.0.0 is not released yet...
* [`47e2e99`](https://github.com/fusesource/jansi/commit/47e2e99bd9afa0d88936b1c9f255dbf4fcc1db4e) removed duplicate line (already in include)
* [`16d9210`](https://github.com/fusesource/jansi/commit/16d921095bdc2e93b05bf0db8beea69cacb4b18b) improved/fixed javadoc
* [`4b24c09`](https://github.com/fusesource/jansi/commit/4b24c0928d8c233cd7dc7c7077ad4d4ddb82cb2e) Filter out escape sequence 'character set' select
* [`5f8eb45`](https://github.com/fusesource/jansi/commit/5f8eb45b376c77b6f72b65b1afe485c322f49198) Correct support for the bright colors on windows - regression fix
* [`5ac2049`](https://github.com/fusesource/jansi/commit/5ac2049c23e4d091bf48a531b450adfdb2d4ef7d) [#95](http://github.com/fusesource/jansi/issues/95) add comments on expected diffs between Print and Output Streams
* [`40631bd`](https://github.com/fusesource/jansi/commit/40631bdf503473054eefd27b3c2301bfcbe9643d) Merge pull request [#95](http://github.com/fusesource/jansi/issues/95) from hboutemy/printstream
* [`3b2eab6`](https://github.com/fusesource/jansi/commit/3b2eab623277d4e6f2dc3b9e355ed6bb9dbbf84f) Merge pull request [#99](http://github.com/fusesource/jansi/issues/99) from jycchoi/master
* [`f7a84bf`](https://github.com/fusesource/jansi/commit/f7a84bf2e1dff352c83089282ff1b1aedc20f901) Merge pull request [#84](http://github.com/fusesource/jansi/issues/84) from hboutemy/website-1.16
* [`5294c87`](https://github.com/fusesource/jansi/commit/5294c8728929f8c97c373141227242df8bfe7e1b) Correct support for the bright colors on windows - regression fix
* [`d340856`](https://github.com/fusesource/jansi/commit/d340856e78925269ecc76cd16c29850fa9ca01e0) add AnsiPrintStream and FilterPrintStream to avoid encoding issues
* [`769ebe0`](https://github.com/fusesource/jansi/commit/769ebe03655169b2eb380600912a55ac88b13efb) Merge pull request [#86](http://github.com/fusesource/jansi/issues/86) from hboutemy/javadoc
* [`3ce6987`](https://github.com/fusesource/jansi/commit/3ce698726b353dd06acaa76777c6c2451415b850) Merge pull request [#92](http://github.com/fusesource/jansi/issues/92) from pmhahn/parse-sgr0
* [`29dff3c`](https://github.com/fusesource/jansi/commit/29dff3cb48615c3d480cd400774d69ce724a9b84) Merge pull request [#88](http://github.com/fusesource/jansi/issues/88) from hboutemy/executable
* [`b11eb3e`](https://github.com/fusesource/jansi/commit/b11eb3e421bff15e22cbc650256ed8f707b57fd9) added basic color rendering tests
* [`cf69386`](https://github.com/fusesource/jansi/commit/cf69386f4010a05b5b122195957dd7f09b0d92ad) added explicit result of AnsiConsole system install on stdout&stderr
* [`0484150`](https://github.com/fusesource/jansi/commit/0484150d01bc05e4f832fe6ee094fa7f46205338) diagnose isatty for both stdout and stderr
* [`e35a57f`](https://github.com/fusesource/jansi/commit/e35a57f5fb17dbe3ac33040e436c12c96c613f81) 'isatty' check added to test
* [`ef2d858`](https://github.com/fusesource/jansi/commit/ef2d858448215ef8639663c186653c501ddfb932) Filter out escape sequence 'character set' select
* [`257b1de`](https://github.com/fusesource/jansi/commit/257b1de6336d3a6848e6739e958ee1d7bd77a712) added main class to jansi.jar to help diagnose issues or configs
* [`f33497c`](https://github.com/fusesource/jansi/commit/f33497c0117b556e39fe806581e717292e6862ef) improved/fixed javadoc
* [`b5a840e`](https://github.com/fusesource/jansi/commit/b5a840ecc600ed1cb6c3a9434e31b2d64c7d63cc) link to central for releases download
* [`d3d8488`](https://github.com/fusesource/jansi/commit/d3d848848db654d756ade20bb0391422f31e9a05) prepared website publication for 1.16, with link to changelog
## [Jansi 1.16][1_16], released 2017-05-04
[1_16]: https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.16
* [`65c537c`](https://github.com/fusesource/jansi/commit/65c537c00f57565b2794d57472ec24e36ac2420a) Upgrade to released versions of hawtjni and jansi-native
* [`7746c55`](https://github.com/fusesource/jansi/commit/7746c55160eb1d5fa1e820c838e6d540380e8c66) Update changelog.md
* [`90fb161`](https://github.com/fusesource/jansi/commit/90fb1619323ae32f9ff5b982fdcbb8939d1970b2) Update changelog
* [`18368e3`](https://github.com/fusesource/jansi/commit/18368e3adfe77574e7201693df7c557f6a6ec717) Support insert / delete lines ansi sequences
* [`52fba5a`](https://github.com/fusesource/jansi/commit/52fba5a1d826893cee4c06c2d957e608a0dae70b) Fix inverted colors
......@@ -28,7 +77,7 @@
* [`4702c58`](https://github.com/fusesource/jansi/commit/4702c58cfa41b544f8df85f505f4134f278f71b3) site enhancements for 1.15 release
## [Jansi 1.15][1_15], released 2017-03-17
[1_15]: http://repo.fusesource.com/nexus/content/groups/public/org/fusesource/jansi/jansi/1.15
[1_15]: https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.15
* [`1e70152`](https://github.com/fusesource/jansi/commit/1e701521ac6a4dec202a3dcf608744724dbb3e06) Merge remote-tracking branch 'dblock/readme-colors'
* [`a8cda38`](https://github.com/fusesource/jansi/commit/a8cda38de363ac11d6a422a1838a5c372e1e0e21) Code cleanup
......@@ -44,7 +93,7 @@
* [`38a24fa`](https://github.com/fusesource/jansi/commit/38a24fa29fa774719ea4a9a7a80797ec49a92aba) Avoid `processCursorDown` overflow on Y axis
## [Jansi 1.14][1_14], released 2016-10-04
[1_14]: http://repo.fusesource.com/nexus/content/groups/public/org/fusesource/jansi/jansi/1.14
[1_14]: https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.14
* [`eeda18c`](https://github.com/fusesource/jansi/commit/eeda18cb05122abe48b284dca969e2c060a0c009) Merge pull request [#59](http://github.com/fusesource/jansi/issues/59) from sschuberth/master
* [`b84df55`](https://github.com/fusesource/jansi/commit/b84df55b6c6a0688cf8ad790d4a3ac952ea6b9d0) Merge pull request [#65](http://github.com/fusesource/jansi/issues/65) from jbonofre/NATIVE_FIX
......@@ -53,7 +102,7 @@
* [`fad337e`](https://github.com/fusesource/jansi/commit/fad337edcf1a58e2f9a0c0f329e74f9b608419c2) Improve fix for issue [#55](http://github.com/fusesource/jansi/issues/55). If we can't load that natives for any reason, fallback to better defaults.
## [Jansi 1.13][1_13], released 2016-06-15
[1_13]: http://repo.fusesource.com/nexus/content/groups/public/org/fusesource/jansi/jansi/1.13
[1_13]: https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.13
* [`a7ec77c`](https://github.com/fusesource/jansi/commit/a7ec77c0ad5cb05f8becdb035fd7fbac9992ae3e) Updating website bits.
* [`55c3817`](https://github.com/fusesource/jansi/commit/55c381767a2bd6f744f796c7b435afbf02c74a99) Merge pull request [#50](http://github.com/fusesource/jansi/issues/50) from sschuberth/master
......@@ -70,7 +119,7 @@
* [`b9f61a2`](https://github.com/fusesource/jansi/commit/b9f61a235471253bdefabe7f8167d5271f247f39) Update readme.md
## [Jansi 1.12][1_12], released 2016-04-27
[1_12]: http://repo.fusesource.com/nexus/content/groups/public/org/fusesource/jansi/jansi/1.12
[1_12]: https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.12
* [`5d4eb66`](https://github.com/fusesource/jansi/commit/5d4eb665e428a63851ab2b51bad7c3487803e841) Fixing dep id.
* [`3949775`](https://github.com/fusesource/jansi/commit/3949775bb2df312d720fa22439efbea2b14e6ef4) Update parent pom.
......@@ -103,23 +152,23 @@
* [`9bab505`](https://github.com/fusesource/jansi/commit/9bab505bfbd57c8511ef3641c6d0fe41c92302dd) Merge pull request [#19](http://github.com/fusesource/jansi/issues/19) from xuwei-k/patch-1
## [Jansi 1.11][1_11], released 2013-05-13
[1_11]: http://repo.fusesource.com/nexus/content/groups/public/org/fusesource/jansi/jansi/1.11
[1_11]: https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.11
* Upgraded to the latest hawtjni version.
## [Jansi 1.10][1_10], released 2013-03-25
[1_10]: http://repo.fusesource.com/nexus/content/groups/public/org/fusesource/jansi/jansi/1.10
[1_10]: https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.10
* Upgraded to the latest jansi native release (1.5).
## [Jansi 1.9][1_9], released 2012-06-04
[1_9]: http://repo.fusesource.com/nexus/content/groups/public/org/fusesource/jansi/jansi/1.9
[1_9]: https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.9
* Added HtmlAnsiOutputStream that converts ANSI output to HTML.
* Fixed handling of default text and background color.
## [Jansi 1.8][1_8], released 2012-02-15
[1_8]: http://repo.fusesource.com/nexus/content/groups/public/org/fusesource/jansi/jansi/1.8
[1_8]: https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.8
* Updated bundled native libraries:
* Windows: Added support for isatty and link against the system msvcrt.dll (so no need for VC redistributables).
......@@ -127,39 +176,39 @@
* If the jansi.passthrough system property is set, then Jansi will not interpret any of the ANSI sequences.
## [Jansi 1.7][1_7], released 2011-09-21
[1_7]: http://repo.fusesource.com/nexus/content/groups/public/org/fusesource/jansi/jansi/1.7
[1_7]: https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.7
* Updated bundled native libraries:
* Windows: Adding support for PeekConsoleInputW, FlushConsoleInputBuffer so that CTRL-C can be handled by jline. Discarding mouse events on readConsoleInput.
* Linux: Built against glib 2.0 to be compatible with more versions of Linux.
## [Jansi 1.6][1_6], released 2011-06-19
[1_6]: http://repo.fusesource.com/nexus/content/groups/public/org/fusesource/jansi/jansi/1.6
[1_6]: https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.6
* Upgrade to HawtJNI 1.2 to pick up a fix to support 32 and 64 bit JVMs on a single machine.
* Add copy constructor for Ansi class.
* Port website doco to use Scalate instead of webgen.
## [Jansi 1.5][1_5], released 2010-11-04
[1_5]: http://repo.fusesource.com/nexus/content/groups/public/org/fusesource/jansi/jansi/1.5
[1_5]: https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.5
* Support for parsing Operating System Command (OSC) control sequences.
* Windows: added support for setting the console title through an OSC command, like on xterm.
* Added option to strip ANSI escapes if the 'jansi.strip' system property is set to true.
## [Jansi 1.4][1_4], released 2010-07-15
[1_4]: http://repo.fusesource.com/nexus/content/groups/public/org/fusesource/jansi/jansi/1.4
[1_4]: https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.4
* JNI libs are now bundled in the Jansi jar.
* Windows: added support for save and restore of cursor position, fixed bug in processCursorTo.
## [Jansi 1.3][1_3], released 2010-03-08
[1_3]: http://repo.fusesource.com/nexus/content/groups/public/org/fusesource/jansi/jansi/1.3
[1_3]: https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.3
* Switched to a HawtJNI generated native library instead of using JNA to access native functions.
## [Jansi 1.2.1][1_2_1], released 2010-03-08
[1_2_1]: http://repo.fusesource.com/nexus/content/groups/public/org/fusesource/jansi/jansi/1.2.1
[1_2_1]: https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.2.1
* Released to Maven Central.
......
jansi (1.16-2) UNRELEASED; urgency=medium
jansi (1.17.1-1) unstable; urgency=medium
* Team upload.
[ Miguel Landaeta ]
* Remove myself from uploaders list. (Closes: #871865)
* Update copyright info.
* Simplify d/rules.
-- Miguel Landaeta <nomadium@debian.org> Mon, 07 Aug 2017 17:11:15 +0100
[ Emmanuel Bourg ]
* New upstream release
- Depend on libhawtjni-runtime-java (>= 1.16)
* Standards-Version updated to 4.1.4
* Switch to debhelper level 11
* Use salsa.debian.org Vcs-* URLs
* Standards-Version updated to 4.3.0
-- Emmanuel Bourg <ebourg@apache.org> Sat, 16 Feb 2019 00:39:02 +0100
jansi (1.16-1) unstable; urgency=medium
......
......@@ -3,16 +3,16 @@ Section: java
Priority: optional
Maintainer: Debian Java Maintainers <pkg-java-maintainers@lists.alioth.debian.org>
Build-Depends:
debhelper (>= 10),
debhelper (>= 11~),
default-jdk,
libhawtjni-runtime-java,
libhawtjni-runtime-java (>= 1.16),
libjansi-native-java (>= 1.7),
libmaven-bundle-plugin-java,
maven-debian-helper
Standards-Version: 4.0.0
Standards-Version: 4.3.0
Vcs-Git: https://salsa.debian.org/java-team/jansi.git
Vcs-Browser: https://salsa.debian.org/java-team/jansi
Homepage: https://fusesource.github.io/jansi/
Vcs-Git: https://anonscm.debian.org/git/pkg-java/jansi.git
Vcs-Browser: https://anonscm.debian.org/cgit/pkg-java/jansi.git
Package: libjansi-java
Architecture: all
......
#!/usr/bin/make -f
%:
dh $@
get-orig-source:
uscan --download-current-version --force-download
......@@ -3,7 +3,7 @@
<parent>
<artifactId>jansi-project</artifactId>
<groupId>org.fusesource.jansi</groupId>
<version>1.16</version>
<version>1.17.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
/**
* Copyright (C) 2009-2017 the original author(s).
* Copyright (C) 2009-2018 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.
......@@ -32,10 +32,13 @@ object Website {
val project_forums_url= "http://groups.google.com/group/jansi"
val project_wiki_url= "https://github.com/fusesource/jansi/wiki"
val project_logo= "/images/project-logo.png"
val project_version= "1.15"
val project_snapshot_version= "1.16-SNAPSHOT"
val project_version= "1.17.1"
val project_snapshot_version= "1.18-SNAPSHOT"
val project_versions = List(
project_version,
"1.17",
"1.16",
"1.15",
"1.14",
"1.13",
"1.12",
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2009-2017 the original author(s).
Copyright (C) 2009-2018 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.
......@@ -21,7 +21,7 @@
<parent>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi-project</artifactId>
<version>1.16-SNAPSHOT</version>
<version>1.17.1</version>
</parent>
<artifactId>jansi-website</artifactId>
......@@ -225,6 +225,13 @@
<classifier>javadoc</classifier>
<outputDirectory>${basedir}/target/sitegen/documentation/api</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi-native</artifactId>
<version>${jansi-native-version}</version>
<classifier>javadoc</classifier>
<outputDirectory>${basedir}/target/sitegen/documentation/native-api</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
......
......@@ -26,8 +26,8 @@ We really want you to get involved in the ${project_name} project, to
[join the community](index.html) and help make it a better price of
software - please do dive in and help!
Try surf the [documentation](../documentation/index.html) and website in
general - if somethings confusing or not clear, [let us
Try surf the [developer documentation](developers.html) and website in
general - if something is confusing or not clear, [let us
know](index.html) or raise a [support request](support.html).
[Download](../download.html) the code and try it out and see what you think.
......@@ -61,9 +61,6 @@ ensure that the problem stays fixed in future releases.
## Working on the code and creating patches
We gladly accept patches if you can find ways to improve, tune or fix
${project_name} in some way.
${include("/community/_creating_patches.ssp.md")}
## Becoming a committer
......
......@@ -33,5 +33,6 @@ Ready to start hacking on ${project_name}?
# API Reference
* [`jansi` API](../documentation/api/index.html)
* [`jansi-native` API](../documentation/native-api/index.html)
Looking for the website documentation of a different ${project_name} [version](${website_base_url}/versions/index.html)?
......@@ -40,7 +40,7 @@ See the [support guide](support.html) for more details.
### How do I build ${project_name}?
First [get the source](source.html) then see the [building
guide](building.html)
guide](building.html): see [developer links](developers.html).
### How do I contribute or become a committer?
......
......@@ -32,7 +32,6 @@ Get the latest source code
#{project_name} stores its source code in a [Git](http://git-scm.com/) repository hosted on [github](http://github.com) at this location:
* [#{github_page}](#{github_page})
* [#{github_page_native}](#{github_page_native})
If you are new to Git you might like to try the [Git guide for subversion users](http://git.or.cz/course/svn.html) or have a look at the [Git community book](http://book.git-scm.com/).
......
......@@ -43,7 +43,7 @@ table.download tr td {
- for( version <- project_versions.headOption )
:&markdown
### #{project_name} #{version}
### #{project_name} #{version} ([changelog](https://github.com/fusesource/jansi/blob/master/changelog.md))
table.download
tr
......
......@@ -20,7 +20,7 @@
<parent>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi-project</artifactId>
<version>1.16</version>
<version>1.17.1</version>
</parent>
<artifactId>jansi</artifactId>
......@@ -32,7 +32,7 @@
<dependency>
<groupId>org.fusesource.hawtjni</groupId>
<artifactId>hawtjni-runtime</artifactId>
<version>1.15</version>
<version>1.16</version>
</dependency>
<dependency>
......@@ -144,6 +144,7 @@
</goals>
<configuration>
<instructions>
<Main-Class>org.fusesource.jansi.AnsiMain</Main-Class>
<Export-Package>
org.fusesource.jansi,
org.fusesource.jansi.internal
......
......@@ -236,7 +236,7 @@ public class Ansi {
}
@Override
public Ansi cursor(int x, int y) {
public Ansi cursor(int row, int column) {
return this;
}
......@@ -494,8 +494,17 @@ public class Ansi {
return this;
}
public Ansi cursor(final int x, final int y) {
return appendEscapeSequence('H', x, y);
/**
* Moves the cursor to row n, column m.
* The values are 1-based, and default to 1 (top left corner) if omitted.
* A sequence such as CSI ;5H is a synonym for CSI 1;5H as well as CSI 17;H is the same as CSI 17H and CSI 17;1H
*
* @param row row (1-based) from top
* @param column column (1 based) from left
* @return Ansi
*/
public Ansi cursor(final int row, final int column) {
return appendEscapeSequence('H', row, column);
}
public Ansi cursorToColumn(final int x) {
......
......@@ -15,8 +15,6 @@
*/
package org.fusesource.jansi;
import org.fusesource.jansi.internal.Kernel32;
import static org.fusesource.jansi.internal.CLibrary.STDERR_FILENO;
import static org.fusesource.jansi.internal.CLibrary.STDOUT_FILENO;
import static org.fusesource.jansi.internal.CLibrary.isatty;
......@@ -25,15 +23,17 @@ import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Locale;
/**
* Provides consistent access to an ANSI aware console PrintStream.
* 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>).
*
* @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
*/
public class AnsiConsole {
......@@ -43,34 +43,26 @@ public class AnsiConsole {
public static final PrintStream system_err = System.err;
public static final PrintStream err;
private static final boolean IS_WINDOWS = System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("win");
static final boolean IS_WINDOWS = System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("win");
private static final boolean IS_CYGWIN = IS_WINDOWS
static final boolean IS_CYGWIN = IS_WINDOWS
&& System.getenv("PWD") != null
&& System.getenv("PWD").startsWith("/")
&& !"cygwin".equals(System.getenv("TERM"));
private static final boolean IS_MINGW = IS_WINDOWS
static final boolean IS_MINGW_XTERM = IS_WINDOWS
&& System.getenv("MSYSTEM") != null
&& System.getenv("MSYSTEM").startsWith("MINGW");
&& System.getenv("MSYSTEM").startsWith("MINGW")
&& "xterm".equals(System.getenv("TERM"));
private static JansiOutputType jansiOutputType;
static final JansiOutputType JANSI_STDOUT_TYPE;
static final JansiOutputType JANSI_STDERR_TYPE;
static {
String charset = Charset.defaultCharset().name();
if (IS_WINDOWS && !IS_CYGWIN && !IS_MINGW) {
int codepage = Kernel32.GetConsoleOutputCP();
//http://docs.oracle.com/javase/6/docs/technotes/guides/intl/encoding.doc.html
if (Charset.isSupported("ms" + codepage)) {
charset = "ms" + codepage;
} else if (Charset.isSupported("cp" + codepage)) {
charset = "cp" + codepage;
}
}
try {
out = new PrintStream(wrapOutputStream(system_out), false, charset);
err = new PrintStream(wrapErrorOutputStream(system_err), false, charset);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
out = wrapSystemOut(system_out);
JANSI_STDOUT_TYPE = jansiOutputType;
err = wrapSystemErr(system_err);
JANSI_STDERR_TYPE = jansiOutputType;
}
private static int installed;
......@@ -78,6 +70,7 @@ public class AnsiConsole {
private AnsiConsole() {
}
@Deprecated
public static OutputStream wrapOutputStream(final OutputStream stream) {
try {
return wrapOutputStream(stream, STDOUT_FILENO);
......@@ -86,6 +79,15 @@ public class AnsiConsole {
}
}
public static PrintStream wrapSystemOut(final PrintStream ps) {
try {
return wrapPrintStream(ps, STDOUT_FILENO);
} catch (Throwable ignore) {
return wrapPrintStream(ps, 1);
}
}
@Deprecated
public static OutputStream wrapErrorOutputStream(final OutputStream stream) {
try {
return wrapOutputStream(stream, STDERR_FILENO);
......@@ -94,24 +96,36 @@ public class AnsiConsole {
}
}
public static PrintStream wrapSystemErr(final PrintStream ps) {
try {
return wrapPrintStream(ps, STDERR_FILENO);
} catch (Throwable ignore) {
return wrapPrintStream(ps, 2);
}
}
@Deprecated
public static OutputStream wrapOutputStream(final OutputStream stream, int fileno) {
// If the jansi.passthrough property is set, then don't interpret
// any of the ansi sequences.
if (Boolean.getBoolean("jansi.passthrough")) {
jansiOutputType = JansiOutputType.PASSTHROUGH;
return stream;
}
// If the jansi.strip property is set, then we just strip the
// the ansi escapes.
if (Boolean.getBoolean("jansi.strip")) {
jansiOutputType = JansiOutputType.STRIP_ANSI;
return new AnsiOutputStream(stream);
}
if (IS_WINDOWS && !IS_CYGWIN && !IS_MINGW) {
if (IS_WINDOWS && !IS_CYGWIN && !IS_MINGW_XTERM) {
// On windows we know the console does not interpret ANSI codes..
try {
jansiOutputType = JansiOutputType.WINDOWS;
return new WindowsAnsiOutputStream(stream);
} catch (Throwable ignore) {
// this happens when JNA is not in the path.. or
......@@ -119,6 +133,7 @@ public class AnsiConsole {
}
// Use the ANSIOutputStream to strip out the ANSI escape sequences.
jansiOutputType = JansiOutputType.STRIP_ANSI;
return new AnsiOutputStream(stream);
}
......@@ -130,6 +145,7 @@ public class AnsiConsole {
// If we can detect that stdout is not a tty.. then setup
// to strip the ANSI sequences..
if (!forceColored && isatty(fileno) == 0) {
jansiOutputType = JansiOutputType.STRIP_ANSI;
return new AnsiOutputStream(stream);
}
} catch (Throwable ignore) {
......@@ -140,6 +156,7 @@ public class AnsiConsole {
// By default we assume your Unix tty can handle ANSI codes.
// Just wrap it up so that when we get closed, we reset the
// attributes.
jansiOutputType = JansiOutputType.RESET_ANSI_AT_CLOSE;
return new FilterOutputStream(stream) {
@Override
public void close() throws IOException {
......@@ -150,6 +167,84 @@ public class AnsiConsole {
};
}
/**
* Wrap PrintStream applying rules in following order:<ul>
* <li>if <code>jansi.passthrough</code> is <code>true</code>, don't wrap but just passthrough (console is
* expected to natively support ANSI escape codes),</li>
* <li>if <code>jansi.strip</code> is <code>true</code>, just strip ANSI escape codes inconditionally,</li>
* <li>if OS is Windows and terminal is not Cygwin or Mingw, wrap as WindowsAnsiPrintStream to process ANSI escape codes,</li>
* <li>if file descriptor is a terminal (see <code>isatty(int)</code>) or <code>jansi.force</code> is <code>true</code>,
* just passthrough,</li>
* <li>else strip ANSI escape codes (not a terminal).</li>
* </ul>
*
* @param ps original PrintStream to wrap
* @param fileno file descriptor
* @return wrapped PrintStream depending on OS and system properties
* @since 1.17
*/
public static PrintStream wrapPrintStream(final PrintStream ps, int fileno) {
// If the jansi.passthrough property is set, then don't interpret
// any of the ansi sequences.
if (Boolean.getBoolean("jansi.passthrough")) {
jansiOutputType = JansiOutputType.PASSTHROUGH;
return ps;
}
// If the jansi.strip property is set, then we just strip the
// the ansi escapes.
if (Boolean.getBoolean("jansi.strip")) {
jansiOutputType = JansiOutputType.STRIP_ANSI;
return new AnsiPrintStream(ps);
}
if (IS_WINDOWS && !IS_CYGWIN && !IS_MINGW_XTERM) {
// On windows we know the console does not interpret ANSI codes..
try {
jansiOutputType = JansiOutputType.WINDOWS;
return new WindowsAnsiPrintStream(ps);
} catch (Throwable ignore) {
// this happens when JNA is not in the path.. or
// this happens when the stdout is being redirected to a file.
}
// Use the AnsiPrintStream to strip out the ANSI escape sequences.
jansiOutputType = JansiOutputType.STRIP_ANSI;
return new AnsiPrintStream(ps);
}
// We must be on some Unix variant, including Cygwin or MSYS(2) on Windows...
try {
// If the jansi.force property is set, then we force to output
// the ansi escapes for piping it into ansi color aware commands (e.g. less -r)
boolean forceColored = Boolean.getBoolean("jansi.force");
// If we can detect that stdout is not a tty.. then setup
// to strip the ANSI sequences..
if (!forceColored && isatty(fileno) == 0) {
jansiOutputType = JansiOutputType.STRIP_ANSI;
return new AnsiPrintStream(ps);
}
} catch (Throwable ignore) {
// These errors happen if the JNI lib is not available for your platform.
// But since we are on ANSI friendly platform, assume the user is on the console.
}
// By default we assume your Unix tty can handle ANSI codes.
// Just wrap it up so that when we get closed, we reset the
// attributes.
jansiOutputType = JansiOutputType.RESET_ANSI_AT_CLOSE;
return new FilterPrintStream(ps) {
@Override
public void close() {
ps.print(AnsiPrintStream.RESET_CODE);
ps.flush();
super.close();
}
};
}
/**
* If the standard out natively supports ANSI escape codes, then this just
* returns System.out, otherwise it will provide an ANSI aware PrintStream
......@@ -157,6 +252,7 @@ public class AnsiConsole {
* sequences.
*
* @return a PrintStream which is ANSI aware.
* @see #wrapPrintStream(PrintStream, int)
*/
public static PrintStream out() {
return out;
......@@ -169,13 +265,16 @@ public class AnsiConsole {
* sequences.
*
* @return a PrintStream which is ANSI aware.
* @see #wrapPrintStream(PrintStream, int)
*/
public static PrintStream err() {
return err;
}
/**
* Install Console.out to System.out.
* Install <code>AnsiConsole.out</code> to <code>System.out</code> and
* <code>AnsiConsole.err</code> to <code>System.err</code>.
* @see #systemUninstall()
*/
synchronized static public void systemInstall() {
installed++;
......@@ -187,7 +286,7 @@ public class AnsiConsole {
/**
* undo a previous {@link #systemInstall()}. If {@link #systemInstall()} was called
* multiple times, it {@link #systemUninstall()} must call the same number of times before
* multiple times, {@link #systemUninstall()} must be called the same number of times before
* it is actually uninstalled.
*/
synchronized public static void systemUninstall() {
......@@ -198,4 +297,24 @@ public class AnsiConsole {
}
}
/**
* Type of output installed by AnsiConsole.
*/
enum JansiOutputType {
PASSTHROUGH("just pass through, ANSI escape codes are supposed to be supported by terminal"),
RESET_ANSI_AT_CLOSE("like pass through but reset ANSI attributes when closing the stream"),
STRIP_ANSI("strip ANSI escape codes, for example when output is not a terminal"),
WINDOWS("detect ANSI escape codes and transform Jansi-supported ones into a Windows API to get desired effect" +
" (since ANSI escape codes are not natively supported by Windows terminals like cmd.exe or PowerShell)");
private final String description;
private JansiOutputType(String description) {
this.description = description;
}
String getDescription() {
return description;
}
};
}
/*
* Copyright (C) 2009-2017 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 static org.fusesource.jansi.Ansi.ansi;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.Reader;
import java.util.Properties;
import org.fusesource.hawtjni.runtime.Library;
import org.fusesource.jansi.internal.CLibrary;
import static org.fusesource.jansi.internal.CLibrary.isatty;
/**
* Main class for the library, providing executable jar to diagnose Jansi setup.
* <p>If no system property is set and output is sent to a terminal (no redirect to a file):
* <ul>
* <li>any terminal on any Unix should get <code>RESET_ANSI_AT_CLOSE</code> mode,</li>
* <li>on Windows, Git-bash or Cygwin terminals should get <code>RESET_ANSI_AT_CLOSE</code> mode also, since they
* 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
* <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.
*/
public class AnsiMain {
public static void main(String... args) throws IOException {
System.out.println("Jansi " + getJansiVersion()
+ " (Jansi native " + getPomPropertiesVersion("org.fusesource.jansi/jansi-native")
+ ", HawtJNI runtime " + getPomPropertiesVersion("org.fusesource.hawtjni/hawtjni-runtime") + ")");
System.out.println();
// info on native library
System.out.println("library.jansi.path= " + System.getProperty("library.jansi.path", ""));
System.out.println("library.jansi.version= " + System.getProperty("library.jansi.version", ""));
Library lib = new Library("jansi", CLibrary.class);
lib.load();
System.out.println("Jansi native library loaded from " + lib.getNativeLibraryPath());
if (lib.getNativeLibrarySourceUrl() != null) {
System.out.println(" which was auto-extracted from " + lib.getNativeLibrarySourceUrl());
}
System.out.println();
System.out.println("os.name= " + System.getProperty("os.name") + ", "
+ "os.version= " + System.getProperty("os.version") + ", "
+ "os.arch= " + System.getProperty("os.arch"));
System.out.println("file.encoding= " + System.getProperty("file.encoding"));
System.out.println("java.version= " + System.getProperty("java.version") + ", "
+ "java.vendor= " + System.getProperty("java.vendor") + ","
+ " java.home= " + System.getProperty("java.home"));
System.out.println();
System.out.println("jansi.passthrough= " + Boolean.getBoolean("jansi.passthrough"));
System.out.println("jansi.strip= " + Boolean.getBoolean("jansi.strip"));
System.out.println("jansi.force= " + Boolean.getBoolean("jansi.force"));
System.out.println(Ansi.DISABLE + "= " + Boolean.getBoolean(Ansi.DISABLE));
System.out.println();
System.out.println("IS_WINDOWS: " + AnsiConsole.IS_WINDOWS);
if (AnsiConsole.IS_WINDOWS) {
System.out.println("IS_CYGWIN: " + AnsiConsole.IS_CYGWIN);
System.out.println("IS_MINGW_XTERM: " + AnsiConsole.IS_MINGW_XTERM);
}
System.out.println();
diagnoseTty(false); // System.out
diagnoseTty(true); // System.err
AnsiConsole.systemInstall();
System.out.println();
System.out.println("Resulting Jansi modes for stout/stderr streams:");
System.out.println(" - System.out: " + AnsiConsole.JANSI_STDOUT_TYPE);
System.out.println(" - System.err: " + AnsiConsole.JANSI_STDERR_TYPE);
System.out.println("modes description:");
int n = 1;
for(AnsiConsole.JansiOutputType type: AnsiConsole.JansiOutputType.values()) {
System.out.println(n++ + ". " + type + ": " + type.getDescription());
}
try {
System.out.println();
testAnsi(false);
testAnsi(true);
if (args.length == 0) {
printJansiLogoDemo();
return;
}
System.out.println();
if (args.length == 1) {
File f = new File(args[0]);
if (f.exists())
{
// write file content
System.out.println(ansi().bold().a("\"" + args[0] + "\" content:").reset());
writeFileContent(f);
return;
}
}
// write args without Jansi then with Jansi AnsiConsole
System.out.println(ansi().bold().a("original args:").reset());
int i = 1;
for (String arg: args) {
AnsiConsole.system_out.print(i++ + ": ");
AnsiConsole.system_out.println(arg);
}
System.out.println(ansi().bold().a("Jansi filtered args:").reset());
i = 1;
for (String arg: args) {
System.out.print(i++ + ": ");
System.out.println(arg);
}
} finally {
AnsiConsole.systemUninstall();
}
}
private static String getJansiVersion() {
Package p = AnsiMain.class.getPackage();
return ( p == null ) ? null : p.getImplementationVersion();
}
private static void diagnoseTty(boolean stderr) {
int fd = stderr ? CLibrary.STDERR_FILENO : CLibrary.STDOUT_FILENO;
int isatty = isatty(fd);
System.out.println("isatty(STD" + (stderr ? "ERR" : "OUT") + "_FILENO): " + isatty + ", System."
+ (stderr ? "err" : "out") + " " + ((isatty == 0) ? "is *NOT*" : "is") + " a terminal");
}
private static void testAnsi(boolean stderr) {
@SuppressWarnings( "resource" )
PrintStream s = stderr ? System.err : System.out;
s.print("test on System." + (stderr ? "err" : "out") + ":");
for(Ansi.Color c: Ansi.Color.values()) {
s.print(" " + ansi().fg(c) + c + ansi().reset());
}
s.println();
s.print(" bright:");
for(Ansi.Color c: Ansi.Color.values()) {
s.print(" " + ansi().fgBright(c) + c + ansi().reset());
}
s.println();
s.print(" bold:");
for(Ansi.Color c: Ansi.Color.values()) {
s.print(" " + ansi().bold().fg(c) + c + ansi().reset());
}
s.println();
}
private static String getPomPropertiesVersion(String path) throws IOException {
InputStream in = AnsiMain.class.getResourceAsStream("/META-INF/maven/" + path + "/pom.properties");
if (in == null) {
return null;
}
try {
Properties p = new Properties();
p.load(in);
return p.getProperty("version");
} finally {
closeQuietly(in);
}
}
private static void printJansiLogoDemo() throws IOException {
Reader in = new InputStreamReader(AnsiMain.class.getResourceAsStream("jansi.txt"), "UTF-8");
try {
char[] buf = new char[1024];
int l = 0;
while ((l = in.read(buf)) >= 0) {
for(int i = 0; i < l; i++) {
System.out.print(buf[i]);
}
}
} finally {
closeQuietly(in);
}
}
private static void writeFileContent(File f) throws IOException {
InputStream in = new FileInputStream(f);
try {
byte[] buf = new byte[1024];
int l = 0;
while ((l = in.read(buf)) >= 0) {
System.out.write(buf, 0, l);
}
} finally {
closeQuietly(in);
}
}
private static void closeQuietly(Closeable c) {
try {
c.close();
} catch (IOException ioe) {
ioe.printStackTrace(System.err);
}
}
}
......@@ -15,9 +15,9 @@
*/
package org.fusesource.jansi;
import java.io.FilterOutputStream;
import java.io.FilterOutputStream; // expected diff with AnsiPrintStream.java
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStream; // expected diff with AnsiPrintStream.java
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Iterator;
......@@ -26,10 +26,10 @@ import java.util.Iterator;
* A ANSI output stream extracts ANSI escape codes written to
* an output stream and calls corresponding <code>process*</code> methods.
*
* For more information about ANSI escape codes, see:
* http://en.wikipedia.org/wiki/ANSI_escape_code
* <p>For more information about ANSI escape codes, see
* <a href="http://en.wikipedia.org/wiki/ANSI_escape_code">Wikipedia article</a>
*
* This class just filters out the escape codes so that they are not
* <p>This class just filters out the escape codes so that they are not
* sent out to the underlying OutputStream: <code>process*</code> methods
* are empty. Subclasses should actually perform the ANSI escape behaviors
* by implementing active code in <code>process*</code> methods.
......@@ -37,16 +37,17 @@ import java.util.Iterator;
* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
* @author Joris Kuipers
* @since 1.0
* @see AnsiPrintStream
*/
public class AnsiOutputStream extends FilterOutputStream {
public class AnsiOutputStream extends FilterOutputStream { // expected diff with AnsiPrintStream.java
public static final byte[] RESET_CODE = "\033[0m".getBytes();
public static final byte[] RESET_CODE = "\033[0m".getBytes(); // expected diff with AnsiPrintStream.java
@Deprecated
public static final byte[] REST_CODE = RESET_CODE;
public static final byte[] REST_CODE = RESET_CODE; // expected diff with AnsiPrintStream.java
public AnsiOutputStream(OutputStream os) {
super(os);
public AnsiOutputStream(OutputStream os) { // expected diff with AnsiPrintStream.java
super(os); // expected diff with AnsiPrintStream.java
}
private final static int MAX_ESCAPE_SEQUENCE_LENGTH = 100;
......@@ -64,6 +65,7 @@ public class AnsiOutputStream extends FilterOutputStream {
private static final int LOOKING_FOR_OSC_COMMAND_END = 6;
private static final int LOOKING_FOR_OSC_PARAM = 7;
private static final int LOOKING_FOR_ST = 8;
private static final int LOOKING_FOR_CHARSET = 9;
int state = LOOKING_FOR_FIRST_ESC_CHAR;
......@@ -72,18 +74,23 @@ public class AnsiOutputStream extends FilterOutputStream {
private static final int SECOND_OSC_CHAR = ']';
private static final int BEL = 7;
private static final int SECOND_ST_CHAR = '\\';
private static final int SECOND_CHARSET0_CHAR = '(';
private static final int SECOND_CHARSET1_CHAR = ')';
/**
* {@inheritDoc}
*/
@Override
public synchronized void write(int data) throws IOException {
public synchronized void write(int data) throws IOException { // expected diff with AnsiPrintStream.java
switch (state) {
case LOOKING_FOR_FIRST_ESC_CHAR:
if (data == FIRST_ESC_CHAR) {
buffer[pos++] = (byte) data;
state = LOOKING_FOR_SECOND_ESC_CHAR;
} else {
out.write(data);
} else { // expected diff with AnsiPrintStream.java
out.write(data); // expected diff with AnsiPrintStream.java
}
break;
break; // expected diff with AnsiPrintStream.java
case LOOKING_FOR_SECOND_ESC_CHAR:
buffer[pos++] = (byte) data;
......@@ -91,6 +98,12 @@ public class AnsiOutputStream extends FilterOutputStream {
state = LOOKING_FOR_NEXT_ARG;
} else if (data == SECOND_OSC_CHAR) {
state = LOOKING_FOR_OSC_COMMAND;
} else if (data == SECOND_CHARSET0_CHAR) {
options.add(Integer.valueOf(0));
state = LOOKING_FOR_CHARSET;
} else if (data == SECOND_CHARSET1_CHAR) {
options.add(Integer.valueOf(1));
state = LOOKING_FOR_CHARSET;
} else {
reset(false);
}
......@@ -193,6 +206,11 @@ public class AnsiOutputStream extends FilterOutputStream {
state = LOOKING_FOR_OSC_PARAM;
}
break;
case LOOKING_FOR_CHARSET:
options.add(Character.valueOf((char) data));
reset(processCharsetSelect(options));
break;
}
// Is it just too long?
......@@ -206,9 +224,9 @@ public class AnsiOutputStream extends FilterOutputStream {
* @param skipBuffer if current buffer should be skipped or written to out
* @throws IOException
*/
private void reset(boolean skipBuffer) throws IOException {
private void reset(boolean skipBuffer) throws IOException { // expected diff with AnsiPrintStream.java
if (!skipBuffer) {
out.write(buffer, 0, pos);
out.write(buffer, 0, pos); // expected diff with AnsiPrintStream.java
}
pos = 0;
startOfValue = 0;
......@@ -237,7 +255,7 @@ public class AnsiOutputStream extends FilterOutputStream {
* @param command
* @return true if the escape command was processed.
*/
private boolean processEscapeCommand(ArrayList<Object> options, int command) throws IOException {
private boolean processEscapeCommand(ArrayList<Object> options, int command) throws IOException { // expected diff with AnsiPrintStream.java
try {
switch (command) {
case 'A':
......@@ -387,7 +405,7 @@ public class AnsiOutputStream extends FilterOutputStream {
* @param options
* @return true if the operating system command was processed.
*/
private boolean processOperatingSystemCommand(ArrayList<Object> options) throws IOException {
private boolean processOperatingSystemCommand(ArrayList<Object> options) throws IOException { // expected diff with AnsiPrintStream.java
int command = optionInt(options, 0);
String label = (String) options.get(1);
// for command > 2 label could be composed (i.e. contain ';'), but we'll leave
......@@ -416,42 +434,48 @@ public class AnsiOutputStream extends FilterOutputStream {
/**
* Process <code>CSI u</code> ANSI code, corresponding to <code>RCP – Restore Cursor Position</code>
* @throws IOException
* @throws IOException IOException
*/
protected void processRestoreCursorPosition() throws IOException {
}
/**
* Process <code>CSI s</code> ANSI code, corresponding to <code>SCP – Save Cursor Position</code>
* @throws IOException
* @throws IOException IOException
*/
protected void processSaveCursorPosition() throws IOException {
}
/**
* Process <code>CSI s</code> ANSI code, corresponding to <code>IL – Insert Line</code>
* @throws IOException
* Process <code>CSI L</code> ANSI code, corresponding to <code>IL – Insert Line</code>
* @param optionInt option
* @throws IOException IOException
* @since 1.16
*/
protected void processInsertLine(int optionInt) throws IOException {
}
/**
* Process <code>CSI s</code> ANSI code, corresponding to <code>DL – Delete Line</code>
* @throws IOException
* Process <code>CSI M</code> ANSI code, corresponding to <code>DL – Delete Line</code>
* @param optionInt option
* @throws IOException IOException
* @since 1.16
*/
protected void processDeleteLine(int optionInt) throws IOException {
}
/**
* Process <code>CSI n T</code> ANSI code, corresponding to <code>SD – Scroll Down</code>
* @throws IOException
* @param optionInt option
* @throws IOException IOException
*/
protected void processScrollDown(int optionInt) throws IOException {
}
/**
* Process <code>CSI n U</code> ANSI code, corresponding to <code>SU – Scroll Up</code>
* @throws IOException
* @param optionInt option
* @throws IOException IOException
*/
protected void processScrollUp(int optionInt) throws IOException {
}
......@@ -462,7 +486,8 @@ public class AnsiOutputStream extends FilterOutputStream {
/**
* Process <code>CSI n J</code> ANSI code, corresponding to <code>ED – Erase in Display</code>
* @throws IOException
* @param eraseOption eraseOption
* @throws IOException IOException
*/
protected void processEraseScreen(int eraseOption) throws IOException {
}
......@@ -473,7 +498,8 @@ public class AnsiOutputStream extends FilterOutputStream {
/**
* Process <code>CSI n K</code> ANSI code, corresponding to <code>ED – Erase in Line</code>
* @throws IOException
* @param eraseOption eraseOption
* @throws IOException IOException
*/
protected void processEraseLine(int eraseOption) throws IOException {
}
......@@ -499,8 +525,8 @@ public class AnsiOutputStream extends FilterOutputStream {
* process <code>SGR</code> other than <code>0</code> (reset), <code>30-39</code> (foreground),
* <code>40-49</code> (background), <code>90-97</code> (foreground high intensity) or
* <code>100-107</code> (background high intensity)
* @param attribute
* @throws IOException
* @param attribute attribute
* @throws IOException IOException
* @see #processAttributeRest()
* @see #processSetForegroundColor(int)
* @see #processSetForegroundColor(int, boolean)
......@@ -524,7 +550,7 @@ public class AnsiOutputStream extends FilterOutputStream {
/**
* process <code>SGR 30-37</code> corresponding to <code>Set text color (foreground)</code>.
* @param color the text color
* @throws IOException
* @throws IOException IOException
*/
protected void processSetForegroundColor(int color) throws IOException {
processSetForegroundColor(color, false);
......@@ -535,7 +561,7 @@ public class AnsiOutputStream extends FilterOutputStream {
* <code>Set text color (foreground)</code> either in normal mode or high intensity.
* @param color the text color
* @param bright is high intensity?
* @throws IOException
* @throws IOException IOException
*/
protected void processSetForegroundColor(int color, boolean bright) throws IOException {
}
......@@ -544,7 +570,7 @@ public class AnsiOutputStream extends FilterOutputStream {
* process <code>SGR 38</code> corresponding to <code>extended set text color (foreground)</code>
* with a palette of 255 colors.
* @param paletteIndex the text color in the palette
* @throws IOException
* @throws IOException IOException
*/
protected void processSetForegroundColorExt(int paletteIndex) throws IOException {
}
......@@ -555,7 +581,7 @@ public class AnsiOutputStream extends FilterOutputStream {
* @param r red
* @param g green
* @param b blue
* @throws IOException
* @throws IOException IOException
*/
protected void processSetForegroundColorExt(int r, int g, int b) throws IOException {
}
......@@ -563,7 +589,7 @@ public class AnsiOutputStream extends FilterOutputStream {
/**
* process <code>SGR 40-47</code> corresponding to <code>Set background color</code>.
* @param color the background color
* @throws IOException
* @throws IOException IOException
*/
protected void processSetBackgroundColor(int color) throws IOException {
processSetBackgroundColor(color, false);
......@@ -574,7 +600,7 @@ public class AnsiOutputStream extends FilterOutputStream {
* <code>Set background color</code> either in normal mode or high intensity.
* @param color the background color
* @param bright is high intensity?
* @throws IOException
* @throws IOException IOException
*/
protected void processSetBackgroundColor(int color, boolean bright) throws IOException {
}
......@@ -583,7 +609,7 @@ public class AnsiOutputStream extends FilterOutputStream {
* process <code>SGR 48</code> corresponding to <code>extended set background color</code>
* with a palette of 255 colors.
* @param paletteIndex the background color in the palette
* @throws IOException
* @throws IOException IOException
*/
protected void processSetBackgroundColorExt(int paletteIndex) throws IOException {
}
......@@ -594,28 +620,28 @@ public class AnsiOutputStream extends FilterOutputStream {
* @param r red
* @param g green
* @param b blue
* @throws IOException
* @throws IOException IOException
*/
protected void processSetBackgroundColorExt(int r, int g, int b) throws IOException {
}
/**
* process <code>SGR 39</code> corresponding to <code>Default text color (foreground)</code>
* @throws IOException
* @throws IOException IOException
*/
protected void processDefaultTextColor() throws IOException {
}
/**
* process <code>SGR 49</code> corresponding to <code>Default background color</code>
* @throws IOException
* @throws IOException IOException
*/
protected void processDefaultBackgroundColor() throws IOException {
}
/**
* process <code>SGR 0</code> corresponding to <code>Reset / Normal</code>
* @throws IOException
* @throws IOException IOException
*/
protected void processAttributeRest() throws IOException {
}
......@@ -623,9 +649,9 @@ public class AnsiOutputStream extends FilterOutputStream {
/**
* process <code>CSI n ; m H</code> corresponding to <code>CUP – Cursor Position</code> or
* <code>CSI n ; m f</code> corresponding to <code>HVP – Horizontal and Vertical Position</code>
* @param row
* @param col
* @throws IOException
* @param row row
* @param col column
* @throws IOException IOException
*/
protected void processCursorTo(int row, int col) throws IOException {
}
......@@ -633,7 +659,7 @@ public class AnsiOutputStream extends FilterOutputStream {
/**
* process <code>CSI n G</code> corresponding to <code>CHA – Cursor Horizontal Absolute</code>
* @param x the column
* @throws IOException
* @throws IOException IOException
*/
protected void processCursorToColumn(int x) throws IOException {
}
......@@ -641,7 +667,7 @@ public class AnsiOutputStream extends FilterOutputStream {
/**
* process <code>CSI n F</code> corresponding to <code>CPL – Cursor Previous Line</code>
* @param count line count
* @throws IOException
* @throws IOException IOException
*/
protected void processCursorUpLine(int count) throws IOException {
}
......@@ -649,47 +675,47 @@ public class AnsiOutputStream extends FilterOutputStream {
/**
* process <code>CSI n E</code> corresponding to <code>CNL – Cursor Next Line</code>
* @param count line count
* @throws IOException
* @throws IOException IOException
*/
protected void processCursorDownLine(int count) throws IOException {
// Poor mans impl..
for (int i = 0; i < count; i++) {
out.write('\n');
out.write('\n'); // expected diff with AnsiPrintStream.java
}
}
/**
* process <code>CSI n D</code> corresponding to <code>CUB – Cursor Back</code>
* @param count
* @throws IOException
* @param count numer of characters to move left
* @throws IOException IOException
*/
protected void processCursorLeft(int count) throws IOException {
}
/**
* process <code>CSI n C</code> corresponding to <code>CUF – Cursor Forward</code>
* @param count
* @throws IOException
* @param count number of characters to move on
* @throws IOException IOException
*/
protected void processCursorRight(int count) throws IOException {
// Poor mans impl..
for (int i = 0; i < count; i++) {
out.write(' ');
out.write(' '); // expected diff with AnsiPrintStream.java
}
}
/**
* process <code>CSI n B</code> corresponding to <code>CUD – Cursor Down</code>
* @param count
* @throws IOException
* @param count numer of line
* @throws IOException IOException
*/
protected void processCursorDown(int count) throws IOException {
}
/**
* process <code>CSI n A</code> corresponding to <code>CUU – Cursor Up</code>
* @param count
* @throws IOException
* @param count number of lines
* @throws IOException IOException
*/
protected void processCursorUp(int count) throws IOException {
}
......@@ -699,8 +725,7 @@ public class AnsiOutputStream extends FilterOutputStream {
/**
* process <code>OSC 0;text BEL</code> corresponding to <code>Change Window and Icon label</code>
* @param label
* @throws IOException
* @param label window label
*/
protected void processChangeIconNameAndWindowTitle(String label) {
processChangeIconName(label);
......@@ -709,28 +734,41 @@ public class AnsiOutputStream extends FilterOutputStream {
/**
* process <code>OSC 1;text BEL</code> corresponding to <code>Change Icon label</code>
* @param label
* @throws IOException
* @param label icon label name
*/
protected void processChangeIconName(String label) {
}
/**
* process <code>OSC 2;text BEL</code> corresponding to <code>Change Window title</code>
* @param label
* @throws IOException
* @param label window label
*/
protected void processChangeWindowTitle(String label) {
}
/**
* Process unknown <code>OSC</code> command.
* @param command
* @param param
* @param command command
* @param param command param
*/
protected void processUnknownOperatingSystemCommand(int command, String param) {
}
/**
* Process character set sequence.
* @param options set of options
* @return true if the charcter set select command was processed.
*/
private boolean processCharsetSelect(ArrayList<Object> options) {
int set = optionInt(options, 0);
char seq = ((Character) options.get(1)).charValue();
processCharsetSelect(set, seq);
return true;
}
protected void processCharsetSelect(int set, char seq) {
}
private int optionInt(ArrayList<Object> options, int index) {
if (options.size() <= index)
throw new IllegalArgumentException();
......@@ -754,8 +792,8 @@ public class AnsiOutputStream extends FilterOutputStream {
}
@Override
public void close() throws IOException {
write(RESET_CODE);
public void close() throws IOException { // expected diff with AnsiPrintStream.java
write(RESET_CODE); // expected diff with AnsiPrintStream.java
flush();
super.close();
}
......
/*
* Copyright (C) 2009-2017 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.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
/**
* A PrintStream filtering to another PrintStream, without making any assumption about encoding.
*
* @author Hervé Boutemy
* @since 1.17
*/
public class FilterPrintStream extends PrintStream
{
private static final String NEWLINE = System.getProperty("line.separator");
protected final PrintStream ps;
public FilterPrintStream(PrintStream ps)
{
super( new OutputStream() {
@Override
public void write(int b) throws IOException {
throw new RuntimeException("Direct OutputStream use forbidden: must go through delegate PrintStream");
}
});
this.ps = ps;
}
/**
* Filter the content
* @param data character to filter
* @return <code>true</code> if the data is not filtered then has to be printed to delegate PrintStream
*/
protected boolean filter(int data)
{
return true;
}
@Override
public void write(int data)
{
if (filter(data))
{
ps.write(data);
}
}
@Override
public void write(byte[] buf, int off, int len)
{
for (int i = 0; i < len; i++)
{
write(buf[off + i]);
}
}
@Override
public boolean checkError()
{
return super.checkError() || ps.checkError();
}
@Override
public void close()
{
super.close();
ps.close();
}
@Override
public void flush()
{
super.flush();
ps.flush();
}
private void write(char buf[]) {
for (char c : buf)
{
if (filter(c))
{
ps.print(c);
}
}
}
private void write(String s) {
char[] buf = new char[s.length()];
s.getChars(0, s.length(), buf, 0);
write(buf);
}
private void newLine() {
write(NEWLINE);
}
/* Methods that do not terminate lines */
@Override
public void print(boolean b) {
write(b ? "true" : "false");
}
@Override
public void print(char c) {
write(String.valueOf(c));
}
@Override
public void print(int i) {
write(String.valueOf(i));
}
@Override
public void print(long l) {
write(String.valueOf(l));
}
@Override
public void print(float f) {
write(String.valueOf(f));
}
@Override
public void print(double d) {
write(String.valueOf(d));
}
@Override
public void print(char s[]) {
write(s);
}
@Override
public void print(String s) {
if (s == null) {
s = "null";
}
write(s);
}
@Override
public void print(Object obj) {
write(String.valueOf(obj));
}
/* Methods that do terminate lines */
@Override
public void println() {
newLine();
}
@Override
public void println(boolean x) {
synchronized (this) {
print(x);
newLine();
}
}
@Override
public void println(char x) {
synchronized (this) {
print(x);
newLine();
}
}
@Override
public void println(int x) {
synchronized (this) {
print(x);
newLine();
}
}
@Override
public void println(long x) {
synchronized (this) {
print(x);
newLine();
}
}
@Override
public void println(float x) {
synchronized (this) {
print(x);
newLine();
}
}
@Override
public void println(double x) {
synchronized (this) {
print(x);
newLine();
}
}
@Override
public void println(char x[]) {
synchronized (this) {
print(x);
newLine();
}
}
@Override
public void println(String x) {
synchronized (this) {
print(x);
newLine();
}
}
@Override
public void println(Object x) {
String s = String.valueOf(x);
synchronized (this) {
print(s);
newLine();
}
}
}