示例#1
0
 function createcfg($type = null)
 {
     $term = \Cherry\Cli\Console::getAdapter();
     if (!$type) {
         fprintf(STDERR, "No such config. Try " . Ansi::setUnderline() . "list-configs" . Ansi::clearUnderline() . "\n");
         return 1;
     }
     $args = func_get_args();
     $type = $args[0];
     $opts = $this->parseOpts(array_slice($args, 1), array('verbose' => '+verbose', 'dest' => 'to:', 'force' => '+force'));
     if ($type) {
         $this->data = new TemplateStrings();
         $this->data->htmlroot = exec('pwd');
         $this->data->environment = 'prodution';
         $tpl = (require CHERRY_LIB . '/share/configs/' . $type . '.php');
         $meta = parse_ini_file(CHERRY_LIB . '/share/configs/' . $type . '.ini', true);
         if (empty($opts['dest'])) {
             $out = $meta['config']['dest'];
         } else {
             $out = $opts['dest'];
         }
         fprintf(STDOUT, "Writing %s...\n", $out);
         if (file_exists($out)) {
             if (empty($opts['force']) || $opts['force'] == 0) {
                 fprintf(STDERR, "Error: File already exists! To replace use +force\n");
                 return 1;
             }
         }
         file_put_contents($out, trim($tpl) . "\n");
     }
 }
示例#2
0
#!/usr/bin/php
<?php 
require_once __DIR__ . "/../../share/include/cherryphp";
use Cherry\Cli\Ansi;
$ca = \Cherry\Cli\Console::getAdapter();
$ca->write(Ansi::pushColor(\Ansi\Color::RED, \Ansi\Color::YELLOW) . "This should be red on yellow and span the entire line" . Ansi::clearToEnd() . Ansi::popColor() . "\n" . "And this should be normal text again.\n" . "There is also " . Ansi::setBold() . "bold" . Ansi::clearBold() . ", " . Ansi::setUnderline() . "underline" . Ansi::clearUnderline() . " and " . Ansi::setReverse() . "reverse" . Ansi::clearReverse() . " text available.\n" . "And take a look at these color bars, pure 256-color ANSI.\n");
for ($m = 0; $m < 32; $m++) {
    $ca->write(\Ansi\Color::color256(null, $m * 8 . ',' . $m * 8 . ',' . $m * 8) . "  ");
}
$ca->write(Ansi::reset() . "\n");
for ($m = 0; $m < 32; $m++) {
    $ca->write(\Ansi\Color::color256(null, '0,' . $m * 8 . ',0') . "  ");
}
$ca->write(Ansi::reset() . "\n");
for ($m = 0; $m < 32; $m++) {
    $ca->write(\Ansi\Color::color256(null, '0,0,' . $m * 8) . "  ");
}
$ca->write(Ansi::reset() . "\n");
for ($m = 0; $m < 32; $m++) {
    $ca->write(\Ansi\Color::color256(null, $m * 8 . ',0,0') . "  ");
}
$ca->write(Ansi::reset() . "\n");
$ca->write(Ansi::color("This is a line in green.\n", "green"));
$ca->write(Ansi::color("And a line in red.\n", "red"));