// 
// Decompiled by Procyon v0.6.0
// 

package org.jline.utils;

import java.io.File;

public class OSUtils
{
    public static final boolean IS_LINUX;
    public static final boolean IS_WINDOWS;
    public static final boolean IS_OSX;
    public static final boolean IS_AIX;
    public static final boolean IS_CYGWIN;
    @Deprecated
    public static final boolean IS_MINGW;
    public static final boolean IS_MSYSTEM;
    public static final boolean IS_WSL;
    public static final boolean IS_WSL1;
    public static final boolean IS_WSL2;
    public static final boolean IS_CONEMU;
    public static String TTY_COMMAND;
    public static String STTY_COMMAND;
    public static String STTY_F_OPTION;
    public static String INFOCMP_COMMAND;
    public static String TEST_COMMAND;
    
    private static boolean isExecutable(final File f) {
        return f.canExecute() && !f.isDirectory();
    }
    
    static {
        IS_LINUX = System.getProperty("os.name").toLowerCase().contains("linux");
        IS_WINDOWS = System.getProperty("os.name").toLowerCase().contains("win");
        IS_OSX = System.getProperty("os.name").toLowerCase().contains("mac");
        IS_AIX = System.getProperty("os.name").toLowerCase().contains("aix");
        IS_CYGWIN = (OSUtils.IS_WINDOWS && System.getenv("PWD") != null && System.getenv("PWD").startsWith("/"));
        IS_MINGW = (OSUtils.IS_WINDOWS && System.getenv("MSYSTEM") != null && System.getenv("MSYSTEM").startsWith("MINGW"));
        IS_MSYSTEM = (OSUtils.IS_WINDOWS && System.getenv("MSYSTEM") != null && (System.getenv("MSYSTEM").startsWith("MINGW") || System.getenv("MSYSTEM").equals("MSYS")));
        IS_WSL = (System.getenv("WSL_DISTRO_NAME") != null);
        IS_WSL1 = (OSUtils.IS_WSL && System.getenv("WSL_INTEROP") == null);
        IS_WSL2 = (OSUtils.IS_WSL && !OSUtils.IS_WSL1);
        IS_CONEMU = (OSUtils.IS_WINDOWS && System.getenv("ConEmuPID") != null);
        final boolean cygwinOrMsys = OSUtils.IS_CYGWIN || OSUtils.IS_MSYSTEM;
        final String suffix = cygwinOrMsys ? ".exe" : "";
        String tty = null;
        String stty = null;
        String sttyfopt = null;
        String infocmp = null;
        String test = null;
        final String path = System.getenv("PATH");
        if (path != null) {
            final String[] split;
            final String[] paths = split = path.split(File.pathSeparator);
            for (final String p : split) {
                final File ttyFile = new File(p, "tty" + suffix);
                if (tty == null && isExecutable(ttyFile)) {
                    tty = ttyFile.getAbsolutePath();
                }
                final File sttyFile = new File(p, "stty" + suffix);
                if (stty == null && isExecutable(sttyFile)) {
                    stty = sttyFile.getAbsolutePath();
                }
                final File infocmpFile = new File(p, "infocmp" + suffix);
                if (infocmp == null && isExecutable(infocmpFile)) {
                    infocmp = infocmpFile.getAbsolutePath();
                }
                final File testFile = new File(p, "test" + suffix);
                if (test == null && isExecutable(testFile)) {
                    test = testFile.getAbsolutePath();
                }
            }
        }
        if (tty == null) {
            tty = "tty" + suffix;
        }
        if (stty == null) {
            stty = "stty" + suffix;
        }
        if (infocmp == null) {
            infocmp = "infocmp" + suffix;
        }
        if (test == null) {
            test = "test" + suffix;
        }
        sttyfopt = (OSUtils.IS_OSX ? "-f" : "-F");
        OSUtils.TTY_COMMAND = tty;
        OSUtils.STTY_COMMAND = stty;
        OSUtils.STTY_F_OPTION = sttyfopt;
        OSUtils.INFOCMP_COMMAND = infocmp;
        OSUtils.TEST_COMMAND = test;
    }
}
