diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 169a1924..891f5f24 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -30,7 +30,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
- java: [ '11', '17' ]
+ java: [ '21' ]
steps:
- uses: actions/checkout@v2
with:
@@ -46,4 +46,4 @@ jobs:
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: mvn verify
- run: mvn test
+ run: mvn verify -Dnosign
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 4e2b2c85..00000000
--- a/Makefile
+++ /dev/null
@@ -1,164 +0,0 @@
-#
-# 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.
-#
-include Makefile.common
-
-.PHONY: all package native native-all deploy crossbuild ducible clean-native
-
-linux-armv6-digest:=@sha256:7bad6ab302af34bdf6634c8c2b02c8dc6ac932c67da9ecc199c549ab405e971e
-linux-x86-digest:=@sha256:7a8fda5ff1bb436ac1f2e7d40043deb630800fce33d123d04779d48f85702dcd
-windows-static-x86-digest:=@sha256:896bd4a43bbc89502904afdc8d00e6f2422f8f35852cc59777d6426bfc8491e8
-windows-static-x64-digest:=@sha256:f159861bc80b29e5dafb223477167bec53ecec6cdacb051d31e90c5823542100
-windows-arm64-digest:=@sha256:f4b3c1a49ec8b53418cef1499dc3f9a54a5570b7a3ecdf42fc8c83eb94b01b7d
-cross-build-digest:=@sha256:8dbaa86462270db93ae1b1b319bdd88d89272faf3a68632daf4fa36b414a326e
-freebsd-crossbuild-digest:=@sha256:cda62697a15d8bdc0bc26e780b1771ee78f12c55e7d5813e62c478af5a747c43
-mcandre-snek-digest:=@sha256:9f84e9fcdf66daafc1f1c3fb772a6c97977714e17800aeac2e3bbe5dc5039dd0
-
-all: package
-
-JANSI_OUT:=target/native-$(OS_NAME)-$(OS_ARCH)
-
-CCFLAGS:= -I$(JANSI_OUT) $(CCFLAGS)
-
-target:
- @test -d target || mkdir target
-
-download-includes: target
- @test -d target/inc || mkdir target/inc
- @test -d target/inc/unix || mkdir target/inc/unix
- @test -d target/inc/windows || mkdir target/inc/windows
- test -f target/inc/jni.h || wget -O target/inc/jni.h https://raw.githubusercontent.com/openjdk/jdk/jdk-11%2B28/src/java.base/share/native/include/jni.h
- test -f target/inc/unix/jni_md.h || wget -O target/inc/unix/jni_md.h https://raw.githubusercontent.com/openjdk/jdk/jdk-11%2B28/src/java.base/unix/native/include/jni_md.h
- test -f target/inc/windows/jni_md.h || wget -O target/inc/windows/jni_md.h https://raw.githubusercontent.com/openjdk/jdk/jdk-11%2B28/src/java.base/windows/native/include/jni_md.h
-
-dockcross: target
- @test -d target/dockcross || mkdir target/dockcross
-
-# This target does not generate the same image digest that the one uploaded
-#crossbuild: target
-# test -d target/crossbuild || git clone https://github.com/multiarch/crossbuild.git target/crossbuild
-# git -C target/crossbuild reset --hard d06cdc31fce0c85ad78408b44794366dafd59554
-# docker build target/crossbuild -t multiarch/crossbuild
-
-ducible: target
- test -d target/ducible || git clone --branch v1.2.2 https://github.com/jasonwhite/ducible.git target/ducible
- make --directory=target/ducible ducible CROSS_PREFIX= CXX=g++ CC=gcc
-
-clean-native:
- rm -rf $(JANSI_OUT)
-
-$(JANSI_OUT)/%.o: src/main/native/%.c
- @mkdir -p $(@D)
- $(info running: $(CC) $(CCFLAGS) -c $< -o $@)
- $(CC) $(CCFLAGS) -c $< -o $@
-
-ifeq ($(OS_NAME), Windows)
-$(JANSI_OUT)/$(LIBNAME): ducible
-endif
-$(JANSI_OUT)/$(LIBNAME): $(JANSI_OUT)/jansi.o $(JANSI_OUT)/jansi_isatty.o $(JANSI_OUT)/jansi_structs.o $(JANSI_OUT)/jansi_ttyname.o
- @mkdir -p $(@D)
- $(CC) $(CCFLAGS) -o $@ $(JANSI_OUT)/jansi.o $(JANSI_OUT)/jansi_isatty.o $(JANSI_OUT)/jansi_structs.o $(JANSI_OUT)/jansi_ttyname.o $(LINKFLAGS)
-ifeq ($(OS_NAME), Windows)
- target/ducible/ducible $(JANSI_OUT)/$(LIBNAME)
-endif
-
-NATIVE_DIR=src/main/resources/org/fusesource/jansi/internal/native/$(OS_NAME)/$(OS_ARCH)
-NATIVE_TARGET_DIR:=target/classes/org/fusesource/jansi/internal/native/$(OS_NAME)/$(OS_ARCH)
-NATIVE_DLL:=$(NATIVE_DIR)/$(LIBNAME)
-
-# For cross-compilation, install docker. See also https://github.com/dockcross/dockcross
-# Disabled linux-armv6 build because of this issue; https://github.com/dockcross/dockcross/issues/190
-native-all: linux-x86 linux-x86_64 linux-arm linux-armv6 linux-armv7 \
- linux-arm64 linux-ppc64 win-x86 win-x86_64 win-arm64 mac-x86 mac-x86_64 mac-arm64 freebsd-x86 freebsd-x86_64
-
-native: $(NATIVE_DLL)
-
-$(NATIVE_DLL): $(JANSI_OUT)/$(LIBNAME)
- @mkdir -p $(@D)
- cp $< $@
- @mkdir -p $(NATIVE_TARGET_DIR)
- cp $< $(NATIVE_TARGET_DIR)/$(LIBNAME)
-
-target/dockcross/dockcross-linux-x86: dockcross
- docker run --rm dockcross/linux-x86$(linux-x86-digest) > target/dockcross/dockcross-linux-x86
- chmod +x target/dockcross/dockcross-linux-x86
-linux-x86: download-includes target/dockcross/dockcross-linux-x86
- target/dockcross/dockcross-linux-x86 bash -c 'make clean-native native OS_NAME=Linux OS_ARCH=x86'
-
-linux-x86_64: download-includes
- docker run -it --rm -v $$PWD:/workdir --user $$(id -u):$$(id -g) \
- -e CROSS_TRIPLE=x86_64-linux-gnu multiarch/crossbuild$(cross-build-digest) make clean-native native OS_NAME=Linux OS_ARCH=x86_64
-
-linux-arm: download-includes
- docker run -it --rm -v $$PWD:/workdir --user $$(id -u):$$(id -g) \
- -e CROSS_TRIPLE=arm-linux-gnueabi multiarch/crossbuild$(cross-build-digest) make clean-native native OS_NAME=Linux OS_ARCH=arm
-
-target/dockcross/dockcross-linux-armv6: dockcross
- docker run --rm dockcross/linux-armv6$(linux-armv6-digest) > target/dockcross/dockcross-linux-armv6
- chmod +x target/dockcross/dockcross-linux-armv6
-linux-armv6: download-includes target/dockcross/dockcross-linux-armv6
- target/dockcross/dockcross-linux-armv6 bash -c 'make clean-native native CROSS_PREFIX=armv6-unknown-linux-gnueabihf- OS_NAME=Linux OS_ARCH=armv6'
-
-linux-armv7: download-includes
- docker run -it --rm -v $$PWD:/workdir --user $$(id -u):$$(id -g) \
- -e CROSS_TRIPLE=arm-linux-gnueabihf multiarch/crossbuild$(cross-build-digest) make clean-native native OS_NAME=Linux OS_ARCH=armv7
-
-linux-arm64: download-includes
- docker run -it --rm -v $$PWD:/workdir --user $$(id -u):$$(id -g) \
- -e CROSS_TRIPLE=aarch64-linux-gnu multiarch/crossbuild$(cross-build-digest) make clean-native native OS_NAME=Linux OS_ARCH=arm64
-
-linux-ppc64: download-includes
- docker run -it --rm -v $$PWD:/workdir --user $$(id -u):$$(id -g) \
- -e CROSS_TRIPLE=powerpc64le-linux-gnu multiarch/crossbuild$(cross-build-digest) make clean-native native OS_NAME=Linux OS_ARCH=ppc64
-
-target/dockcross/dockcross-windows-static-x86: dockcross
- docker run --rm dockcross/windows-static-x86$(windows-static-x86-digest) > target/dockcross/dockcross-windows-static-x86
- chmod +x target/dockcross/dockcross-windows-static-x86
-win-x86: download-includes target/dockcross/dockcross-windows-static-x86
- target/dockcross/dockcross-windows-static-x86 bash -c 'make clean-native native CROSS_PREFIX=i686-w64-mingw32.static- OS_NAME=Windows OS_ARCH=x86'
-
-target/dockcross/dockcross-windows-static-x64: dockcross
- docker run --rm dockcross/windows-static-x64$(windows-static-x64-digest) > target/dockcross/dockcross-windows-static-x64
- chmod +x target/dockcross/dockcross-windows-static-x64
-win-x86_64: download-includes target/dockcross/dockcross-windows-static-x64
- target/dockcross/dockcross-windows-static-x64 bash -c 'make clean-native native CROSS_PREFIX=x86_64-w64-mingw32.static- OS_NAME=Windows OS_ARCH=x86_64'
-
-target/dockcross/dockcross-windows-arm64: dockcross
- docker run --rm dockcross/windows-arm64$(windows-arm64-digest) > target/dockcross/dockcross-windows-arm64
- chmod +x target/dockcross/dockcross-windows-arm64
-win-arm64: download-includes target/dockcross/dockcross-windows-arm64
- target/dockcross/dockcross-windows-arm64 bash -c 'make clean-native native CROSS_PREFIX=aarch64-w64-mingw32- OS_NAME=Windows OS_ARCH=arm64'
-
-mac-x86: download-includes
- docker run -it --rm -v $$PWD:/workdir --user $$(id -u):$$(id -g) \
- -e CROSS_TRIPLE=i386-apple-darwin multiarch/crossbuild$(cross-build-digest) make clean-native native OS_NAME=Mac OS_ARCH=x86
-
-mac-x86_64: download-includes
- docker run -it --rm -v $$PWD:/workdir --user $$(id -u):$$(id -g) \
- -e CROSS_TRIPLE=x86_64-apple-darwin multiarch/crossbuild$(cross-build-digest) make clean-native native OS_NAME=Mac OS_ARCH=x86_64
-
-mac-arm64: download-includes
- docker run -it --rm -v $$PWD:/src --user $$(id -u):$$(id -g) \
- -e TARGET=arm64-apple-darwin mcandre/snek$(mcandre-snek-digest) sh -c "make clean-native native CROSS_PREFIX=arm64-apple-darwin20.4- OS_NAME=Mac OS_ARCH=arm64"
-
-freebsd-x86: download-includes
- docker run -it --rm -v $$PWD:/workdir --user $$(id -u):$$(id -g) \
- empterdose/freebsd-cross-build$(freebsd-crossbuild-digest) make clean-native native CROSS_PREFIX=i386-freebsd9- OS_NAME=FreeBSD OS_ARCH=x86
-
-freebsd-x86_64: download-includes
- docker run -it --rm -v $$PWD:/workdir --user $$(id -u):$$(id -g) \
- empterdose/freebsd-cross-build$(freebsd-crossbuild-digest) make clean-native native CROSS_PREFIX=x86_64-freebsd9- OS_NAME=FreeBSD OS_ARCH=x86_64
-
-#sparcv9:
-# $(MAKE) native OS_NAME=SunOS OS_ARCH=sparcv9
-
diff --git a/Makefile.common b/Makefile.common
deleted file mode 100644
index d67eb0e6..00000000
--- a/Makefile.common
+++ /dev/null
@@ -1,171 +0,0 @@
-#
-# 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.
-#
-
-# os=Default is meant to be generic unix/linux
-
-known_targets := Linux-x86 Linux-x86_64 Linux-arm Linux-armv6 Linux-armv7 Linux-android-arm Linux-ppc64 Mac-x86 Mac-x86_64 Mac-arm64 DragonFly-x86_64 FreeBSD-x86_64 OpenBSD-x86_64 Windows-x86 Windows-x86_64 SunOS-sparcv9 HPUX-ia64_32
-target := $(OS_NAME)-$(OS_ARCH)
-
-ifeq (,$(findstring $(strip $(target)),$(known_targets)))
- target := Default
-endif
-
-# cross-compilation toolchain prefix (e.g. "arm-linux-gnueabi-")
-CROSS_PREFIX :=
-
-Default_CC := $(CROSS_PREFIX)gcc
-Default_STRIP := $(CROSS_PREFIX)strip
-Default_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -fPIC -fvisibility=hidden
-Default_LINKFLAGS := -shared
-Default_LIBNAME := libjansi.so
-Default_JANSI_FLAGS :=
-
-Linux-x86_CC := $(CROSS_PREFIX)gcc
-Linux-x86_STRIP := $(CROSS_PREFIX)strip
-Linux-x86_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -fPIC -m32 -fvisibility=hidden
-Linux-x86_LINKFLAGS := -shared -static-libgcc
-Linux-x86_LIBNAME := libjansi.so
-Linux-x86_JANSI_FLAGS :=
-
-Linux-x86_64_CC := $(CROSS_PREFIX)gcc
-Linux-x86_64_STRIP := $(CROSS_PREFIX)strip
-Linux-x86_64_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -fPIC -m64 -fvisibility=hidden
-Linux-x86_64_LINKFLAGS := -shared -static-libgcc
-Linux-x86_64_LIBNAME := libjansi.so
-Linux-x86_64_JANSI_FLAGS :=
-
-Linux-arm_CC := $(CROSS_PREFIX)gcc
-Linux-arm_STRIP := $(CROSS_PREFIX)strip
-Linux-arm_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -fPIC -mfloat-abi=softfp -mfpu=vfp -fvisibility=hidden
-Linux-arm_LINKFLAGS := -shared -static-libgcc
-Linux-arm_LIBNAME := libjansi.so
-Linux-arm_JANSI_FLAGS :=
-
-Linux-armv6_CC := $(CROSS_PREFIX)gcc
-Linux-armv6_STRIP := $(CROSS_PREFIX)strip
-Linux-armv6_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -mfloat-abi=hard -mfpu=vfp -fPIC -fvisibility=hidden
-Linux-armv6_LINKFLAGS := -shared -static-libgcc
-Linux-armv6_LIBNAME := libjansi.so
-Linux-armv6_JANSI_FLAGS :=
-
-Linux-armv7_CC := $(CROSS_PREFIX)gcc
-Linux-armv7_STRIP := $(CROSS_PREFIX)strip
-Linux-armv7_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -mfloat-abi=hard -mfpu=vfp -fPIC -fvisibility=hidden
-Linux-armv7_LINKFLAGS := -shared -static-libgcc
-Linux-armv7_LIBNAME := libjansi.so
-Linux-armv7_JANSI_FLAGS :=
-
-Linux-arm64_CC := $(CROSS_PREFIX)gcc
-Linux-arm64_STRIP := $(CROSS_PREFIX)strip
-Linux-arm64_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -mfloat-abi=hard -mfpu=vfp -fPIC -fvisibility=hidden
-Linux-arm64_LINKFLAGS := -shared -static-libgcc
-Linux-arm64_LIBNAME := libjansi.so
-Linux-arm64_JANSI_FLAGS :=
-
-Linux-ppc64_CC := $(CROSS_PREFIX)gcc
-Linux-ppc64_STRIP := $(CROSS_PREFIX)strip
-Linux-ppc64_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -fPIC -fvisibility=hidden
-Linux-ppc64_LINKFLAGS := -shared -static-libgcc
-Linux-ppc64_LIBNAME := libjansi.so
-Linux-ppc64_JANSI_FLAGS :=
-
-DragonFly-x86_64_CC := $(CROSS_PREFIX)cc
-DragonFly-x86_64_STRIP := $(CROSS_PREFIX)strip
-DragonFly-x86_64_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -O2 -fPIC -fvisibility=hidden
-DragonFly-x86_64_LINKFLAGS := -shared
-DragonFly-x86_64_LIBNAME := libjansi.so
-DragonFly-x86_64_JANSI_FLAGS :=
-
-FreeBSD-x86_CC := $(CROSS_PREFIX)gcc
-FreeBSD-x86_STRIP := $(CROSS_PREFIX)strip
-FreeBSD-x86_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -fPIC -fvisibility=hidden
-FreeBSD-x86_LINKFLAGS := -shared
-FreeBSD-x86_LIBNAME := libjansi.so
-FreeBSD-x86_JANSI_FLAGS :=
-
-FreeBSD-x86_64_CC := $(CROSS_PREFIX)gcc
-FreeBSD-x86_64_STRIP := $(CROSS_PREFIX)strip
-FreeBSD-x86_64_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -fPIC -fvisibility=hidden
-FreeBSD-x86_64_LINKFLAGS := -shared
-FreeBSD-x86_64_LIBNAME := libjansi.so
-FreeBSD-x86_64_JANSI_FLAGS :=
-
-OpenBSD-x86_64_CC := $(CROSS_PREFIX)gcc
-OpenBSD-x86_64_STRIP := $(CROSS_PREFIX)strip
-OpenBSD-x86_64_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -fPIC -fvisibility=hidden
-OpenBSD-x86_64_LINKFLAGS := -shared
-OpenBSD-x86_64_LIBNAME := libjansi.so
-OpenBSD-x86_64_JANSI_FLAGS :=
-
-SunOS-sparcv9_CC := $(CROSS_PREFIX)gcc
-SunOS-sparcv9_STRIP := $(CROSS_PREFIX)strip
-SunOS-sparcv9_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -O2s -fPIC -m64 -fvisibility=hidden
-SunOS-sparcv9_LINKFLAGS := -shared -static-libgcc
-SunOS-sparcv9_LIBNAME := libjansi.so
-SunOS-sparcv9_JANSI_FLAGS :=
-
-HPUX-ia64_32_CC := cc
-HPUX-ia64_32_STRIP := strip
-HPUX-ia64_32_CCFLAGS := -Itarget/inc -Itarget/inc/unix +Osize +z -Bhidden
-HPUX-ia64_32_LINKFLAGS := -b
-HPUX-ia64_32_LIBNAME := libjansi.so
-HPUX-ia64_32_JANSI_FLAGS :=
-
-Mac-x86_CC := gcc
-Mac-x86_STRIP := strip -x
-Mac-x86_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -fPIC -mmacosx-version-min=10.4 -fvisibility=hidden
-Mac-x86_LINKFLAGS := -dynamiclib
-Mac-x86_LIBNAME := libjansi.jnilib
-Mac-x86_JANSI_FLAGS := -DJANSI_ENABLE_LOCKING_STYLE=0
-
-Mac-x86_64_CC := gcc -arch $(OS_ARCH)
-Mac-x86_64_STRIP := strip -x
-MAC_SDK := /Developer/SDKs/MacOSX10.10.sdk
-ifeq ($(wildcard MAC_SDK),)
- MAC_SDK := /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk
-endif
-Mac-x86_64_CCFLAGS := -I$(MAC_SDK)/System/Library/Frameworks/JavaVM.framework/Headers -Itarget/inc -Itarget/inc/unix -Os -fPIC -mmacosx-version-min=10.6 -fvisibility=hidden
-Mac-x86_64_LINKFLAGS := -dynamiclib
-Mac-x86_64_LIBNAME := libjansi.jnilib
-Mac-x86_64_JANSI_FLAGS :=
-
-Mac-arm64_CC := $(CROSS_PREFIX)clang -v
-Mac-arm64_STRIP := $(CROSS_PREFIX)strip -x
-MAC_SDK := /usr/local/osxcross/SDK/MacOSX11.3.sdk/
-Mac-arm64_CCFLAGS := -I$(MAC_SDK)/System/Library/Frameworks/JavaVM.framework/Headers -Itarget/inc -Itarget/inc/unix -Os -fPIC -mmacosx-version-min=11.0 -fvisibility=hidden
-Mac-arm64_LINKFLAGS := -shared
-Mac-arm64_LIBNAME := libjansi.jnilib
-Mac-arm64_JANSI_FLAGS :=
-
-Windows-x86_CC := $(CROSS_PREFIX)gcc
-Windows-x86_STRIP := $(CROSS_PREFIX)strip
-Windows-x86_CCFLAGS := -D_JNI_IMPLEMENTATION_ -Itarget/inc -Itarget/inc/windows -Os
-Windows-x86_LINKFLAGS := -Wl,--kill-at -shared -static-libgcc
-Windows-x86_LIBNAME := jansi.dll
-Windows-x86_JANSI_FLAGS :=
-
-Windows-x86_64_CC := $(CROSS_PREFIX)gcc
-Windows-x86_64_STRIP := $(CROSS_PREFIX)strip
-Windows-x86_64_CCFLAGS := -D_JNI_IMPLEMENTATION_ -Itarget/inc -Itarget/inc/windows -Os
-Windows-x86_64_LINKFLAGS := -Wl,--kill-at -shared -static-libgcc
-Windows-x86_64_LIBNAME := jansi.dll
-Windows-x86_64_JANSI_FLAGS :=
-
-
-CC := $($(target)_CC)
-STRIP := $($(target)_STRIP)
-CCFLAGS := $($(target)_CCFLAGS)
-LINKFLAGS := $($(target)_LINKFLAGS)
-LIBNAME := $($(target)_LIBNAME)
-CCFLAGS := $(CCFLAGS)
diff --git a/pom.xml b/pom.xml
index 9cf9578f..1bc16e7f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
org.fusesource.jansijansi
- 2.4.1-SNAPSHOT
+ 3.0.0-SNAPSHOTjarJansi
@@ -109,6 +109,23 @@
+
+ org.jline
+ jline-terminal-ffm
+ 3.23.1-SNAPSHOT
+
+
+ org.jline
+ jline-terminal-jni
+ 3.23.1-SNAPSHOT
+
+
+ org.graalvm.sdk
+ nativeimage
+ 23.1.0
+ provided
+ true
+ org.junit.jupiterjunit-jupiter
@@ -160,13 +177,67 @@
+
+ org.apache.maven.plugins
+ maven-enforcer-plugin
+ 3.4.1
+
+
+ enforce-java
+
+ enforce
+
+
+
+
+ 21
+
+
+
+
+
+ org.apache.maven.pluginsmaven-compiler-plugin
- 3.8.1
+ 3.11.0
+ true
+ ${jdkTarget}
+ ${jdkTarget}${jdkTarget}
+
+ -Xlint:-options
+
+
+
+ default-compile
+
+
+ **/ffm/*.java
+
+
+
+
+ jdk-21
+
+ compile
+
+
+ 21
+
+ **/ffm/*.java
+
+
+ --enable-preview
+
+
+
+
+ default-testCompile
+
+ org.apache.felix
@@ -206,12 +277,14 @@
9
+ org.fusesource.jansi.AnsiMainorg.fusesource.jansiorg.fusesource.jansi;
org.fusesource.jansi.io;
+ true
@@ -324,20 +397,6 @@
maven-release-plugin3.0.0-M1
-
- org.apache.maven.plugins
- maven-gpg-plugin
- 1.6
-
-
- sign-artifacts
-
- sign
-
- verify
-
-
- org.sonatype.pluginsnexus-staging-maven-plugin
@@ -351,12 +410,12 @@
com.diffplug.spotlessspotless-maven-plugin
- 2.38.0
+ 2.39.0
- 2.35.0
+ 2.38.0java|javax,org,,\#
@@ -410,4 +469,33 @@
+
+
+ sign
+
+
+ !nosign
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-gpg-plugin
+ 1.6
+
+
+ sign-artifacts
+
+ sign
+
+ verify
+
+
+
+
+
+
+
+
diff --git a/src/main/java/org/fusesource/jansi/Ansi.java b/src/main/java/org/fusesource/jansi/Ansi.java
index c1054742..576d8d53 100644
--- a/src/main/java/org/fusesource/jansi/Ansi.java
+++ b/src/main/java/org/fusesource/jansi/Ansi.java
@@ -149,17 +149,14 @@ public int value() {
}
}
+ @FunctionalInterface
public interface Consumer {
void apply(Ansi ansi);
}
public static final String DISABLE = Ansi.class.getName() + ".disable";
- private static Callable detector = new Callable() {
- public Boolean call() throws Exception {
- return !Boolean.getBoolean(DISABLE);
- }
- };
+ private static Callable detector = () -> !Boolean.getBoolean(DISABLE);
public static void setDetector(final Callable detector) {
if (detector == null) throw new IllegalArgumentException();
@@ -374,7 +371,7 @@ public Ansi reset() {
}
private final StringBuilder builder;
- private final ArrayList attributeOptions = new ArrayList(5);
+ private final ArrayList attributeOptions = new ArrayList<>(5);
public Ansi() {
this(new StringBuilder(80));
@@ -716,19 +713,45 @@ public Ansi scrollDown(final int rows) {
return rows > 0 ? appendEscapeSequence('T', rows) : rows < 0 ? scrollUp(-rows) : this;
}
+ @Deprecated
+ public Ansi restorCursorPosition() {
+ return restoreCursorPosition();
+ }
+
public Ansi saveCursorPosition() {
+ saveCursorPositionSCO();
+ return saveCursorPositionDEC();
+ }
+
+ // SCO command
+ public Ansi saveCursorPositionSCO() {
return appendEscapeSequence('s');
}
- @Deprecated
- public Ansi restorCursorPosition() {
- return appendEscapeSequence('u');
+ // DEC command
+ public Ansi saveCursorPositionDEC() {
+ builder.append(FIRST_ESC_CHAR);
+ builder.append('7');
+ return this;
}
public Ansi restoreCursorPosition() {
+ restoreCursorPositionSCO();
+ return restoreCursorPositionDEC();
+ }
+
+ // SCO command
+ public Ansi restoreCursorPositionSCO() {
return appendEscapeSequence('u');
}
+ // DEC command
+ public Ansi restoreCursorPositionDEC() {
+ builder.append(FIRST_ESC_CHAR);
+ builder.append('8');
+ return this;
+ }
+
public Ansi reset() {
return a(Attribute.RESET);
}
diff --git a/src/main/java/org/fusesource/jansi/AnsiConsole.java b/src/main/java/org/fusesource/jansi/AnsiConsole.java
index 3b7b0032..e7120e23 100644
--- a/src/main/java/org/fusesource/jansi/AnsiConsole.java
+++ b/src/main/java/org/fusesource/jansi/AnsiConsole.java
@@ -24,24 +24,17 @@
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
-import java.util.Locale;
-import org.fusesource.jansi.internal.CLibrary;
-import org.fusesource.jansi.internal.CLibrary.WinSize;
-import org.fusesource.jansi.internal.Kernel32.CONSOLE_SCREEN_BUFFER_INFO;
import org.fusesource.jansi.io.AnsiOutputStream;
import org.fusesource.jansi.io.AnsiProcessor;
import org.fusesource.jansi.io.FastBufferedOutputStream;
-import org.fusesource.jansi.io.WindowsAnsiProcessor;
-
-import static org.fusesource.jansi.internal.CLibrary.ioctl;
-import static org.fusesource.jansi.internal.CLibrary.isatty;
-import static org.fusesource.jansi.internal.Kernel32.GetConsoleMode;
-import static org.fusesource.jansi.internal.Kernel32.GetConsoleScreenBufferInfo;
-import static org.fusesource.jansi.internal.Kernel32.GetStdHandle;
-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.SetConsoleMode;
+import org.jline.terminal.Terminal;
+import org.jline.terminal.TerminalBuilder;
+import org.jline.terminal.impl.DumbTerminal;
+import org.jline.terminal.spi.SystemStream;
+import org.jline.terminal.spi.TerminalExt;
+import org.jline.terminal.spi.TerminalProvider;
+import org.jline.utils.OSUtils;
/**
* Provides consistent access to an ANSI aware console PrintStream or an ANSI codes stripping PrintStream
@@ -167,6 +160,33 @@ public class AnsiConsole {
*/
public static final String JANSI_GRACEFUL = "jansi.graceful";
+ /**
+ * The {@code jansi.providers} system property can be set to control which internal provider
+ * will be used. If this property is not set, the {@code ffm} provider will be used if available,
+ * else the {@code jni} one will be used. If set, this property is interpreted as a comma
+ * separated list of provider names to try in order.
+ */
+ public static final String JANSI_PROVIDERS = "jansi.providers";
+ /**
+ * The name of the {@code jni} provider.
+ */
+ public static final String JANSI_PROVIDER_JNI = "jni";
+ /**
+ * The name of the {@code ffm} provider.
+ */
+ public static final String JANSI_PROVIDER_FFM = "ffm";
+ /**
+ * The name of the {@code native-image} provider.
+ *
This provider uses the
+ * Native Image C API
+ * to call native functions, so it is only available when building to native image.
+ * Additionally, this provider currently does not support Windows.
+ *
Note: This is not the only provider available on Native Image,
+ * and it is usually recommended to use ffm or jni provider.
+ * This provider is mainly used when building static native images linked to musl libc.
+ */
+ public static final String JANSI_PROVIDER_NATIVE_IMAGE = "native-image";
+
/**
* @deprecated this field will be made private in a future release, use {@link #sysOut()} instead
*/
@@ -202,8 +222,7 @@ public static int getTerminalWidth() {
return w;
}
- static final boolean IS_WINDOWS =
- System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("win");
+ static final boolean IS_WINDOWS = OSUtils.IS_WINDOWS;
static final boolean IS_CYGWIN =
IS_WINDOWS && System.getenv("PWD") != null && System.getenv("PWD").startsWith("/");
@@ -223,127 +242,86 @@ public static int getTerminalWidth() {
static {
if (getBoolean(JANSI_EAGER)) {
- initStreams();
+ doInstall();
}
}
- private static boolean initialized;
private static int installed;
- private static int virtualProcessing;
+ static Terminal terminal;
private AnsiConsole() {}
- private static AnsiPrintStream ansiStream(boolean stdout) {
- FileDescriptor descriptor = stdout ? FileDescriptor.out : FileDescriptor.err;
- final OutputStream out = new FastBufferedOutputStream(new FileOutputStream(descriptor));
-
- String enc = System.getProperty(stdout ? "sun.stdout.encoding" : "sun.stderr.encoding");
+ /**
+ * Initialize the out/err ansi-enabled streams
+ */
+ static synchronized void doInstall() {
+ try {
+ if (terminal == null) {
+ TerminalBuilder builder = TerminalBuilder.builder()
+ .system(true)
+ .name("jansi")
+ .providers(System.getProperty(JANSI_PROVIDERS));
+ String graceful = System.getProperty(JANSI_GRACEFUL);
+ if (graceful != null) {
+ builder.dumb(Boolean.parseBoolean(graceful));
+ }
+ terminal = builder.build();
+ out = ansiStream(true);
+ err = ansiStream(false);
+ }
+ } catch (IOException e) {
+ throw new IOError(e);
+ }
+ }
- final boolean isatty;
- boolean isAtty;
- boolean withException;
- // Do not use the CLibrary.STDOUT_FILENO to avoid errors in case
- // the library can not be loaded on unsupported platforms
- final int fd = stdout ? STDOUT_FILENO : STDERR_FILENO;
+ static synchronized void doUninstall() {
try {
- // If we can detect that stdout is not a tty.. then setup
- // to strip the ANSI sequences..
- isAtty = isatty(fd) != 0;
- String term = System.getenv("TERM");
- String emacs = System.getenv("INSIDE_EMACS");
- if (isAtty && "dumb".equals(term) && emacs != null && !emacs.contains("comint")) {
- isAtty = false;
+ if (terminal != null) {
+ terminal.close();
}
- withException = false;
- } 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.
- isAtty = false;
- withException = true;
+ } catch (IOException e) {
+ throw new IOError(e);
+ } finally {
+ terminal = null;
+ out = null;
+ err = null;
}
- isatty = isAtty;
+ }
+ private static AnsiPrintStream ansiStream(boolean stdout) throws IOException {
+ final OutputStream out;
final AnsiOutputStream.WidthSupplier width;
- final AnsiProcessor processor;
+ final AnsiProcessor processor = null;
final AnsiType type;
- final AnsiOutputStream.IoRunnable installer;
- final AnsiOutputStream.IoRunnable uninstaller;
- if (!isatty) {
- processor = null;
- type = withException ? AnsiType.Unsupported : AnsiType.Redirected;
- installer = uninstaller = null;
+ final AnsiOutputStream.IoRunnable installer = null;
+ final AnsiOutputStream.IoRunnable uninstaller = null;
+
+ // TerminalBuilder builder = TerminalBuilder.builder()
+ // .system(true)
+ // .name("jansi")
+ // .providers(System.getProperty(JANSI_PROVIDERS))
+ // .systemOutput(stdout ? TerminalBuilder.SystemOutput.SysOut :
+ // TerminalBuilder.SystemOutput.SysErr);
+ // String graceful = System.getProperty(JANSI_GRACEFUL);
+ // if (graceful != null) {
+ // builder.dumb(Boolean.parseBoolean(graceful));
+ // }
+ // Terminal terminal = builder.build();
+ final TerminalProvider provider = ((TerminalExt) terminal).getProvider();
+ final boolean isatty =
+ provider != null && provider.isSystemStream(stdout ? SystemStream.Output : SystemStream.Error);
+ if (isatty) {
+ out = terminal.output();
+ width = terminal::getWidth;
+ type = terminal instanceof DumbTerminal ? AnsiType.Unsupported : AnsiType.Native;
+ } else {
+ out = new FastBufferedOutputStream(new FileOutputStream(stdout ? FileDescriptor.out : FileDescriptor.err));
width = new AnsiOutputStream.ZeroWidthSupplier();
- } else if (IS_WINDOWS) {
- final long console = GetStdHandle(stdout ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE);
- final int[] mode = new int[1];
- final boolean isConsole = GetConsoleMode(console, mode) != 0;
- if (isConsole && SetConsoleMode(console, mode[0] | ENABLE_VIRTUAL_TERMINAL_PROCESSING) != 0) {
- SetConsoleMode(console, mode[0]); // set it back for now, but we know it works
- processor = null;
- type = AnsiType.VirtualTerminal;
- installer = new AnsiOutputStream.IoRunnable() {
- @Override
- public void run() throws IOException {
- virtualProcessing++;
- SetConsoleMode(console, mode[0] | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
- }
- };
- uninstaller = new AnsiOutputStream.IoRunnable() {
- @Override
- public void run() throws IOException {
- if (--virtualProcessing == 0) {
- SetConsoleMode(console, mode[0]);
- }
- }
- };
- } else if ((IS_CONEMU || IS_CYGWIN || IS_MSYSTEM) && !isConsole) {
- // ANSI-enabled ConEmu, Cygwin or MSYS(2) on Windows...
- processor = null;
- type = AnsiType.Native;
- installer = uninstaller = null;
- } else {
- // On Windows, when no ANSI-capable terminal is used, we know the console does not natively interpret
- // ANSI
- // codes but we can use jansi Kernel32 API for console
- AnsiProcessor proc;
- AnsiType ttype;
- try {
- proc = new WindowsAnsiProcessor(out, console);
- ttype = AnsiType.Emulation;
- } catch (Throwable ignore) {
- // this happens when the stdout is being redirected to a file.
- // Use the AnsiProcessor to strip out the ANSI escape sequences.
- proc = new AnsiProcessor(out);
- ttype = AnsiType.Unsupported;
- }
- processor = proc;
- type = ttype;
- installer = uninstaller = null;
- }
- width = new AnsiOutputStream.WidthSupplier() {
- @Override
- public int getTerminalWidth() {
- CONSOLE_SCREEN_BUFFER_INFO info = new CONSOLE_SCREEN_BUFFER_INFO();
- GetConsoleScreenBufferInfo(console, info);
- return info.windowWidth();
- }
- };
+ type = ((TerminalExt) terminal).getSystemStream() != null ? AnsiType.Redirected : AnsiType.Unsupported;
}
-
- // We must be on some Unix variant...
- else {
- // ANSI-enabled ConEmu, Cygwin or MSYS(2) on Windows...
- processor = null;
- type = AnsiType.Native;
- installer = uninstaller = null;
- width = new AnsiOutputStream.WidthSupplier() {
- @Override
- public int getTerminalWidth() {
- WinSize sz = new WinSize();
- ioctl(fd, CLibrary.TIOCGWINSZ, sz);
- return sz.ws_col;
- }
- };
+ String enc = System.getProperty(stdout ? "stdout.encoding" : "stderr.encoding");
+ if (enc == null) {
+ enc = System.getProperty(stdout ? "sun.stdout.encoding" : "sun.stderr.encoding");
}
AnsiMode mode;
@@ -446,8 +424,7 @@ static boolean getBoolean(String name) {
try {
String val = System.getProperty(name);
result = val.isEmpty() || Boolean.parseBoolean(val);
- } catch (IllegalArgumentException e) {
- } catch (NullPointerException e) {
+ } catch (IllegalArgumentException | NullPointerException ignored) {
}
return result;
}
@@ -461,7 +438,7 @@ static boolean getBoolean(String name) {
* @return a PrintStream which is ANSI aware.
*/
public static AnsiPrintStream out() {
- initStreams();
+ doInstall();
return (AnsiPrintStream) out;
}
@@ -483,7 +460,7 @@ public static PrintStream sysOut() {
* @return a PrintStream which is ANSI aware.
*/
public static AnsiPrintStream err() {
- initStreams();
+ doInstall();
return (AnsiPrintStream) err;
}
@@ -503,13 +480,7 @@ public static PrintStream sysErr() {
*/
public static synchronized void systemInstall() {
if (installed == 0) {
- initStreams();
- try {
- ((AnsiPrintStream) out).install();
- ((AnsiPrintStream) err).install();
- } catch (IOException e) {
- throw new IOError(e);
- }
+ doInstall();
System.setOut(out);
System.setErr(err);
}
@@ -531,26 +502,9 @@ public static synchronized boolean isInstalled() {
public static synchronized void systemUninstall() {
installed--;
if (installed == 0) {
- try {
- ((AnsiPrintStream) out).uninstall();
- ((AnsiPrintStream) err).uninstall();
- } catch (IOException e) {
- throw new IOError(e);
- }
- initialized = false;
+ doUninstall();
System.setOut(system_out);
System.setErr(system_err);
}
}
-
- /**
- * Initialize the out/err ansi-enabled streams
- */
- static synchronized void initStreams() {
- if (!initialized) {
- out = ansiStream(true);
- err = ansiStream(false);
- initialized = true;
- }
- }
}
diff --git a/src/main/java/org/fusesource/jansi/AnsiMain.java b/src/main/java/org/fusesource/jansi/AnsiMain.java
index c2a845d6..89ca722f 100644
--- a/src/main/java/org/fusesource/jansi/AnsiMain.java
+++ b/src/main/java/org/fusesource/jansi/AnsiMain.java
@@ -26,9 +26,8 @@
import java.util.Properties;
import org.fusesource.jansi.Ansi.Attribute;
-import org.fusesource.jansi.internal.CLibrary;
-import org.fusesource.jansi.internal.JansiLoader;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.fusesource.jansi.Ansi.ansi;
/**
@@ -54,30 +53,37 @@ public static void main(String... args) throws IOException {
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", ""));
- boolean loaded = JansiLoader.initialize();
- if (loaded) {
- System.out.println("Jansi native library loaded from " + JansiLoader.getNativeLibraryPath());
- if (JansiLoader.getNativeLibrarySourceUrl() != null) {
- System.out.println(" which was auto-extracted from " + JansiLoader.getNativeLibrarySourceUrl());
- }
- } else {
- String prev = System.getProperty(AnsiConsole.JANSI_GRACEFUL);
- try {
- System.setProperty(AnsiConsole.JANSI_GRACEFUL, "false");
- JansiLoader.initialize();
- } catch (Throwable e) {
- e.printStackTrace(System.out);
- } finally {
- if (prev != null) {
- System.setProperty(AnsiConsole.JANSI_GRACEFUL, prev);
- } else {
- System.clearProperty(AnsiConsole.JANSI_GRACEFUL);
- }
- }
- }
+ System.out.println("jansi.providers= " + System.getProperty(AnsiConsole.JANSI_PROVIDERS, ""));
+ // String provider = ((TerminalExt) AnsiConsole.terminal).getProvider().name();
+ // System.out.println("Selected provider: " + provider);
+ //
+ // if (AnsiConsole.JANSI_PROVIDER_JNI.equals(provider)) {
+ // // 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", ""));
+ // boolean loaded = JansiLoader.initialize();
+ // if (loaded) {
+ // System.out.println("Jansi native library loaded from " + JansiLoader.getNativeLibraryPath());
+ // if (JansiLoader.getNativeLibrarySourceUrl() != null) {
+ // System.out.println(" which was auto-extracted from " +
+ // JansiLoader.getNativeLibrarySourceUrl());
+ // }
+ // } else {
+ // String prev = System.getProperty(AnsiConsole.JANSI_GRACEFUL);
+ // try {
+ // System.setProperty(AnsiConsole.JANSI_GRACEFUL, "false");
+ // JansiLoader.initialize();
+ // } catch (Throwable e) {
+ // e.printStackTrace(System.out);
+ // } finally {
+ // if (prev != null) {
+ // System.setProperty(AnsiConsole.JANSI_GRACEFUL, prev);
+ // } else {
+ // System.clearProperty(AnsiConsole.JANSI_GRACEFUL);
+ // }
+ // }
+ // }
+ // }
System.out.println();
@@ -85,9 +91,14 @@ public static void main(String... args) throws IOException {
+ "os.version= " + System.getProperty("os.version") + ", "
+ "os.arch= " + System.getProperty("os.arch"));
System.out.println("file.encoding= " + System.getProperty("file.encoding"));
+ System.out.println("sun.stdout.encoding= " + System.getProperty("sun.stdout.encoding") + ", "
+ + "sun.stderr.encoding= " + System.getProperty("sun.stderr.encoding"));
+ System.out.println("stdout.encoding= " + System.getProperty("stdout.encoding") + ", " + "stderr.encoding= "
+ + System.getProperty("stderr.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("Console: " + System.console());
System.out.println();
@@ -188,11 +199,34 @@ private static String getJansiVersion() {
}
private static void diagnoseTty(boolean stderr) {
- int fd = stderr ? CLibrary.STDERR_FILENO : CLibrary.STDOUT_FILENO;
- int isatty = CLibrary.LOADED ? CLibrary.isatty(fd) : 0;
-
- System.out.println("isatty(STD" + (stderr ? "ERR" : "OUT") + "_FILENO): " + isatty + ", System."
- + (stderr ? "err" : "out") + " " + ((isatty == 0) ? "is *NOT*" : "is") + " a terminal");
+ // int isatty;
+ // int width;
+ // if (AnsiConsole.IS_WINDOWS) {
+ // long console = AnsiConsoleSupportHolder.getKernel32().getStdHandle(!stderr);
+ // isatty = AnsiConsoleSupportHolder.getKernel32().isTty(console);
+ // if ((AnsiConsole.IS_CONEMU || AnsiConsole.IS_CYGWIN || AnsiConsole.IS_MSYSTEM) && isatty == 0) {
+ // MingwSupport mingw = new MingwSupport();
+ // String name = mingw.getConsoleName(!stderr);
+ // if (name != null && !name.isEmpty()) {
+ // isatty = 1;
+ // width = mingw.getTerminalWidth(name);
+ // } else {
+ // isatty = 0;
+ // width = 0;
+ // }
+ // } else {
+ // width = AnsiConsoleSupportHolder.getKernel32().getTerminalWidth(console);
+ // }
+ // } else {
+ // int fd = stderr ? AnsiConsoleSupport.CLibrary.STDERR_FILENO :
+ // AnsiConsoleSupport.CLibrary.STDOUT_FILENO;
+ // isatty = AnsiConsoleSupportHolder.getCLibrary().isTty(fd);
+ // width = AnsiConsoleSupportHolder.getCLibrary().getTerminalWidth(fd);
+ // }
+ //
+ // System.out.println("isatty(STD" + (stderr ? "ERR" : "OUT") + "_FILENO): " + isatty + ", System."
+ // + (stderr ? "err" : "out") + " " + ((isatty == 0) ? "is *NOT*" : "is") + " a terminal");
+ // System.out.println("width(STD" + (stderr ? "ERR" : "OUT") + "_FILENO): " + width);
}
private static void testAnsi(boolean stderr) {
@@ -274,7 +308,7 @@ private static String getPomPropertiesVersion(String path) throws IOException {
private static void printJansiLogoDemo() throws IOException {
BufferedReader in =
- new BufferedReader(new InputStreamReader(AnsiMain.class.getResourceAsStream("jansi.txt"), "UTF-8"));
+ new BufferedReader(new InputStreamReader(AnsiMain.class.getResourceAsStream("jansi.txt"), UTF_8));
try {
String l;
while ((l = in.readLine()) != null) {
diff --git a/src/main/java/org/fusesource/jansi/WindowsSupport.java b/src/main/java/org/fusesource/jansi/WindowsSupport.java
index 010f527e..d55606de 100644
--- a/src/main/java/org/fusesource/jansi/WindowsSupport.java
+++ b/src/main/java/org/fusesource/jansi/WindowsSupport.java
@@ -15,27 +15,18 @@
*/
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;
+// import org.fusesource.jansi.internal.AnsiConsoleSupportHolder;
public class WindowsSupport {
public static String getLastErrorMessage() {
- int errorCode = GetLastError();
- return getErrorMessage(errorCode);
+ // int errorCode = AnsiConsoleSupportHolder.getKernel32().getLastError();
+ // return getErrorMessage(errorCode);
+ throw new UnsupportedOperationException();
}
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);
- }
+ // return AnsiConsoleSupportHolder.getKernel32().getErrorMessage(errorCode);
+ throw new UnsupportedOperationException();
}
}
diff --git a/src/main/java/org/fusesource/jansi/internal/CLibrary.java b/src/main/java/org/fusesource/jansi/internal/CLibrary.java
deleted file mode 100644
index 2e2285c3..00000000
--- a/src/main/java/org/fusesource/jansi/internal/CLibrary.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Copyright (C) 2009-2023 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.internal;
-
-/**
- * Interface to access some low level POSIX functions, loaded by
- * HawtJNI Runtime
- * as jansi library.
- *
- * @see JansiLoader
- */
-@SuppressWarnings("unused")
-public class CLibrary {
-
- //
- // Initialization
- //
-
- public static final boolean LOADED;
-
- static {
- LOADED = JansiLoader.initialize();
- if (LOADED) {
- init();
- }
- }
-
- private static native void init();
-
- //
- // Constants
- //
-
- public static int STDOUT_FILENO = 1;
-
- public static int STDERR_FILENO = 2;
-
- public static boolean HAVE_ISATTY;
-
- public static boolean HAVE_TTYNAME;
-
- public static int TCSANOW;
- public static int TCSADRAIN;
- public static int TCSAFLUSH;
- public static long TIOCGETA;
- public static long TIOCSETA;
- public static long TIOCGETD;
- public static long TIOCSETD;
- public static long TIOCGWINSZ;
- public static long TIOCSWINSZ;
-
- /**
- * test whether a file descriptor refers to a terminal
- *
- * @param fd file descriptor
- * @return isatty() returns 1 if fd is an open file descriptor referring to a
- * terminal; otherwise 0 is returned, and errno is set to indicate the
- * error
- * @see ISATTY(3) man-page
- * @see ISATTY(3P) man-page
- */
- public static native int isatty(int fd);
-
- public static native String ttyname(int filedes);
-
- /**
- * The openpty() function finds an available pseudoterminal and returns
- * file descriptors for the master and slave in amaster and aslave.
- *
- * @param amaster master return value
- * @param aslave slave return value
- * @param name filename return value
- * @param termios optional pty attributes
- * @param winsize optional size
- * @return 0 on success
- * @see OPENPTY(3) man-page
- */
- public static native int openpty(int[] amaster, int[] aslave, byte[] name, Termios termios, WinSize winsize);
-
- public static native int tcgetattr(int filedes, Termios termios);
-
- public static native int tcsetattr(int filedes, int optional_actions, Termios termios);
-
- /**
- * Control a STREAMS device.
- *
- * @see IOCTL(3P) man-page
- */
- public static native int ioctl(int filedes, long request, int[] params);
-
- public static native int ioctl(int filedes, long request, WinSize params);
-
- /**
- * Window sizes.
- *
- * @see IOCTL_TTY(2) man-page
- */
- public static class WinSize {
-
- static {
- JansiLoader.initialize();
- init();
- }
-
- private static native void init();
-
- public static int SIZEOF;
-
- public short ws_row;
- public short ws_col;
- public short ws_xpixel;
- public short ws_ypixel;
-
- public WinSize() {}
-
- public WinSize(short ws_row, short ws_col) {
- this.ws_row = ws_row;
- this.ws_col = ws_col;
- }
- }
-
- /**
- * termios structure for termios functions, describing a general terminal interface that is
- * provided to control asynchronous communications ports
- *
- * @see TERMIOS(3) man-page
- */
- public static class Termios {
-
- static {
- JansiLoader.initialize();
- init();
- }
-
- private static native void init();
-
- public static int SIZEOF;
-
- public long c_iflag;
- public long c_oflag;
- public long c_cflag;
- public long c_lflag;
- public byte[] c_cc = new byte[32];
- public long c_ispeed;
- public long c_ospeed;
- }
-}
diff --git a/src/main/java/org/fusesource/jansi/internal/JansiLoader.java b/src/main/java/org/fusesource/jansi/internal/JansiLoader.java
deleted file mode 100644
index f705620c..00000000
--- a/src/main/java/org/fusesource/jansi/internal/JansiLoader.java
+++ /dev/null
@@ -1,416 +0,0 @@
-/*
- * Copyright (C) 2009-2023 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.internal;
-
-/*--------------------------------------------------------------------------
- * Copyright 2007 Taro L. Saito
- *
- * 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.
- *--------------------------------------------------------------------------*/
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URL;
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Properties;
-import java.util.Random;
-
-import org.fusesource.jansi.AnsiConsole;
-
-/**
- * Set the system properties, org.jansi.lib.path, org.jansi.lib.name,
- * appropriately so that jansi can find *.dll, *.jnilib and
- * *.so files, according to the current OS (win, linux, mac).
- *
- * The library files are automatically extracted from this project's package
- * (JAR).
- *
- * usage: call {@link #initialize()} before using Jansi.
- */
-public class JansiLoader {
-
- private static boolean loaded = false;
- private static String nativeLibraryPath;
- private static String nativeLibrarySourceUrl;
-
- /**
- * Loads Jansi native library.
- *
- * @return True if jansi native library is successfully loaded; false
- * otherwise.
- */
- public static synchronized boolean initialize() {
- // only cleanup before the first extract
- if (!loaded) {
- Thread cleanup = new Thread(JansiLoader::cleanup, "cleanup");
- cleanup.setPriority(Thread.MIN_PRIORITY);
- cleanup.setDaemon(true);
- cleanup.start();
- }
- try {
- loadJansiNativeLibrary();
- } catch (Exception e) {
- if (!Boolean.parseBoolean(System.getProperty(AnsiConsole.JANSI_GRACEFUL, "true"))) {
- throw new RuntimeException(
- "Unable to load jansi native library. You may want set the `jansi.graceful` system property to true to be able to use Jansi on your platform",
- e);
- }
- }
- return loaded;
- }
-
- public static String getNativeLibraryPath() {
- return nativeLibraryPath;
- }
-
- public static String getNativeLibrarySourceUrl() {
- return nativeLibrarySourceUrl;
- }
-
- private static File getTempDir() {
- return new File(System.getProperty("jansi.tmpdir", System.getProperty("java.io.tmpdir")));
- }
-
- /**
- * Deleted old native libraries e.g. on Windows the DLL file is not removed
- * on VM-Exit (bug #80)
- */
- static void cleanup() {
- String tempFolder = getTempDir().getAbsolutePath();
- File dir = new File(tempFolder);
-
- File[] nativeLibFiles = dir.listFiles(new FilenameFilter() {
- private final String searchPattern = "jansi-" + getVersion();
-
- public boolean accept(File dir, String name) {
- return name.startsWith(searchPattern) && !name.endsWith(".lck");
- }
- });
- if (nativeLibFiles != null) {
- for (File nativeLibFile : nativeLibFiles) {
- File lckFile = new File(nativeLibFile.getAbsolutePath() + ".lck");
- if (!lckFile.exists()) {
- try {
- nativeLibFile.delete();
- } catch (SecurityException e) {
- System.err.println("Failed to delete old native lib" + e.getMessage());
- }
- }
- }
- }
- }
-
- private static int readNBytes(InputStream in, byte[] b) throws IOException {
- int n = 0;
- int len = b.length;
- while (n < len) {
- int count = in.read(b, n, len - n);
- if (count <= 0) break;
- n += count;
- }
- return n;
- }
-
- private static String contentsEquals(InputStream in1, InputStream in2) throws IOException {
- byte[] buffer1 = new byte[8192];
- byte[] buffer2 = new byte[8192];
- int numRead1;
- int numRead2;
- while (true) {
- numRead1 = readNBytes(in1, buffer1);
- numRead2 = readNBytes(in2, buffer2);
- if (numRead1 > 0) {
- if (numRead2 <= 0) {
- return "EOF on second stream but not first";
- }
- if (numRead2 != numRead1) {
- return "Read size different (" + numRead1 + " vs " + numRead2 + ")";
- }
- // Otherwise same number of bytes read
- if (!Arrays.equals(buffer1, buffer2)) {
- return "Content differs";
- }
- // Otherwise same bytes read, so continue ...
- } else {
- // Nothing more in stream 1 ...
- if (numRead2 > 0) {
- return "EOF on first stream but not second";
- } else {
- return null;
- }
- }
- }
- }
-
- /**
- * Extracts and loads the specified library file to the target folder
- *
- * @param libFolderForCurrentOS Library path.
- * @param libraryFileName Library name.
- * @param targetFolder Target folder.
- * @return
- */
- private static boolean extractAndLoadLibraryFile(
- String libFolderForCurrentOS, String libraryFileName, String targetFolder) {
- String nativeLibraryFilePath = libFolderForCurrentOS + "/" + libraryFileName;
- // Include architecture name in temporary filename in order to avoid conflicts
- // when multiple JVMs with different architectures running at the same time
- String uuid = randomUUID();
- String extractedLibFileName = String.format("jansi-%s-%s-%s", getVersion(), uuid, libraryFileName);
- String extractedLckFileName = extractedLibFileName + ".lck";
-
- File extractedLibFile = new File(targetFolder, extractedLibFileName);
- File extractedLckFile = new File(targetFolder, extractedLckFileName);
-
- try {
- // Extract a native library file into the target directory
- try (InputStream in = JansiLoader.class.getResourceAsStream(nativeLibraryFilePath)) {
- if (!extractedLckFile.exists()) {
- new FileOutputStream(extractedLckFile).close();
- }
- try (OutputStream out = new FileOutputStream(extractedLibFile)) {
- copy(in, out);
- }
- } finally {
- // Delete the extracted lib file on JVM exit.
- extractedLibFile.deleteOnExit();
- extractedLckFile.deleteOnExit();
- }
-
- // Set executable (x) flag to enable Java to load the native library
- extractedLibFile.setReadable(true);
- extractedLibFile.setWritable(true);
- extractedLibFile.setExecutable(true);
-
- // Check whether the contents are properly copied from the resource folder
- try (InputStream nativeIn = JansiLoader.class.getResourceAsStream(nativeLibraryFilePath)) {
- try (InputStream extractedLibIn = new FileInputStream(extractedLibFile)) {
- String eq = contentsEquals(nativeIn, extractedLibIn);
- if (eq != null) {
- throw new RuntimeException(String.format(
- "Failed to write a native library file at %s because %s", extractedLibFile, eq));
- }
- }
- }
-
- // Load library
- if (loadNativeLibrary(extractedLibFile)) {
- nativeLibrarySourceUrl =
- JansiLoader.class.getResource(nativeLibraryFilePath).toExternalForm();
- return true;
- }
- } catch (IOException e) {
- System.err.println(e.getMessage());
- }
- return false;
- }
-
- private static String randomUUID() {
- return Long.toHexString(new Random().nextLong());
- }
-
- private static void copy(InputStream in, OutputStream out) throws IOException {
- byte[] buf = new byte[8192];
- int n;
- while ((n = in.read(buf)) > 0) {
- out.write(buf, 0, n);
- }
- }
-
- /**
- * Loads native library using the given path and name of the library.
- *
- * @param libPath Path of the native library.
- * @return True for successfully loading; false otherwise.
- */
- private static boolean loadNativeLibrary(File libPath) {
- if (libPath.exists()) {
- try {
- String path = libPath.getAbsolutePath();
- System.load(path);
- nativeLibraryPath = path;
- return true;
- } catch (UnsatisfiedLinkError e) {
- if (!libPath.canExecute()) {
- // NOTE: this can be tested using something like:
- // docker run --rm --tmpfs /tmp -v $PWD:/jansi openjdk:11 java -jar
- // /jansi/target/jansi-xxx-SNAPSHOT.jar
- System.err.printf(
- "Failed to load native library:%s. The native library file at %s is not executable, "
- + "make sure that the directory is mounted on a partition without the noexec flag, or set the "
- + "jansi.tmpdir system property to point to a proper location. osinfo: %s%n",
- libPath.getName(), libPath, OSInfo.getNativeLibFolderPathForCurrentOS());
- } else {
- System.err.printf(
- "Failed to load native library:%s. osinfo: %s%n",
- libPath.getName(), OSInfo.getNativeLibFolderPathForCurrentOS());
- }
- System.err.println(e);
- return false;
- }
-
- } else {
- return false;
- }
- }
-
- /**
- * Loads jansi library using given path and name of the library.
- *
- * @throws
- */
- private static void loadJansiNativeLibrary() throws Exception {
- if (loaded) {
- return;
- }
-
- List triedPaths = new LinkedList();
-
- // Try loading library from library.jansi.path library path */
- String jansiNativeLibraryPath = System.getProperty("library.jansi.path");
- String jansiNativeLibraryName = System.getProperty("library.jansi.name");
- if (jansiNativeLibraryName == null) {
- jansiNativeLibraryName = System.mapLibraryName("jansi");
- assert jansiNativeLibraryName != null;
- if (jansiNativeLibraryName.endsWith(".dylib")) {
- jansiNativeLibraryName = jansiNativeLibraryName.replace(".dylib", ".jnilib");
- }
- }
-
- if (jansiNativeLibraryPath != null) {
- String withOs = jansiNativeLibraryPath + "/" + OSInfo.getNativeLibFolderPathForCurrentOS();
- if (loadNativeLibrary(new File(withOs, jansiNativeLibraryName))) {
- loaded = true;
- return;
- } else {
- triedPaths.add(withOs);
- }
-
- if (loadNativeLibrary(new File(jansiNativeLibraryPath, jansiNativeLibraryName))) {
- loaded = true;
- return;
- } else {
- triedPaths.add(jansiNativeLibraryPath);
- }
- }
-
- // Load the os-dependent library from the jar file
- String packagePath = JansiLoader.class.getPackage().getName().replace('.', '/');
- jansiNativeLibraryPath =
- String.format("/%s/native/%s", packagePath, OSInfo.getNativeLibFolderPathForCurrentOS());
- boolean hasNativeLib = hasResource(jansiNativeLibraryPath + "/" + jansiNativeLibraryName);
-
- if (hasNativeLib) {
- // temporary library folder
- String tempFolder = getTempDir().getAbsolutePath();
- // Try extracting the library from jar
- if (extractAndLoadLibraryFile(jansiNativeLibraryPath, jansiNativeLibraryName, tempFolder)) {
- loaded = true;
- return;
- } else {
- triedPaths.add(jansiNativeLibraryPath);
- }
- }
-
- // As a last resort try from java.library.path
- String javaLibraryPath = System.getProperty("java.library.path", "");
- for (String ldPath : javaLibraryPath.split(File.pathSeparator)) {
- if (ldPath.isEmpty()) {
- continue;
- }
- if (loadNativeLibrary(new File(ldPath, jansiNativeLibraryName))) {
- loaded = true;
- return;
- } else {
- triedPaths.add(ldPath);
- }
- }
-
- throw new Exception(String.format(
- "No native library found for os.name=%s, os.arch=%s, paths=[%s]",
- OSInfo.getOSName(), OSInfo.getArchName(), join(triedPaths, File.pathSeparator)));
- }
-
- private static boolean hasResource(String path) {
- return JansiLoader.class.getResource(path) != null;
- }
-
- /**
- * @return The major version of the jansi library.
- */
- public static int getMajorVersion() {
- String[] c = getVersion().split("\\.");
- return (c.length > 0) ? Integer.parseInt(c[0]) : 1;
- }
-
- /**
- * @return The minor version of the jansi library.
- */
- public static int getMinorVersion() {
- String[] c = getVersion().split("\\.");
- return (c.length > 1) ? Integer.parseInt(c[1]) : 0;
- }
-
- /**
- * @return The version of the jansi library.
- */
- public static String getVersion() {
-
- URL versionFile = JansiLoader.class.getResource("/org/fusesource/jansi/jansi.properties");
-
- String version = "unknown";
- try {
- if (versionFile != null) {
- Properties versionData = new Properties();
- versionData.load(versionFile.openStream());
- version = versionData.getProperty("version", version);
- version = version.trim().replaceAll("[^0-9.]", "");
- }
- } catch (IOException e) {
- System.err.println(e);
- }
- return version;
- }
-
- private static String join(List list, String separator) {
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- for (String item : list) {
- if (first) first = false;
- else sb.append(separator);
-
- sb.append(item);
- }
- return sb.toString();
- }
-}
diff --git a/src/main/java/org/fusesource/jansi/internal/Kernel32.java b/src/main/java/org/fusesource/jansi/internal/Kernel32.java
deleted file mode 100644
index 1d45de1f..00000000
--- a/src/main/java/org/fusesource/jansi/internal/Kernel32.java
+++ /dev/null
@@ -1,521 +0,0 @@
-/*
- * Copyright (C) 2009-2023 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.internal;
-
-import java.io.IOException;
-
-import org.fusesource.jansi.WindowsSupport;
-
-/**
- * Interface to access Win32 base APIs.
- *
- * @see JansiLoader
- */
-@SuppressWarnings("unused")
-public class Kernel32 {
-
- static {
- if (JansiLoader.initialize()) {
- init();
- }
- }
-
- private static native void init();
-
- public static short FOREGROUND_BLUE;
- public static short FOREGROUND_GREEN;
- public static short FOREGROUND_RED;
- public static short FOREGROUND_INTENSITY;
- public static short BACKGROUND_BLUE;
- public static short BACKGROUND_GREEN;
- public static short BACKGROUND_RED;
- public static short BACKGROUND_INTENSITY;
- public static short COMMON_LVB_LEADING_BYTE;
- public static short COMMON_LVB_TRAILING_BYTE;
- public static short COMMON_LVB_GRID_HORIZONTAL;
- public static short COMMON_LVB_GRID_LVERTICAL;
- public static short COMMON_LVB_GRID_RVERTICAL;
- public static short COMMON_LVB_REVERSE_VIDEO;
- public static short COMMON_LVB_UNDERSCORE;
- public static int FORMAT_MESSAGE_FROM_SYSTEM;
- public static int STD_INPUT_HANDLE;
- public static int STD_OUTPUT_HANDLE;
- public static int STD_ERROR_HANDLE;
- public static int INVALID_HANDLE_VALUE;
-
- public static native long malloc(long size);
-
- public static native void free(long ptr);
-
- /**
- * http://msdn.microsoft.com/en-us/library/ms686311%28VS.85%29.aspx
- */
- public static class SMALL_RECT {
- static {
- JansiLoader.initialize();
- init();
- }
-
- private static native void init();
-
- public static int SIZEOF;
-
- public short left;
- public short top;
- public short right;
- public short bottom;
-
- public short width() {
- return (short) (right - left);
- }
-
- public short height() {
- return (short) (bottom - top);
- }
-
- public SMALL_RECT copy() {
- SMALL_RECT rc = new SMALL_RECT();
- rc.left = left;
- rc.top = top;
- rc.right = right;
- rc.bottom = bottom;
- return rc;
- }
- }
-
- /**
- * see http://msdn.microsoft.com/en-us/library/ms686047%28VS.85%29.aspx
- */
- public static native int SetConsoleTextAttribute(long consoleOutput, short attributes);
-
- public static class COORD {
-
- static {
- JansiLoader.initialize();
- init();
- }
-
- private static native void init();
-
- public static int SIZEOF;
-
- public short x;
- public short y;
-
- public COORD copy() {
- COORD rc = new COORD();
- rc.x = x;
- rc.y = y;
- return rc;
- }
- }
-
- /**
- * http://msdn.microsoft.com/en-us/library/ms682093%28VS.85%29.aspx
- */
- public static class CONSOLE_SCREEN_BUFFER_INFO {
-
- static {
- JansiLoader.initialize();
- init();
- }
-
- private static native void init();
-
- public static int SIZEOF;
-
- public COORD size = new COORD();
- public COORD cursorPosition = new COORD();
- public short attributes;
- public SMALL_RECT window = new SMALL_RECT();
- public COORD maximumWindowSize = new COORD();
-
- public int windowWidth() {
- return window.width() + 1;
- }
-
- public int windowHeight() {
- return window.height() + 1;
- }
- }
-
- // DWORD WINAPI WaitForSingleObject(
- // _In_ HANDLE hHandle,
- // _In_ DWORD dwMilliseconds
- // );
- public static native int WaitForSingleObject(long hHandle, int dwMilliseconds);
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms724211%28VS.85%29.aspx
- */
- public static native int CloseHandle(long handle);
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms679360(VS.85).aspx
- */
- public static native int GetLastError();
-
- public static native int FormatMessageW(
- int flags, long source, int messageId, int languageId, byte[] buffer, int size, long[] args);
-
- /**
- * See: http://msdn.microsoft.com/en-us/library/ms683171%28VS.85%29.aspx
- */
- public static native int GetConsoleScreenBufferInfo(
- long consoleOutput, CONSOLE_SCREEN_BUFFER_INFO consoleScreenBufferInfo);
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms683231%28VS.85%29.aspx
- */
- public static native long GetStdHandle(int stdHandle);
-
- /**
- * http://msdn.microsoft.com/en-us/library/ms686025%28VS.85%29.aspx
- */
- public static native int SetConsoleCursorPosition(long consoleOutput, COORD cursorPosition);
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms682663%28VS.85%29.aspx
- */
- public static native int FillConsoleOutputCharacterW(
- long consoleOutput, char character, int length, COORD writeCoord, int[] numberOfCharsWritten);
-
- /**
- * see: https://msdn.microsoft.com/en-us/library/ms682662%28VS.85%29.aspx
- */
- public static native int FillConsoleOutputAttribute(
- long consoleOutput, short attribute, int length, COORD writeCoord, int[] numberOfAttrsWritten);
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms687401(v=VS.85).aspx
- */
- public static native int WriteConsoleW(
- long consoleOutput, char[] buffer, int numberOfCharsToWrite, int[] numberOfCharsWritten, long reserved);
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms683167%28VS.85%29.aspx
- */
- public static native int GetConsoleMode(long handle, int[] mode);
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms686033%28VS.85%29.aspx
- */
- public static native int SetConsoleMode(long handle, int mode);
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/078sfkak(VS.80).aspx
- */
- public static native int _getch();
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms686050%28VS.85%29.aspx
- *
- * @return 0 if title was set successfully
- */
- public static native int SetConsoleTitle(String title);
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms683169(v=VS.85).aspx
- *
- * @return the current output code page
- */
- public static native int GetConsoleOutputCP();
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms686036(v=VS.85).aspx
- *
- * @return non 0 if code page was set
- */
- public static native int SetConsoleOutputCP(int codePageID);
-
- /**
- * see: https://msdn.microsoft.com/en-us/library/windows/desktop/ms682013(v=vs.85).aspx
- */
- public static class CHAR_INFO {
-
- static {
- JansiLoader.initialize();
- init();
- }
-
- private static native void init();
-
- public static int SIZEOF;
-
- public short attributes;
- public char unicodeChar;
- }
-
- /**
- * see: https://msdn.microsoft.com/en-us/library/windows/desktop/ms685107(v=vs.85).aspx
- */
- public static native int ScrollConsoleScreenBuffer(
- long consoleOutput,
- SMALL_RECT scrollRectangle,
- SMALL_RECT clipRectangle,
- COORD destinationOrigin,
- CHAR_INFO fill);
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms684166(v=VS.85).aspx
- */
- public static class KEY_EVENT_RECORD {
-
- static {
- JansiLoader.initialize();
- init();
- }
-
- private static native void init();
-
- public static int SIZEOF;
- public static int CAPSLOCK_ON;
- public static int NUMLOCK_ON;
- public static int SCROLLLOCK_ON;
- public static int ENHANCED_KEY;
- public static int LEFT_ALT_PRESSED;
- public static int LEFT_CTRL_PRESSED;
- public static int RIGHT_ALT_PRESSED;
- public static int RIGHT_CTRL_PRESSED;
- public static int SHIFT_PRESSED;
-
- public boolean keyDown;
- public short repeatCount;
- public short keyCode;
- public short scanCode;
- public char uchar;
- public int controlKeyState;
-
- public String toString() {
- return "KEY_EVENT_RECORD{" + "keyDown="
- + keyDown + ", repeatCount="
- + repeatCount + ", keyCode="
- + keyCode + ", scanCode="
- + scanCode + ", uchar="
- + uchar + ", controlKeyState="
- + controlKeyState + '}';
- }
- }
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms684239(v=VS.85).aspx
- */
- public static class MOUSE_EVENT_RECORD {
-
- static {
- JansiLoader.initialize();
- init();
- }
-
- private static native void init();
-
- public static int SIZEOF;
- public static int FROM_LEFT_1ST_BUTTON_PRESSED;
- public static int FROM_LEFT_2ND_BUTTON_PRESSED;
- public static int FROM_LEFT_3RD_BUTTON_PRESSED;
- public static int FROM_LEFT_4TH_BUTTON_PRESSED;
- public static int RIGHTMOST_BUTTON_PRESSED;
-
- public static int CAPSLOCK_ON;
- public static int NUMLOCK_ON;
- public static int SCROLLLOCK_ON;
- public static int ENHANCED_KEY;
- public static int LEFT_ALT_PRESSED;
- public static int LEFT_CTRL_PRESSED;
- public static int RIGHT_ALT_PRESSED;
- public static int RIGHT_CTRL_PRESSED;
- public static int SHIFT_PRESSED;
-
- public static int DOUBLE_CLICK;
- public static int MOUSE_HWHEELED;
- public static int MOUSE_MOVED;
- public static int MOUSE_WHEELED;
-
- public COORD mousePosition = new COORD();
- public int buttonState;
- public int controlKeyState;
- public int eventFlags;
-
- public String toString() {
- return "MOUSE_EVENT_RECORD{" + "mousePosition="
- + mousePosition + ", buttonState="
- + buttonState + ", controlKeyState="
- + controlKeyState + ", eventFlags="
- + eventFlags + '}';
- }
- }
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms687093(v=VS.85).aspx
- */
- public static class WINDOW_BUFFER_SIZE_RECORD {
-
- static {
- JansiLoader.initialize();
- init();
- }
-
- private static native void init();
-
- public static int SIZEOF;
-
- public COORD size = new COORD();
-
- public String toString() {
- return "WINDOW_BUFFER_SIZE_RECORD{size=" + size + '}';
- }
- }
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms683149(v=VS.85).aspx
- */
- public static class FOCUS_EVENT_RECORD {
- static {
- JansiLoader.initialize();
- init();
- }
-
- private static native void init();
-
- public static int SIZEOF;
- public boolean setFocus;
- }
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms684213(v=VS.85).aspx
- */
- public static class MENU_EVENT_RECORD {
- static {
- JansiLoader.initialize();
- init();
- }
-
- private static native void init();
-
- public static int SIZEOF;
- public int commandId;
- }
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms683499(v=VS.85).aspx
- */
- public static class INPUT_RECORD {
-
- static {
- JansiLoader.initialize();
- init();
- }
-
- private static native void init();
-
- public static int SIZEOF;
- public static short KEY_EVENT;
- public static short MOUSE_EVENT;
- public static short WINDOW_BUFFER_SIZE_EVENT;
- public static short FOCUS_EVENT;
- public static short MENU_EVENT;
- public short eventType;
- public KEY_EVENT_RECORD keyEvent = new KEY_EVENT_RECORD();
- public MOUSE_EVENT_RECORD mouseEvent = new MOUSE_EVENT_RECORD();
- public WINDOW_BUFFER_SIZE_RECORD windowBufferSizeEvent = new WINDOW_BUFFER_SIZE_RECORD();
- public MENU_EVENT_RECORD menuEvent = new MENU_EVENT_RECORD();
- public FOCUS_EVENT_RECORD focusEvent = new FOCUS_EVENT_RECORD();
-
- public static native void memmove(INPUT_RECORD dest, long src, long size);
- }
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms684961(v=VS.85).aspx
- */
- private static native int ReadConsoleInputW(long handle, long inputRecord, int length, int[] eventsCount);
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms684344(v=VS.85).aspx
- */
- private static native int PeekConsoleInputW(long handle, long inputRecord, int length, int[] eventsCount);
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms683207(v=VS.85).aspx
- */
- public static native int GetNumberOfConsoleInputEvents(long handle, int[] numberOfEvents);
-
- /**
- * see: http://msdn.microsoft.com/en-us/library/ms683147(v=VS.85).aspx
- */
- public static native int FlushConsoleInputBuffer(long handle);
-
- /**
- * Return console input events.
- */
- public static INPUT_RECORD[] readConsoleInputHelper(long handle, int count, boolean peek) throws IOException {
- int[] length = new int[1];
- int res;
- long inputRecordPtr = 0;
- try {
- inputRecordPtr = malloc(INPUT_RECORD.SIZEOF * count);
- if (inputRecordPtr == 0) {
- throw new IOException("cannot allocate memory with JNI");
- }
- res = peek
- ? PeekConsoleInputW(handle, inputRecordPtr, count, length)
- : ReadConsoleInputW(handle, inputRecordPtr, count, length);
- if (res == 0) {
- throw new IOException("ReadConsoleInputW failed: " + WindowsSupport.getLastErrorMessage());
- }
- if (length[0] <= 0) {
- return new INPUT_RECORD[0];
- }
- INPUT_RECORD[] records = new INPUT_RECORD[length[0]];
- for (int i = 0; i < records.length; i++) {
- records[i] = new INPUT_RECORD();
- INPUT_RECORD.memmove(records[i], inputRecordPtr + i * INPUT_RECORD.SIZEOF, INPUT_RECORD.SIZEOF);
- }
- return records;
- } finally {
- if (inputRecordPtr != 0) {
- free(inputRecordPtr);
- }
- }
- }
-
- /**
- * Return console input key events (discard other events).
- *
- * @param count requested number of events
- * @return array possibly of size smaller then count
- */
- public static INPUT_RECORD[] readConsoleKeyInput(long handle, int count, boolean peek) throws IOException {
- while (true) {
- // read events until we have keyboard events, the queue could be full
- // of mouse events.
- INPUT_RECORD[] evts = readConsoleInputHelper(handle, count, peek);
- int keyEvtCount = 0;
- for (INPUT_RECORD evt : evts) {
- if (evt.eventType == INPUT_RECORD.KEY_EVENT) keyEvtCount++;
- }
- if (keyEvtCount > 0) {
- INPUT_RECORD[] res = new INPUT_RECORD[keyEvtCount];
- int i = 0;
- for (INPUT_RECORD evt : evts) {
- if (evt.eventType == INPUT_RECORD.KEY_EVENT) {
- res[i++] = evt;
- }
- }
- return res;
- }
- }
- }
-}
diff --git a/src/main/java/org/fusesource/jansi/internal/OSInfo.java b/src/main/java/org/fusesource/jansi/internal/OSInfo.java
deleted file mode 100644
index 8c9999ca..00000000
--- a/src/main/java/org/fusesource/jansi/internal/OSInfo.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Copyright (C) 2009-2023 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.internal;
-
-/*--------------------------------------------------------------------------
- * Copyright 2008 Taro L. Saito
- *
- * 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.
- *--------------------------------------------------------------------------*/
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Locale;
-
-/**
- * Provides OS name and architecture name.
- *
- */
-public class OSInfo {
-
- public static final String X86 = "x86";
- public static final String X86_64 = "x86_64";
- public static final String IA64_32 = "ia64_32";
- public static final String IA64 = "ia64";
- public static final String PPC = "ppc";
- public static final String PPC64 = "ppc64";
- public static final String ARM64 = "arm64";
-
- private static final HashMap archMapping = new HashMap();
-
- static {
- // x86 mappings
- archMapping.put(X86, X86);
- archMapping.put("i386", X86);
- archMapping.put("i486", X86);
- archMapping.put("i586", X86);
- archMapping.put("i686", X86);
- archMapping.put("pentium", X86);
-
- // x86_64 mappings
- archMapping.put(X86_64, X86_64);
- archMapping.put("amd64", X86_64);
- archMapping.put("em64t", X86_64);
- archMapping.put("universal", X86_64); // Needed for openjdk7 in Mac
-
- // Itenium 64-bit mappings
- archMapping.put(IA64, IA64);
- archMapping.put("ia64w", IA64);
-
- // Itenium 32-bit mappings, usually an HP-UX construct
- archMapping.put(IA64_32, IA64_32);
- archMapping.put("ia64n", IA64_32);
-
- // PowerPC mappings
- archMapping.put(PPC, PPC);
- archMapping.put("power", PPC);
- archMapping.put("powerpc", PPC);
- archMapping.put("power_pc", PPC);
- archMapping.put("power_rs", PPC);
-
- // TODO: PowerPC 64bit mappings
- archMapping.put(PPC64, PPC64);
- archMapping.put("power64", PPC64);
- archMapping.put("powerpc64", PPC64);
- archMapping.put("power_pc64", PPC64);
- archMapping.put("power_rs64", PPC64);
-
- // aarch64 mappings
- archMapping.put("aarch64", ARM64);
- }
-
- public static void main(String[] args) {
- if (args.length >= 1) {
- if ("--os".equals(args[0])) {
- System.out.print(getOSName());
- return;
- } else if ("--arch".equals(args[0])) {
- System.out.print(getArchName());
- return;
- }
- }
-
- System.out.print(getNativeLibFolderPathForCurrentOS());
- }
-
- public static String getNativeLibFolderPathForCurrentOS() {
- return getOSName() + "/" + getArchName();
- }
-
- public static String getOSName() {
- return translateOSNameToFolderName(System.getProperty("os.name"));
- }
-
- public static boolean isAndroid() {
- return System.getProperty("java.runtime.name", "").toLowerCase().contains("android");
- }
-
- public static boolean isAlpine() {
- try {
- Process p = Runtime.getRuntime().exec("cat /etc/os-release | grep ^ID");
- p.waitFor();
-
- InputStream in = p.getInputStream();
- try {
- return readFully(in).toLowerCase().contains("alpine");
- } finally {
- in.close();
- }
-
- } catch (Throwable e) {
- return false;
- }
- }
-
- static String getHardwareName() {
- try {
- Process p = Runtime.getRuntime().exec("uname -m");
- p.waitFor();
-
- InputStream in = p.getInputStream();
- try {
- return readFully(in);
- } finally {
- in.close();
- }
- } catch (Throwable e) {
- System.err.println("Error while running uname -m: " + e.getMessage());
- return "unknown";
- }
- }
-
- private static String readFully(InputStream in) throws IOException {
- int readLen = 0;
- ByteArrayOutputStream b = new ByteArrayOutputStream();
- byte[] buf = new byte[32];
- while ((readLen = in.read(buf, 0, buf.length)) >= 0) {
- b.write(buf, 0, readLen);
- }
- return b.toString();
- }
-
- static String resolveArmArchType() {
- if (System.getProperty("os.name").contains("Linux")) {
- String armType = getHardwareName();
- // armType (uname -m) can be armv5t, armv5te, armv5tej, armv5tejl, armv6, armv7, armv7l, aarch64, i686
- if (armType.startsWith("armv6")) {
- // Raspberry PI
- return "armv6";
- } else if (armType.startsWith("armv7")) {
- // Generic
- return "armv7";
- } else if (armType.startsWith("armv5")) {
- // Use armv5, soft-float ABI
- return "arm";
- } else if (armType.equals("aarch64")) {
- // Use arm64
- return "arm64";
- }
-
- // Java 1.8 introduces a system property to determine armel or armhf
- // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8005545
- String abi = System.getProperty("sun.arch.abi");
- if (abi != null && abi.startsWith("gnueabihf")) {
- return "armv7";
- }
- }
- // Use armv5, soft-float ABI
- return "arm";
- }
-
- public static String getArchName() {
- String osArch = System.getProperty("os.arch");
- // For Android
- if (isAndroid()) {
- return "android-arm";
- }
-
- if (osArch.startsWith("arm")) {
- osArch = resolveArmArchType();
- } else {
- String lc = osArch.toLowerCase(Locale.US);
- if (archMapping.containsKey(lc)) return archMapping.get(lc);
- }
- return translateArchNameToFolderName(osArch);
- }
-
- static String translateOSNameToFolderName(String osName) {
- if (osName.contains("Windows")) {
- return "Windows";
- } else if (osName.contains("Mac") || osName.contains("Darwin")) {
- return "Mac";
- // } else if (isAlpine()) {
- // return "Linux-Alpine";
- } else if (osName.contains("Linux")) {
- return "Linux";
- } else if (osName.contains("AIX")) {
- return "AIX";
- } else {
- return osName.replaceAll("\\W", "");
- }
- }
-
- static String translateArchNameToFolderName(String archName) {
- return archName.replaceAll("\\W", "");
- }
-}
diff --git a/src/main/java/org/fusesource/jansi/io/AnsiOutputStream.java b/src/main/java/org/fusesource/jansi/io/AnsiOutputStream.java
index d925d728..9c45afef 100644
--- a/src/main/java/org/fusesource/jansi/io/AnsiOutputStream.java
+++ b/src/main/java/org/fusesource/jansi/io/AnsiOutputStream.java
@@ -25,6 +25,8 @@
import org.fusesource.jansi.AnsiMode;
import org.fusesource.jansi.AnsiType;
+import static java.nio.charset.StandardCharsets.US_ASCII;
+
/**
* A ANSI print stream extracts ANSI escape codes written to
* an output stream and calls corresponding AnsiProcessor.process* methods.
@@ -38,12 +40,14 @@
*/
public class AnsiOutputStream extends FilterOutputStream {
- public static final byte[] RESET_CODE = "\033[0m".getBytes();
+ public static final byte[] RESET_CODE = "\033[0m".getBytes(US_ASCII);
+ @FunctionalInterface
public interface IoRunnable {
void run() throws IOException;
}
+ @FunctionalInterface
public interface WidthSupplier {
int getTerminalWidth();
}
@@ -79,7 +83,7 @@ public int getTerminalWidth() {
private final byte[] buffer = new byte[MAX_ESCAPE_SEQUENCE_LENGTH];
private int pos = 0;
private int startOfValue;
- private final ArrayList