Steve Losh avatar Steve Losh committed 7a33972

Fix querySize() on OS X

Comments (0)

Files changed (1)

src/org/lantern/terminal/TerminalStatus.java

             return null;
         
         String stty = (ShellCommand.exec(STTY_PROGRAM, "-F", tty, "-a"));
+        if (stty.equals("")) {
+            // OS X's stty command uses -f instead of -F
+            stty = (ShellCommand.exec(STTY_PROGRAM, "-f", tty, "-a"));
+        }
         String []splittedSTTY = stty.split(";");
         int terminalWidth = -1;
         int terminalHeight = -1;
-        final Pattern columnsPattern = Pattern.compile("columns ([0-9]+)");
-        final Pattern rowsPattern = Pattern.compile("rows ([0-9]+)");
+        final Pattern columnsPattern = Pattern.compile("(?:columns ([0-9]+)|([0-9]+) columns)");
+        final Pattern rowsPattern = Pattern.compile("(?:rows ([0-9]+)|([0-9]+) rows)");
         for(String sttyElement: splittedSTTY) {
             if(terminalHeight >= 0 && terminalWidth >= 0)
                 break;
             final String element = sttyElement.trim();
             final Matcher colMatcher = columnsPattern.matcher(element);
             if(colMatcher.matches()) {
-                terminalWidth = Integer.parseInt(colMatcher.group(1));
+                terminalWidth = Integer.parseInt(
+                    colMatcher.group(1) != null ? colMatcher.group(1) : colMatcher.group(2)
+                );
                 continue;
             }
             
             final Matcher rowMatcher = rowsPattern.matcher(element);
             if(rowMatcher.matches()) {
-                terminalHeight = Integer.parseInt(rowMatcher.group(1));
+                terminalHeight = Integer.parseInt(
+                    rowMatcher.group(1) != null ? rowMatcher.group(1) : rowMatcher.group(2)
+                );
                 continue;
             }
         }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.