Cursor.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace League\CLImate\Util;
  3. class Cursor
  4. {
  5. /**
  6. * Move the cursor up in the terminal x number of lines.
  7. *
  8. * @param int $lines
  9. *
  10. * @return string
  11. */
  12. public function up($lines = 1)
  13. {
  14. return "\e[{$lines}A";
  15. }
  16. /**
  17. * Move the cursor left in the terminal x number of columns.
  18. *
  19. * @param int $cols
  20. *
  21. * @return string
  22. */
  23. public function left($cols = 1)
  24. {
  25. return "\e[{$cols}D";
  26. }
  27. /**
  28. * Move cursor to the beginning of the current line.
  29. *
  30. * @return string
  31. */
  32. public function startOfCurrentLine()
  33. {
  34. return "\r";
  35. }
  36. /**
  37. * Delete the current line to the end.
  38. *
  39. * @return string
  40. */
  41. public function deleteCurrentLine()
  42. {
  43. return "\e[K";
  44. }
  45. /**
  46. * Get the style for hiding the cursor
  47. *
  48. * @return string
  49. */
  50. public function hide()
  51. {
  52. return "\e[?25l";
  53. }
  54. /**
  55. * Get the style for returning the cursor to its default
  56. *
  57. * @return string
  58. */
  59. public function defaultStyle()
  60. {
  61. return "\e[?25h";
  62. }
  63. }