001package org.jdrupes.builder.core.progessui;
002
003import java.io.IOException;
004
005public class Terminal {
006    private int lines;
007    private int cols;
008    final boolean supportsAnsi;
009
010    @SuppressWarnings("PMD.ConstructorCallsOverridableMethod")
011    Terminal() {
012        this.supportsAnsi
013            = System.console() != null && System.getenv("TERM") != null
014                && !"dumb".equals(System.getenv("TERM"));
015        refreshSize();
016    }
017
018    public int lines() {
019        return lines;
020    }
021
022    public int columns() {
023        return cols;
024    }
025
026    void refreshSize() {
027        this.lines = readEnvInt("LINES", 24);
028        this.cols = readEnvInt("COLUMNS", 80);
029    }
030
031    private int readEnvInt(String key, int def) {
032        try {
033            return Integer.parseInt(System.getenv(key));
034        } catch (NumberFormatException e) {
035            return def;
036        }
037    }
038}