function Cursor::getCurrentPosition
Returns the current cursor position as x,y coordinates.
File
-
vendor/
symfony/ console/ Cursor.php, line 183
Class
- Cursor
- @author Pierre du Plessis <pdples@gmail.com>
Namespace
Symfony\Component\ConsoleCode
public function getCurrentPosition() : array {
static $isTtySupported;
if (!($isTtySupported ??= '/' === \DIRECTORY_SEPARATOR && stream_isatty(\STDOUT))) {
return [
1,
1,
];
}
$sttyMode = shell_exec('stty -g');
shell_exec('stty -icanon -echo');
@fwrite($this->input, "\x1b[6n");
$code = trim(fread($this->input, 1024));
shell_exec(\sprintf('stty %s', $sttyMode));
sscanf($code, "\x1b[%d;%dR", $row, $col);
return [
$col,
$row,
];
}