Passed
Push — master ( 84d38d...ef0840 )
by Alec
02:22
created

Cursor::show()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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