package net.rdrei.android.buildtimetracker.reporters

import groovy.transform.Memoized

/**
 * Singleton info class for determining the width of the terminal we run in.
 */
class TerminalInfo {
    @Memoized
    public int getWidth(int fallback) {
        def cols = System.getenv("COLUMNS")
        if (cols != null) {
            return Integer.parseInt(cols, 10)
        }

        try {
            def res = Integer.parseInt("tput cols".execute().text.trim())
        } catch (Exception ignored) {
            fallback
        }
    }
}

package net.rdrei.android.buildtimetracker.reporters

import groovy.transform.Memoized

/**
 * Singleton info class for determining the width of the terminal we run in.
 */
class TerminalInfo {
    @Memoized
    public int getWidth(int fallback) {
        // Start by trying to get the `COLUMNS` env variable, which is swallowed by Gradle most of the time.
        def cols = System.getenv("COLUMNS")
        if (cols != null) {
            return Integer.parseInt(cols, 10)
        }

        // Totally unportable way of detecting the terminal width on POSIX and OS X.
        try {
            Process p = Runtime.getRuntime().exec([ "bash", "-c", "tput cols 2> /dev/tty" ] as String[])
            p.waitFor()
            def reader = new BufferedReader(new InputStreamReader(p.getInputStream()))
            Integer.valueOf(reader.readLine().trim())
        } catch (IOException ignored) {
            fallback
        }
    }
}

Add working columns detection for Linux and Mac
Add working columns detection for Linux and Mac
