コード例 #1
0
ファイル: functions.inc.php プロジェクト: Natolumin/observium
function print_cli_table($table_rows, $table_header = array(), $descr = NULL)
{
    if (!is_array($table_rows)) {
        print_error("print_cli_table() argument {$table_rows} should be an array. Please report this error to developers.");
        return;
    }
    if (OBS_QUIET) {
        return;
    }
    if (!cli_is_piped() || OBS_DEBUG) {
        $count_rows = count($table_rows);
        if ($count_rows == 0) {
            return;
        }
        if (strlen($descr)) {
            print_cli_data($descr, '', 3);
        }
        $table = new \cli\Table();
        $count_header = count($table_header);
        if ($count_header) {
            $table->setHeaders($table_header);
        }
        $table->setRows($table_rows);
        $table->display();
        echo PHP_EOL;
    } else {
        print_cli_data("Notice", "Table output suppressed due to piped output." . PHP_EOL);
    }
}
コード例 #2
0
ファイル: common.inc.php プロジェクト: Natolumin/observium
function print_prompt($text, $default_yes = FALSE)
{
    if (is_cli()) {
        if (cli_is_piped()) {
            // If now not have interactive TTY skip any prompts, return default
            $return = TRUE && $default_yes;
        }
        $question = $default_yes ? 'Y/n' : 'y/N';
        echo trim($text), " [{$question}]: ";
        $handle = fopen('php://stdin', 'r');
        $line = strtolower(trim(fgets($handle, 3)));
        fclose($handle);
        if ($default_yes) {
            $return = $line === 'no' || $line === 'n';
        } else {
            $return = $line === 'yes' || $line === 'y';
        }
    } else {
        // Here placeholder for web prompt
        $return = TRUE && $default_yes;
    }
    return $return;
}