Cursor::downLine()   A
last analyzed

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