WP_CLI\Loggers

Regular::error_multi_line()publicWP-CLI 1.0

Similar to error( $message ), but outputs $message in a red box.

Method of the class: Regular{}

No Hooks.

Return

null. Nothing.

Usage

$Regular = new Regular();
$Regular->error_multi_line( $message_lines );
$message_lines(array) (required)
Message to write.

Regular::error_multi_line() code WP-CLI 2.8.0-alpha

public function error_multi_line( $message_lines ) {
	// Convert tabs to four spaces, as some shells will output the tabs as variable-length.
	$message_lines = array_map(
		function( $line ) {
			return str_replace( "\t", '    ', $line );
		},
		$message_lines
	);

	$longest = max( array_map( 'strlen', $message_lines ) );

	// Write an empty line before the message.
	$empty_line = Colors::colorize( '%w%1 ' . str_repeat( ' ', $longest ) . ' %n' );
	$this->write( STDERR, "\n\t$empty_line\n" );

	foreach ( $message_lines as $line ) {
		$padding = str_repeat( ' ', $longest - strlen( $line ) );
		$line    = Colors::colorize( "%w%1 $line $padding%n" );
		$this->write( STDERR, "\t$line\n" );
	}

	// Write an empty line after the message.
	$this->write( STDERR, "\t$empty_line\n\n" );
}