nunomaduro / laravel-console-task

✅ Laravel Console Task is a output method for Laravel Console Commands.
MIT License
254 stars 21 forks source link

Prints the title of a task before executing the task #5

Closed Namoshek closed 6 years ago

Namoshek commented 6 years ago

This PR changes the way tasks are written to the console. It does not have any impact on style, content or formatting - just on the time, when something is printed.

Before

The task handed to $this->task($title, $task) was executed, after which a line was printed with the $title and the result of the $task function.

After

The title handed to $this->task($title, $task) is now written to the output before the task is executed. As soon as a result of the task is available, it will be attached to the output on the same line. The output format has not changed.

Reasons

For long running tasks, it is quite inconvenient to not know what is going on. With this change, the user will see what task is being executed and that it has not finished yet (indicated by a missing result and, depending on the console, a blinking cursor).

Additional information

I had to change the test cases slightly to match the new function calls of the macro.

nunomaduro commented 6 years ago

@Namoshek Excellent pull request. I really like your proposition. 👏

There is something that I don't like tho: The fact that the cursor is just after the : thing. Giving the impression that the user must introduce an input.

screenshot 2018-02-25 19 46 39

Any ideas on this? 🧐

Namoshek commented 6 years ago

Yeah, I kind of get what you mean. I actually had a look deep into the console system, also in the symfony part, to see if there is a way of repositioning the cursor like you can do in C for example. This would allow us to do a lot of cool stuff, like displaying <Task name>: Loading... and replacing it by <Task name>: ✔ when it finished. But unfortunately, it doesn't seem to be supported by the symfony console.

So the only two suggestions I can come up with are:

Load some long running task...
>>>> and when done
Load some long running task...: ✔

and

Load some long running task
>>>> and when done
Load some long running task: ✔

I kind of prefer the styling of the second approach, but I miss the loading indication of the first one. But as I said, I couldn't find a way to indicate the loading in a dynamic way. Although it might be possible I missed something, to be fair. Because the progress bar is dynamic, depending on the console you run it in.

Edit: When doing some more research about the progress bar stuff, I just came across this part of their code which looks promising and like it utilizes bash specials with ANSI codes... I will give this another shot (but I first have to find out which console on windows supports this stuff to test it 👍).

nunomaduro commented 6 years ago

@Namoshek Wow! That overwrite method looks really promising! Can't wait for your feedback! 🤞

Namoshek commented 6 years ago

It actually works pretty well. I added a fallback ($this->output->isDecorated() is the indicator for escape sequence support) in case the executing shell does not support escape sequences. In this case, it will simply print two lines like so:

Foo: loading...
Foo: ✔

An alternative would be to perform the isDecorated() check before executing the $task, which would allow us to fall back to the current implementation (displaying only one line and only after the task has finished). I guess you should answer what style fits your package more.

Namoshek commented 6 years ago

By the way, I obviously had to extend the test cases quite significantly due to the additional isDecorated() criteria having major impact on the output. I hope that's okay.

nunomaduro commented 6 years ago

@Namoshek Great job! Just test it locally and works like magic! 👏

Thanks for this amazing contribution!

nunomaduro commented 6 years ago

@Namoshek Can you give me your twitter handle?

Namoshek commented 6 years ago

I don't have twitter, sorry. 😅

nunomaduro commented 6 years ago

@Namoshek Ok! I just addressed some credits of your work on Twitter: https://twitter.com/enunomaduro/status/967864228693540865

Namoshek commented 6 years ago

By the way, I need to thank you for the great responsiveness on this PR. That's really something you like to see when you want to get something done!