pawamoy / failprint

Run a command, print its output only if it fails.
https://pawamoy.github.io/failprint
ISC License
7 stars 1 forks source link

feature: Strip whitespace surrounding output #18

Open dalito opened 2 months ago

dalito commented 2 months ago

Is your feature request related to a problem? Please describe.

When running for example git status as a a duty task the output has too much white space around it. In this case the output ends with three empty lines instead of one.

Describe the solution you'd like

Strip white space around output to achieve more consistent formatting no matter which command is run.

Additional context

This is quite easy to do by adding `|trim' in the jinja template. I modified the pretty fomat to:

{% if success %}<green>✓</green>
{% elif nofail %}<yellow>✗</yellow>
{% else %}<red>✗</red>{% endif %} 
<bold>{{ title or command }}</bold>
{% if failure %} ({{ code }}){% endif %}
{% if failure and output and not quiet %}\n
{{ ('  > ' + command + '\n') if title else '' }}
{{ output|trim|indent(2 * ' ') }}{% endif %}

Maybe you want to do this as default?

:cake: Thanks a lot for making duty! I discovered it today like it more than other command runners I looked at (make, task, just, invoke).

Boost priority

Fund with Polar

pawamoy commented 2 months ago

Thanks for the request and the kind words! Super happy you like duty ^^

The request sounds reasonable. However I'm generally very hesitant with changing output arbitrarily. For all I know, someone wants to keep all the spacing 🤔

But I agree that most of the time there's no point in keeping trailing empty lines. Let me think about it more. Whether we do this by default or not, we can at least have a toggle to enable/disable trimming ^^