Passed
Push — master ( 0d73f0...9e6f1e )
by Alec
07:52
created

Cursor::goTo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Control;
4
5
use AlecRabbit\ConsoleColour\ConsoleColor;
6
7
class Cursor
8
{
9
    protected const ESC = ConsoleColor::ESC_CHAR;
10
11
    /**
12
     * Show cursor sequence
13
     *
14
     * @return string
15
     */
16 1
    public static function show(): string
17
    {
18 1
        return self::ESC . '[?25h' . self::ESC . '[?0c';
19
    }
20
21
    /**
22
     * Hide cursor sequence
23
     *
24
     * @return string
25
     */
26 1
    public static function hide(): string
27
    {
28 1
        return self::ESC . '[?25l';
29
    }
30
31
    /**
32
     * Move cursor up sequence
33
     *
34
     * @param int $rows
35
     * @return string
36
     */
37
    public static function up(int $rows = 1): string
38
    {
39
        return self::ESC . "[{$rows}A";
40
    }
41
42
    /**
43
     * Move cursor down sequence
44
     *
45
     * @param int $rows
46
     * @return string
47
     */
48
    public static function down(int $rows = 1): string
49
    {
50
        return self::ESC . "[{$rows}B";
51
    }
52
53
    /**
54
     * Move cursor forward sequence
55
     *
56
     * @param int $cols
57
     * @return string
58
     */
59
    public static function forward(int $cols = 1): string
60
    {
61
        return self::ESC . "[{$cols}C";
62
    }
63
64
    /**
65
     * Move cursor back sequence
66
     *
67
     * @param int $cols
68
     * @return string
69
     */
70
    public static function back(int $cols = 1): string
71
    {
72
        return self::ESC . "[{$cols}D";
73
    }
74
75
    /**
76
     * Move cursor to sequence
77
     *
78
     * @param int $col
79
     * @param int $row
80
     * @return string
81
     */
82
    public static function goTo(int $col = 1, int $row = 1): string
83
    {
84
        return self::ESC . "[{$row};{$col}f";
85
    }
86
87
    /**
88
     * Save cursor position sequence
89
     *
90
     * @return string
91
     */
92
    public static function savePosition(): string
93
    {
94
        return self::ESC . '[s';
95
    }
96
97
    /**
98
     * Restore cursor position sequence
99
     *
100
     * @return string
101
     */
102
    public static function restorePosition(): string
103
    {
104
        return self::ESC . '[u';
105
    }
106
    /**
107
     * Save cursor position and attributes sequence
108
     *
109
     * @return string
110
     */
111
    public static function save(): string
112
    {
113
        return self::ESC . '7';
114
    }
115
116
    /**
117
     * Restore cursor position and attributes sequence
118
     *
119
     * @return string
120
     */
121
    public static function restore(): string
122
    {
123
        return self::ESC . '8';
124
    }
125
}
126
//