-
Notifications
You must be signed in to change notification settings - Fork 1k
Optionally omit the trailing newline when writing output #5400
Description
Feature Request
- Yes, I reviewed the contribution guidelines.
Describe your use case and the problem you are facing
At times, it's useful to be able to not automatically append newlines to every line being written to STDOUT/STDERR. For example:
$ wp do-something
Preparing to do something
- Doing the first thing...OK
- Doing the second thing...OK
All things have been completed successfully!
While the first or second steps are executing, it would be nice to be able to effectively leave the cursor at the end of the ellipsis (...):
WP_CLI::line('- Doing the first thing...');
// Do the thing.
WP_CLI::line(WP_CLI::colorize('%gOK%n'));Unfortunately, the current logging API will result in something like:
- Doing the first thing...
OK
Describe the solution you'd like
It would be nice if the logging API (even just WP_CLI::log()) had an optional $newline argument, which would default to true, e.g.:
WP_CLI::line('- Doing the first thing...', false);
// Do the thing.
WP_CLI::line(WP_CLI::colorize('%gOK%n'));This would eventually come down to a conditional in WP_CLI\Loggers\Base::_line(), determining whether or not the \n character (which, separately, would probably be better served by PHP_EOL) is appended to the $message.
Since this would be a change to the public-facing API (albeit adding a new, optional argument with no backwards-compatibility breaks), I wanted to propose it first before spending time preparing a PR.