Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console Clear - Symfony Console Component

I'm writing a console app using Symfony 2 Console Component, and I want to run a console clear command before (or as) the first line of my app.

I have done some research and am struggling to find if this is possible.

like image 950
NickOS Avatar asked Aug 27 '15 03:08

NickOS


People also ask

How to clear Symfony cache?

To clear the cache you can use the bin/console cache:pool:clear [pool] command. That will remove all the entries from your storage and you will have to recalculate all the values. You can also group your pools into "cache clearers".

What is Symfony Console component?

The Console component eases the creation of beautiful and testable command line interfaces. The Console component allows you to create command-line commands. Your console commands can be used for any recurring task, such as cronjobs, imports, or other batch jobs.

What is bin console in Symfony?

The Symfony framework provides lots of commands through the bin/console script (e.g. the well-known bin/console cache:clear command). These commands are created with the Console component. You can also use it to create your own commands.


1 Answers

I have been looking for similar functionality. There is nothing built-in to the symfony console that can clear the screen as far as I can tell, but you can still achieve the clear behavior by using the escape code for resetting the terminal like so:

$output->write(sprintf("\033\143"));

See the post "Clear the Ubuntu bash screen for real" and "What commands can I use to reset and clear my terminal?" for a more extensive explanation of the codes, and this symfony console pull request, where I got the code from, that attempted to emulate the clear functionality.

like image 77
Onema Avatar answered Oct 01 '22 10:10

Onema