Skip to content

Commit 279e552

Browse files
authored
Merge pull request #993 from S-Gaertner/master
#991 more robust terminal width detection for international Windows versions
2 parents a0172f1 + 281156a commit 279e552

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/main/java/picocli/CommandLine.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6697,7 +6697,9 @@ public void run() {
66976697
txt += " " + line;
66986698
}
66996699
tracer.debug("getTerminalWidth() parsing output: %s%n", txt);
6700-
Pattern pattern = Pattern.compile(".*olumns(:)?\\s+(\\d+)\\D.*", Pattern.DOTALL);
6700+
Pattern pattern = (Help.Ansi.isWindows() && !Help.Ansi.isPseudoTTY())
6701+
? Pattern.compile(".*?:\\s*(\\d+)\\D.*?:\\s*(\\d+)\\D.*", Pattern.DOTALL)
6702+
: Pattern.compile(".*olumns(:)?\\s+(\\d+)\\D.*", Pattern.DOTALL);
67016703
Matcher matcher = pattern.matcher(txt);
67026704
if (matcher.matches()) {
67036705
size.set(Integer.parseInt(matcher.group(2)));
@@ -6715,7 +6717,7 @@ public void run() {
67156717
do {
67166718
if (size.intValue() >= 0) { break; }
67176719
try { Thread.sleep(25); } catch (InterruptedException ignored) {}
6718-
} while (System.currentTimeMillis() < now + 2000);
6720+
} while (System.currentTimeMillis() < now + 2000 && t.isAlive());
67196721
double duration = (System.nanoTime() - start) / 1000000.0;
67206722
tracer.debug("getTerminalWidth() returning: %s in %,.1fms%n", size, duration);
67216723
return size.intValue();

src/test/java/picocli/HelpTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3619,7 +3619,24 @@ public void testGetTerminalWidthWindows() {
36193619
" Keyboard delay: 1\n" +
36203620
" Code page: 932\n" +
36213621
"\n";
3622-
Pattern pattern = Pattern.compile(".*olumns(:)?\\s+(\\d+)\\D.*", Pattern.DOTALL);
3622+
Pattern pattern = Pattern.compile(".*?:\\s*(\\d+)\\D.*?:\\s*(\\d+)\\D.*", Pattern.DOTALL);
3623+
Matcher matcher = pattern.matcher(sttyResult);
3624+
assertTrue(matcher.matches());
3625+
assertEquals(113, Integer.parseInt(matcher.group(2)));
3626+
}
3627+
3628+
@Test
3629+
public void testGetTerminalWidthWindowsInternational() {
3630+
String sttyResult = "\n" +
3631+
"Status von Gerät CON:\n" +
3632+
"---------------------\n" +
3633+
" Zeilen: 9001\n" +
3634+
" Spalten: 113\n" +
3635+
" Wiederholrate: 31\n" +
3636+
" Verzögerungszeit:1\n" +
3637+
" Codepage: 850\n" +
3638+
"\n";
3639+
Pattern pattern = Pattern.compile(".*?:\\s*(\\d+)\\D.*?:\\s*(\\d+)\\D.*", Pattern.DOTALL);
36233640
Matcher matcher = pattern.matcher(sttyResult);
36243641
assertTrue(matcher.matches());
36253642
assertEquals(113, Integer.parseInt(matcher.group(2)));

0 commit comments

Comments
 (0)