Skip to content

Instantly share code, notes, and snippets.

@trepmal
Last active August 29, 2015 13:56
Show Gist options
  • Save trepmal/9234624 to your computer and use it in GitHub Desktop.
Save trepmal/9234624 to your computer and use it in GitHub Desktop.
<?php
# this should be included in your command's class
/**
* Create a bar that spans with width of the console
*
* ## OPTIONS
*
* [<character>]
* : The character(s) to make the bar with. Default =
*
* [--c=<c>]
* : Color for bar. Default %p
*
*
* ## EXAMPLES
*
* wp <command> bar
*
* wp <command> bar '-~' --c='%r'
*
* wp <command> bar '+-' --c='%r%3'
*/
function bar( $args = array(), $assoc_args = array() ) {
$char = isset( $args[0] ) ? $args[0] : '=';
$cols = \cli\Shell::columns();
$line = substr( str_repeat($char, $cols), 0, $cols );
if ( ! isset( $assoc_args['c'] ) ) {
$color = '%p'; // https://github.com/jlogsdon/php-cli-tools/blob/master/lib/cli/Colors.php#L113
} else {
$color = $assoc_args['c'];
$color = '%'. trim( $color, '%' );
}
WP_CLI::line( WP_CLI::colorize( $color . $line .'%n' ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment