Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into stty
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo committed Oct 4, 2023
2 parents b1351c5 + 9d60bc5 commit 4264b64
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
43 changes: 29 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -387,20 +387,6 @@
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<goals>
<goal>sign</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
Expand Down Expand Up @@ -473,4 +459,33 @@
</extensions>
</build>

<profiles>
<profile>
<id>sign</id>
<activation>
<property>
<name>!nosign</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<goals>
<goal>sign</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
1 change: 1 addition & 0 deletions src/main/java/org/fusesource/jansi/AnsiMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public static void main(String... args) throws IOException {
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();

Expand Down
35 changes: 20 additions & 15 deletions src/main/native/jansi_isatty.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ JNIEXPORT jint JNICALL CLibrary_NATIVE(isatty)

/* check if fd is a pipe */
HANDLE h = (HANDLE) _get_osfhandle(arg0);
DWORD t = GetFileType(h);
if (t == FILE_TYPE_CHAR) {
DWORD t = h != NULL ? GetFileType(h) : 0;
if (h != NULL && t == FILE_TYPE_CHAR) {
// check that this is a real tty because the /dev/null
// and /dev/zero streams are also of type FILE_TYPE_CHAR
rc = GetConsoleMode(h, &mode) != 0;
Expand All @@ -84,20 +84,25 @@ JNIEXPORT jint JNICALL CLibrary_NATIVE(isatty)
else {

name = nameinfo->Name.Buffer;
name[nameinfo->Name.Length / 2] = 0;

//fprintf( stderr, "Standard stream %d: pipe name: %S\n", arg0, name);

/*
* Check if this could be a MSYS2 pty pipe ('msys-XXXX-ptyN-XX')
* or a cygwin pty pipe ('cygwin-XXXX-ptyN-XX')
*/
if ((wcsstr(name, L"msys-") || wcsstr(name, L"cygwin-")) && wcsstr(name, L"-pty")) {
rc = 1;
} else {
// This is definitely not a tty
rc = 0;
if (name == NULL) {
rc = 0;
}
else {
name[nameinfo->Name.Length / 2] = 0;

//fprintf( stderr, "Standard stream %d: pipe name: %S\n", arg0, name);

/*
* Check if this could be a MSYS2 pty pipe ('msys-XXXX-ptyN-XX')
* or a cygwin pty pipe ('cygwin-XXXX-ptyN-XX')
*/
if ((wcsstr(name, L"msys-") || wcsstr(name, L"cygwin-")) && wcsstr(name, L"-pty")) {
rc = 1;
} else {
// This is definitely not a tty
rc = 0;
}
}
}
}
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
36 changes: 36 additions & 0 deletions src/test/java/org/fusesource/jansi/AnsiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@
*/
package org.fusesource.jansi;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.fusesource.jansi.Ansi.Color;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

Expand Down Expand Up @@ -165,6 +173,34 @@ public void testColorDisabled() {
}
}

@Test
@EnabledOnOs(OS.WINDOWS)
@Disabled("Does not really fail: launch `javaw -jar jansi-xxx.jar` directly instead")
public void testAnsiMainWithNoConsole() throws Exception {
Path javaHome = Paths.get(System.getProperty("java.home"));
Path java = javaHome.resolve("bin\\javaw.exe");
String cp = System.getProperty("java.class.path");

Process process = new ProcessBuilder()
.command(java.toString(), "-cp", cp, AnsiMain.class.getName())
.start();

ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (InputStream in = process.getInputStream()) {
byte[] buffer = new byte[8192];
while (true) {
int nb = in.read(buffer);
if (nb > 0) {
baos.write(buffer, 0, nb);
} else {
break;
}
}
}

assertTrue(baos.toString().contains("test on System.out"), baos.toString());
}

private static void assertAnsi(String expected, Ansi actual) {
assertEquals(expected.replace("ESC", "\033"), actual.toString());
}
Expand Down

0 comments on commit 4264b64

Please sign in to comment.