Example #1
0
\Tailor\Config::set('styles_dir', path($assets_dir, 'css'));
\Tailor\Config::set('scripts_dir', path($assets_dir, 'js'));
if (arg('b build')) {
    say("\n  \\cwhite,blue(**COMPILING**)\\c");
} else {
    say("\n  \\cwhite,magenta(**WATCHING**)\\c\n  Press \\bwhite(CTRL+C)\\b to exit");
}
say("\n  *From*: {$source_dir}\n    *To*: {$output_dir}\n");
$cache_file = path($target_dir, '.cache');
$cache = explode("\n", read($cache_file)) ?: array();
$timeout = (int) arg('t to') ?: 3;
if ($recreate) {
    require path(__DIR__, 'create_skeleton.php');
} elseif (arg('r reset')) {
    $cache = array();
    \IO\Dir::unfile($output_dir, '*', TRUE);
    is_dir($output_dir) or mkdir($output_dir, 0755, TRUE);
    status('reset');
}
if (arg('b build')) {
    $a = microtime(TRUE);
    $cache = array();
    $timeout = 0;
    require path(__DIR__, 'do_compile.php');
    $diff = round(microtime(TRUE) - $a, 4);
    say("\n  *Done*: {$diff}s\n");
} else {
    \Sauce\Shell\CLI::main(function () use(&$cache, $target_dir, $assets_dir, $source_dir, $output_dir, $timeout) {
        require path(__DIR__, 'do_compile.php');
    });
}
Example #2
0
say("\n  {$prefix}Press \\bwhite(CTRL+C)\\b to exit\n");
$cache = array();
if ($readline = function_exists('readline')) {
    readline_completion_function(function () {
        return array();
    });
}
$callback = $readline ? 'readline' : '\\Sauce\\Shell\\CLI::readln';
\Sauce\Shell\CLI::main(function () use($callback, $readline, &$cache, $warn) {
    $_ = trim(call_user_func($callback, colorize('  > ')));
    if (!$_) {
        return;
    } elseif ($readline && $_ && !in_array($_, $cache)) {
        readline_add_history($_);
        $cache[] = $_;
    }
    $code = "extract(__set());return __set({$_},get_defined_vars());";
    $out = $warn ? (array) @eval($code) : @assert($_);
    if (is_array($out)) {
        foreach ($out as $key => $one) {
            $prefix = '';
            if (is_string($key)) {
                $prefix = "\\clight_gray({$key} )\\c";
            }
            $one = preg_replace('/^/m', colorize("  \\cgreen(>)\\c {$prefix}"), trim(inspect($one)));
            writeln($one);
        }
    } else {
        writeln(colorize(sprintf('  \\c%s(> %s)\\c', $out ? 'green' : 'red', $_)));
    }
});