Exemple #1
0
 function setUp()
 {
     // Reset enable state
     \cli\Colors::enable(null);
     // Empty the cache
     \cli\Colors::clearStringCache();
 }
    /**
     * Draw simple One column table with colored string
     * Output should look like:
     * +-------------+
     * | Test Header |
     * +-------------+
     * | x           |
     * +-------------+
     *
     * where `x` character has green color.
     * At the same time it checks that `green` defined in `cli\Colors` really looks as `green`.
     */
    public function testDrawOneColumnColoredTable()
    {
        Colors::enable(true);
        $headers = array('Test Header');
        $rows = array(array(Colors::colorize('%Gx%n', true)));
        // green `x`
        $x = "x";
        $output = <<<OUT
+-------------+
| Test Header |
+-------------+
| {$x}           |
+-------------+

OUT;
        $this->assertInOutEquals(array($headers, $rows), $output);
    }
Exemple #3
0
 /**
  * Show items in a \cli\Table.
  *
  * @param array $items
  * @param array $fields
  */
 private static function show_table($items, $fields)
 {
     $table = new \cli\Table();
     $enabled = \cli\Colors::shouldColorize();
     if ($enabled) {
         \cli\Colors::disable(true);
     }
     $table->setHeaders($fields);
     foreach ($items as $item) {
         $table->addRow(array_values(\WP_CLI\Utils\pick_fields($item, $fields)));
     }
     foreach ($table->getDisplayLines() as $line) {
         \WP_CLI::line($line);
     }
     if ($enabled) {
         \cli\Colors::enable(true);
     }
 }
 /**
  * Installer process for project based on post install event hook on composer.
  *
  * @param CommandEvent $event The event passed in by Composer.
  *
  * @author Benjamin Carl <*****@*****.**>
  * @return boolean|null TRUE on success, otherwise FALSE (signal for Composer to resolve with error)
  * @access public
  * @static
  */
 public static function postInstall(CommandEvent $event)
 {
     // Detect path to composer.json
     self::setInstallPath(self::retrieveInstallPath());
     // We must include autoloader - funny.
     require_once self::getInstallPath() . DIRECTORY_SEPARATOR . 'vendor/autoload.php';
     // Store extra from composer
     self::setExtra($event->getComposer()->getPackage()->getExtra());
     // Force colors
     \cli\Colors::enable();
     // Process event
     return self::handleEvent($event);
 }
<?php

// Samples. Lines marked with * should be colored in output
// php examples/colors.php
// *  All output is run through \cli\Colors::colorize before display
// *  All output is run through \cli\Colors::colorize before display
// *  All output is run through \cli\Colors::colorize before display
// *  All output is run through \cli\Colors::colorize before display
//    All output is run through \cli\Colors::colorize before display
// *  All output is run through \cli\Colors::colorize before display
// php examples/colors.php | cat
//    All output is run through \cli\Colors::colorize before display
// *  All output is run through \cli\Colors::colorize before display
//    All output is run through \cli\Colors::colorize before display
// *  All output is run through \cli\Colors::colorize before display
//    All output is run through \cli\Colors::colorize before display
//    All output is run through \cli\Colors::colorize before display
require_once 'common.php';
\cli\line('  %C%5All output is run through %Y%6\\cli\\Colors::colorize%C%5 before display%n');
echo \cli\Colors::colorize('  %C%5All output is run through %Y%6\\cli\\Colors::colorize%C%5 before display%n', true) . "\n";
echo \cli\Colors::colorize('  %C%5All output is run through %Y%6\\cli\\Colors::colorize%C%5 before display%n') . "\n";
\cli\Colors::enable();
// Forcefully enable
\cli\line('  %C%5All output is run through %Y%6\\cli\\Colors::colorize%C%5 before display%n');
\cli\Colors::disable();
// Disable forcefully!
\cli\line('  %C%5All output is run through %Y%6\\cli\\Colors::colorize%C%5 before display%n', true);
\cli\Colors::enable(false);
// Enable, but not forcefully
\cli\line('  %C%5All output is run through %Y%6\\cli\\Colors::colorize%C%5 before display%n');
Exemple #6
0
 /**
  * Configures.
  *
  * @param array $configuration The configuration for commands
  *
  * @author Benjamin Carl <*****@*****.**>
  *
  * @return $this Instance for chaining.
  */
 protected function configure(array $configuration)
 {
     // Force colors
     \cli\Colors::enable();
     foreach ($configuration as $key => $values) {
         if ($values['type'] === 'short') {
             $this->getFlags()->{$values['type']}($key, $values['info']);
         } else {
             $this->getFlags()->{$values['type']}($key, $values['value'], $values['info']);
         }
     }
     return $this;
 }
Exemple #7
0
<?php

namespace potrans;

/**
 * @author Roman Ozana <*****@*****.**>
 */
use cli\Arguments;
use cli\Colors;
use cli\progress\Bar;
use Sepia\PoParser;
require_once __DIR__ . '/../vendor/autoload.php';
Colors::enable();
$arguments = new Arguments(compact('strict'));
$arguments->addOption(['apikey', 'k'], ['description' => 'Google Translate API Key']);
$arguments->addOption(['input', 'i'], ['description' => 'Path to input PO file']);
$arguments->addOption(['output', 'o'], ['description' => 'Path to output PO file (default: ./tmp/*.po)']);
$arguments->addOption(['from', 'f'], ['default' => 'en', 'description' => 'Source language (default: en)']);
$arguments->addOption(['to', 't'], ['default' => 'cs', 'description' => 'Target language (default: cs)']);
$arguments->addFlag(['verbose', 'v'], 'Turn on verbose output');
$arguments->addFlag(['help', 'h'], 'Show help');
$arguments->parse();
$apikey = $arguments['apikey'];
$input = $arguments['input'];
$output = $arguments['output'] ? $arguments['output'] : __DIR__ . '/../tmp/' . basename($input);
$from = $arguments['from'] ? $arguments['from'] : 'en';
$to = $arguments['to'] ? $arguments['to'] : 'cs';
$verbose = (bool) $arguments['verbose'];
if ($arguments['help'] || !$apikey || !$input) {
    echo str_repeat('-', 80) . PHP_EOL;
    echo 'PO translator parametters ' . PHP_EOL;
Exemple #8
0
#!/usr/bin/php
<?php 
$loader = (require __DIR__ . "/../vendor/autoload.php");
\cli\Colors::enable();
use InstantWin\Player;
use InstantWin\Distribution\EvenOverTimeDistribution;
use InstantWin\TimePeriod;
$screenCols = exec('tput cols');
for ($tries = 0; $tries < 20; $tries++) {
    $durationInSeconds = 20000;
    $eachDot = ceil($durationInSeconds / ($screenCols - 3));
    /*
    use InstantWin\Distribution\FixedOddsDistribution;
    $dist = new FixedOddsDistribution();
    $dist->setOdds(0.002);
    
    $player = new Player();
    $player->setDistribution($dist);
    $player->setMaxWins(3);
    */
    $dist = new EvenOverTimeDistribution();
    $timePeriod = new TimePeriod();
    $timePeriod->setStartTimestamp(1);
    $timePeriod->setEndTimestamp($durationInSeconds);
    $player = new Player();
    $player->setDistribution($dist);
    $player->setCurWins(0);
    $player->setMaxWins(3);
    $player->setTimePeriod($timePeriod);
    $wins = 0;
    $plays = 0;