1<?php 2/** 3 * Zend Framework (http://framework.zend.com/) 4 * 5 * @link http://github.com/zendframework/zf2 for the canonical source repository 6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 7 * @license http://framework.zend.com/license/new-bsd New BSD License 8 */ 9 10namespace Zend\Console\Adapter; 11 12use Zend\Console\Charset\CharsetInterface; 13 14interface AdapterInterface 15{ 16 const LINE_NONE = 1; 17 const LINE_SINGLE = 2; 18 const LINE_DOUBLE = 3; 19 const LINE_BLOCK = 4; 20 const FILL_NONE = 0; 21 const FILL_SHADE_LIGHT = 1; 22 const FILL_SHADE_MEDIUM = 2; 23 const FILL_SHADE_DARK = 3; 24 const FILL_BLOCK = 10; 25 26 /** 27 * Write a chunk of text to console. 28 * 29 * @param string $text 30 * @param null|int $color 31 * @param null|int $bgColor 32 * @return void 33 */ 34 public function write($text, $color = null, $bgColor = null); 35 36 /** 37 * Alias for write() 38 * 39 * @param string $text 40 * @param null|int $color 41 * @param null|int $bgColor 42 * @return void 43 */ 44 public function writeText($text, $color = null, $bgColor = null); 45 46 /** 47 * Write a single line of text to console and advance cursor to the next line. 48 * If the text is longer than console width it will be truncated. 49 * 50 * @param string $text 51 * @param null|int $color 52 * @param null|int $bgColor 53 * @return void 54 */ 55 public function writeLine($text = "", $color = null, $bgColor = null); 56 57 /** 58 * Write a piece of text at the coordinates of $x and $y 59 * 60 * @param string $text Text to write 61 * @param int $x Console X coordinate (column) 62 * @param int $y Console Y coordinate (row) 63 * @param null|int $color 64 * @param null|int $bgColor 65 * @return void 66 */ 67 public function writeAt($text, $x, $y, $color = null, $bgColor = null); 68 69 /** 70 * Write a box at the specified coordinates. 71 * If X or Y coordinate value is negative, it will be calculated as the distance from far right or bottom edge 72 * of the console (respectively). 73 * 74 * @param int $x1 Top-left corner X coordinate (column) 75 * @param int $y1 Top-left corner Y coordinate (row) 76 * @param int $x2 Bottom-right corner X coordinate (column) 77 * @param int $y2 Bottom-right corner Y coordinate (row) 78 * @param int $lineStyle (optional) Box border style. 79 * @param int $fillStyle (optional) Box fill style or a single character to fill it with. 80 * @param int $color (optional) Foreground color 81 * @param int $bgColor (optional) Background color 82 * @param null|int $fillColor (optional) Foreground color of box fill 83 * @param null|int $fillBgColor (optional) Background color of box fill 84 * @return void 85 */ 86 public function writeBox( 87 $x1, 88 $y1, 89 $x2, 90 $y2, 91 $lineStyle = self::LINE_SINGLE, 92 $fillStyle = self::FILL_NONE, 93 $color = null, 94 $bgColor = null, 95 $fillColor = null, 96 $fillBgColor = null 97 ); 98 99 /** 100 * Write a block of text at the given coordinates, matching the supplied width and height. 101 * In case a line of text does not fit desired width, it will be wrapped to the next line. 102 * In case the whole text does not fit in desired height, it will be truncated. 103 * 104 * @param string $text Text to write 105 * @param int $width Maximum block width. Negative value means distance from right edge. 106 * @param int|null $height Maximum block height. Negative value means distance from bottom edge. 107 * @param int $x Block X coordinate (column) 108 * @param int $y Block Y coordinate (row) 109 * @param null|int $color (optional) Text color 110 * @param null|int $bgColor (optional) Text background color 111 * @return void 112 */ 113 public function writeTextBlock( 114 $text, 115 $width, 116 $height = null, 117 $x = 0, 118 $y = 0, 119 $color = null, 120 $bgColor = null 121 ); 122 123 /** 124 * Determine and return current console width. 125 * 126 * @return int 127 */ 128 public function getWidth(); 129 130 /** 131 * Determine and return current console height. 132 * 133 * @return int 134 */ 135 public function getHeight(); 136 137 /** 138 * Determine and return current console width and height. 139 * 140 * @return array array($width, $height) 141 */ 142 public function getSize(); 143 144 /** 145 * Check if console is UTF-8 compatible 146 * 147 * @return bool 148 */ 149 public function isUtf8(); 150 151 /** 152 * Set cursor position 153 * 154 * @param int $x 155 * @param int $y 156 * @return void 157 */ 158 public function setPos($x, $y); 159 160 /** 161 * Hide console cursor 162 * @return void 163 */ 164 public function hideCursor(); 165 166 /** 167 * Show console cursor 168 * @return void 169 */ 170 public function showCursor(); 171 172 /** 173 * Return current console window title. 174 * 175 * @return string 176 */ 177 public function getTitle(); 178 179 /** 180 * Prepare a string that will be rendered in color. 181 * 182 * @param string $string 183 * @param null|int $color Foreground color 184 * @param null|int $bgColor Background color 185 * @return string 186 */ 187 public function colorize($string, $color = null, $bgColor = null); 188 189 /** 190 * Change current drawing color. 191 * 192 * @param int $color 193 * @return void 194 */ 195 public function setColor($color); 196 197 /** 198 * Change current drawing background color 199 * 200 * @param int $color 201 * @return void 202 */ 203 public function setBgColor($color); 204 205 /** 206 * Reset color to console default. 207 * @return void 208 */ 209 public function resetColor(); 210 211 /** 212 * Set Console charset to use. 213 * 214 * @param CharsetInterface $charset 215 * @return void 216 */ 217 public function setCharset(CharsetInterface $charset); 218 219 /** 220 * Get charset currently in use by this adapter. 221 * 222 * @return CharsetInterface $charset 223 */ 224 public function getCharset(); 225 226 /** 227 * @return CharsetInterface 228 */ 229 public function getDefaultCharset(); 230 231 /** 232 * Clear console screen 233 * @return void 234 */ 235 public function clear(); 236 237 /** 238 * Clear line at cursor position 239 * @return void 240 */ 241 public function clearLine(); 242 243 /** 244 * Clear console screen 245 * @return void 246 */ 247 public function clearScreen(); 248 249 /** 250 * Read a single line from the console input 251 * 252 * @param int $maxLength Maximum response length 253 * @return string 254 */ 255 public function readLine($maxLength = 2048); 256 257 /** 258 * Read a single character from the console input 259 * 260 * @param string|null $mask A list of allowed chars 261 * @return string 262 */ 263 public function readChar($mask = null); 264} 265