From 6adb388dce250940217b4fc47a3713f7b78d1738 Mon Sep 17 00:00:00 2001 From: dantleech Date: Sun, 22 Jun 2014 19:44:20 +0200 Subject: [PATCH 1/2] [POC] Symfony Console formatter --- FSHL/Output/SymfonyConsole.php | 105 +++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 FSHL/Output/SymfonyConsole.php diff --git a/FSHL/Output/SymfonyConsole.php b/FSHL/Output/SymfonyConsole.php new file mode 100644 index 0000000..166e1ba --- /dev/null +++ b/FSHL/Output/SymfonyConsole.php @@ -0,0 +1,105 @@ +getFormatter(); + * + * $colors = array( + * 'html-tag' => 'magenta', + * 'html-tagin' => 'yellow', + * 'html-quote' => null, + * ); + * + * foreach ($colors as $tag => $color) { + * $style = new OutputFormatterStyle($color, null, array()); + * $formatter->setStyle($tag, $style); + * } + * + * @author Daniel Leech + * @license http://fshl.kukulich.cz/#license + */ +class SymfonyConsole implements FSHL\Output +{ + /** + * Last used class. + * + * @var string + */ + private $lastStyle = null; + + /** + * Outputs a template part. + * + * @param string $part + * @param string $class + * @return string + */ + public function template($part, $class) + { + $output = ''; + + if ($this->lastStyle !== $class) { + if (null !== $this->lastStyle) { + $output .= 'lastStyle . '>'; + } + if (null !== $class) { + $output .= '<' . $class . '>'; + } + + $this->lastStyle = $class; + } + + return $output . $part; + } + + /** + * Outputs a keyword. + * + * @param string $part + * @param string $class + * @return string + */ + public function keyword($part, $class) + { + return $output; + $output = ''; + + if ($this->lastStyle !== $class) { + if (null !== $this->lastStyle) { + $output .= 'lastStyle . '>'; + } + if (null !== $class) { + $output .= '<' . $this->lastStyle . '>'; + } + + $this->lastStyle = $class; + } + + return $output . $part; + } +} From 892f95f3cffd3caa081b97613b9a42e4958e32de Mon Sep 17 00:00:00 2001 From: dantleech Date: Tue, 8 Jul 2014 21:52:44 +0200 Subject: [PATCH 2/2] Reformatted to tabs --- FSHL/Output/SymfonyConsole.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/FSHL/Output/SymfonyConsole.php b/FSHL/Output/SymfonyConsole.php index 166e1ba..b850cc5 100644 --- a/FSHL/Output/SymfonyConsole.php +++ b/FSHL/Output/SymfonyConsole.php @@ -65,10 +65,10 @@ public function template($part, $class) if ($this->lastStyle !== $class) { if (null !== $this->lastStyle) { - $output .= 'lastStyle . '>'; + $output .= 'lastStyle . '>'; } if (null !== $class) { - $output .= '<' . $class . '>'; + $output .= '<' . $class . '>'; } $this->lastStyle = $class; @@ -85,16 +85,15 @@ public function template($part, $class) * @return string */ public function keyword($part, $class) - { - return $output; + { $output = ''; if ($this->lastStyle !== $class) { if (null !== $this->lastStyle) { - $output .= 'lastStyle . '>'; + $output .= 'lastStyle . '>'; } if (null !== $class) { - $output .= '<' . $this->lastStyle . '>'; + $output .= '<' . $this->lastStyle . '>'; } $this->lastStyle = $class;