Passed
Push — master ( ada559...ce303d )
by Alec
03:02
created

Cursor::save()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Cli\Tools;
4
5
use const AlecRabbit\ESC;
6
7
class Cursor
8
{
9
    /**
10
     * Show cursor sequence
11
     *
12
     * @return string
13
     */
14 2
    public static function show(): string
15
    {
16 2
        return ESC . '[?25h' . ESC . '[?0c';
17
    }
18
19
    /**
20
     * Hide cursor sequence
21
     *
22
     * @return string
23
     */
24 2
    public static function hide(): string
25
    {
26 2
        return ESC . '[?25l';
27
    }
28
29
    /**
30
     * Move cursor up sequence
31
     *
32
     * @param int $rows
33
     * @return string
34
     */
35 2
    public static function up(int $rows = 1): string
36
    {
37 2
        return ESC . "[{$rows}A";
38
    }
39
40
    /**
41
     * Move cursor up to begin of the line sequence
42
     *
43
     * @param int $rows
44
     * @return string
45
     */
46
    public static function upLine(int $rows = 1): string
47
    {
48
        return ESC . "[{$rows}F";
49
    }
50
51
    /**
52
     * Move cursor down to begin of the line sequence
53
     *
54
     * @param int $rows
55
     * @return string
56
     */
57
    public static function downLine(int $rows = 1): string
58
    {
59
        return ESC . "[{$rows}E";
60
    }
61
62
    /**
63
     * Move cursor down sequence
64
     *
65
     * @param int $rows
66
     * @return string
67
     */
68 2
    public static function down(int $rows = 1): string
69
    {
70 2
        return ESC . "[{$rows}B";
71
    }
72
73
    /**
74
     * Move cursor forward sequence
75
     *
76
     * @param int $cols
77
     * @return string
78
     */
79 2
    public static function forward(int $cols = 1): string
80
    {
81 2
        return ESC . "[{$cols}C";
82
    }
83
84
    /**
85
     * Move cursor back sequence
86
     *
87
     * @param int $cols
88
     * @return string
89
     */
90 2
    public static function back(int $cols = 1): string
91
    {
92 2
        return ESC . "[{$cols}D";
93
    }
94
95
    /**
96
     * Move cursor to sequence
97
     *
98
     * @param int $col
99
     * @param int $row
100
     * @return string
101
     */
102 2
    public static function goTo(int $col = 1, int $row = 1): string
103
    {
104 2
        return ESC . "[{$row};{$col}f";
105
    }
106
107
    /**
108
     * Move cursor to position in current line sequence
109
     *
110
     * @param int $col
111
     * @return string
112
     */
113
    public static function absX(int $col = 1): string
114
    {
115
        return ESC . "[{$col}G";
116
    }
117
118
    /**
119
     * Move cursor to position in current column sequence
120
     *
121
     * @param int $row
122
     * @return string
123
     */
124
    public static function absY(int $row = 1): string
125
    {
126
        return ESC . "[{$row}d";
127
    }
128
129
    /**
130
     * Save cursor position sequence
131
     *
132
     * @return string
133
     */
134 2
    public static function savePosition(): string
135
    {
136 2
        return ESC . '[s';
137
    }
138
139
    /**
140
     * Restore cursor position sequence
141
     *
142
     * @return string
143
     */
144 2
    public static function restorePosition(): string
145
    {
146 2
        return ESC . '[u';
147
    }
148
149
    /**
150
     * Save cursor position and attributes sequence
151
     *
152
     * @return string
153
     */
154 2
    public static function save(): string
155
    {
156 2
        return ESC . '7';
157
    }
158
159
    /**
160
     * Restore cursor position and attributes sequence
161
     *
162
     * @return string
163
     */
164 2
    public static function restore(): string
165
    {
166 2
        return ESC . '8';
167
    }
168
}
169