/lib/Willow/Plugin/Core/Cli.plugin/Willow/Cli/View.php

https://github.com/smarterwebdev/php-willow · PHP · 147 lines · 83 code · 21 blank · 43 comment · 4 complexity · 8fd4f96f513d19b37dcfdf0c2de70cbb MD5 · raw file

  1. <?php
  2. /* $Id$ */
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4. /**
  5. * ...
  6. */
  7. abstract class Willow_Cli_View extends Willow_View_Abstract
  8. {
  9. /**
  10. * Constructor
  11. */
  12. public function __construct(Willow_Request_Interface $request)
  13. {
  14. $this->_request = $request;
  15. /**
  16. * @todo
  17. */
  18. $this->_plexus = new Willow_Plexus();
  19. }
  20. /**
  21. * Style CLI output
  22. */
  23. protected $_styles = array(
  24. 'off' => "\033[0m",
  25. 'bold' => "\033[1m",
  26. 'b' => "\033[1m",
  27. 'underline' => "\033[4m",
  28. 'u' => "\033[4m",
  29. // foreground colors
  30. 'black' => "\033[30m",
  31. 'red' => "\033[31m",
  32. 'green' => "\033[32m",
  33. 'yellow' => "\033[33m",
  34. 'blue' => "\033[34m",
  35. 'magenta' => "\033[35m",
  36. 'cyan' => "\033[36m",
  37. 'white' => "\033[37m",
  38. // background colors
  39. 'blackbg' => "\033[40m",
  40. 'redbg' => "\033[41m",
  41. 'greenbg' => "\033[42m",
  42. 'yellowbg' => "\033[43m",
  43. 'bluebg' => "\033[44m",
  44. 'magentabg' => "\033[45m",
  45. 'cyanbg' => "\033[46m",
  46. 'whitebg' => "\033[47m",
  47. );
  48. /**
  49. * ...
  50. */
  51. public function update($notification)
  52. {
  53. if (method_exists($this, $notification))
  54. {
  55. $args = array();
  56. if (func_num_args() > 1)
  57. {
  58. $args = func_get_args();
  59. array_shift($args);
  60. }
  61. call_user_func_array(array($this, $notification), $args);
  62. }
  63. }
  64. /**
  65. * Send output to screen/console/log
  66. */
  67. public function out($message = '', $resetAfter = true)
  68. {
  69. if ($resetAfter === true)
  70. {
  71. $message .= '[off]' . NL;
  72. }
  73. echo preg_replace_callback('/\[(\w+)\]/', array($this, '_formatOutputFromPcre'), $message);
  74. }
  75. /**
  76. * ...
  77. */
  78. public function error($message)
  79. {
  80. $this->out("[red][bold]ERROR: $message");
  81. }
  82. /**
  83. * ...
  84. */
  85. public function success($message)
  86. {
  87. $this->out("[green][bold]$message");
  88. }
  89. /**
  90. * Clear the screen
  91. */
  92. public function clear()
  93. {
  94. echo "\033[1;1H\033[2J";
  95. }
  96. /**
  97. * Sound a beep
  98. */
  99. public function beep()
  100. {
  101. echo "\007";
  102. }
  103. /**
  104. * ...
  105. */
  106. protected function _formatOutputFromPcre($matches)
  107. {
  108. if (isset($this->_styles[$matches[1]]))
  109. {
  110. return $this->_styles[$matches[1]];
  111. }
  112. return $matches[0];
  113. }
  114. /**
  115. * ...
  116. */
  117. public function preGenerate()
  118. {
  119. }
  120. /**
  121. * ...
  122. */
  123. public function generate()
  124. {
  125. }
  126. }