diff --git a/src/Joomla/Application/README.md b/src/Joomla/Application/README.md index d82adc727..361187fd1 100644 --- a/src/Joomla/Application/README.md +++ b/src/Joomla/Application/README.md @@ -173,22 +173,55 @@ You can provide customised implementations these methods by creating the followi * `mockWebSetBody` * `mockWebSetHeader` -## Colors for CLI Applications +## Command Line Applications + +The Joomla Framework provides an application class for making command line applications. + +An example command line application skeleton: + +```php +out('It works'); + } +} + +$app = new MyCli; +$app->execute(); + +``` + +### Colors for CLI Applications It is possible to use colors on an ANSI enabled terminal. ```php -// Green text -$this->out('foo'); +class MyCli extends AbstractCliApplication +{ + protected function doExecute() + { + // Green text + $this->out('foo'); -// Yellow text -$this->out('foo'); + // Yellow text + $this->out('foo'); -// Black text on a cyan background -$this->out('foo'); + // Black text on a cyan background + $this->out('foo'); -// White text on a red background -$this->out('foo'); + // White text on a red background + $this->out('foo'); + } +} ``` You can also create your own styles. @@ -196,9 +229,26 @@ You can also create your own styles. ```php use Joomla\Application\Cli\Colorstyle; -$style = new Colorstyle('yellow', 'red', array('bold', 'blink')); -$this->getOutput()->addStyle('fire', $style); -$this->out('foo'); +class MyCli extends AbstractCliApplication +{ + /** + * Override to initialise the colour styles. + * + * @return void + * + * @since 1.0 + */ + protected function initialise() + { + $style = new Colorstyle('yellow', 'red', array('bold', 'blink')); + $this->getOutput()->addStyle('fire', $style); + } + + protected function doExecute() + { + $this->out('foo'); + } +} ``` @@ -209,14 +259,20 @@ And available options are: bold, underscore, blink and reverse. You can also set these colors and options inside the tagname: ```php -// Green text -$this->out('foo'); +class MyCli extends AbstractCliApplication +{ + protected function doExecute() + { + // Green text + $this->out('foo'); -// Black text on a cyan background -$this->out('foo'); + // Black text on a cyan background + $this->out('foo'); -// Bold text on a yellow background -$this->out('foo'); + // Bold text on a yellow background + $this->out('foo'); + } +} ``` ## Installation via Composer