Last active
August 29, 2015 13:56
-
-
Save trepmal/9234624 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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