Completed
Push — master ( a4afb1...d2ff2c )
by Harry
02:25
created

ANSI::moveLeft()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * This file is part of graze/console-diff-renderer.
4
 *
5
 * Copyright (c) 2017 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/console-diff-renderer/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/console-diff-renderer
12
 */
13
14
namespace Graze\DiffRenderer\Terminal;
15
16
class ANSI implements CursorInterface
17
{
18
    const ESCAPE = "\e";
19
20
    const CODE_MOVE_POSITION   = '[%d;%dH'; // line, column
21
    const CODE_MOVE_UP_LINES   = '[%dA'; // lines
22
    const CODE_MOVE_DOWN_LINES = '[%dB'; // lines
23
    const CODE_MOVE_FORWARD    = '[%dC'; // columns
24
    const CODE_MOVE_BACKWARDS  = '[%dD'; // columns
25
26
    const CODE_ERASE_TO_END_OF_LINE   = '[K';
27
    const CODE_ERASE_TO_START_OF_LINE = '[1K';
28
    const CODE_ERASE_LINE             = '[2K';
29
    const CODE_ERASE_DOWN             = '[J';
30
    const CODE_ERASE_UP               = '[1J';
31
    const CODE_ERASE_SCREEN           = '[2J';
32
33
    /**
34
     * @param int $line
35
     * @param int $column
36
     *
37
     * @return string
38
     */
39
    public function move($line, $column)
40
    {
41
        return static::ESCAPE . sprintf(static::CODE_MOVE_POSITION, $line, $column);
42
    }
43
44
    /**
45
     * @param int $lines
46
     *
47
     * @return string
48
     */
49
    public function moveUp($lines)
50
    {
51
        return static::ESCAPE . sprintf(static::CODE_MOVE_UP_LINES, $lines);
52
    }
53
54
    /**
55
     * @param int $lines
56
     *
57
     * @return string
58
     */
59
    public function moveDown($lines)
60
    {
61
        return static::ESCAPE . sprintf(static::CODE_MOVE_DOWN_LINES, $lines);
62
    }
63
64
    /**
65
     * @param int $columns
66
     *
67
     * @return string
68
     */
69
    public function moveLeft($columns)
70
    {
71
        return static::ESCAPE . sprintf(static::CODE_MOVE_BACKWARDS, $columns);
72
    }
73
74
    /**
75
     * @param int $columns
76
     *
77
     * @return string
78
     */
79
    public function moveRight($columns)
80
    {
81
        return static::ESCAPE . sprintf(static::CODE_MOVE_FORWARD, $columns);
82
    }
83
84
    /**
85
     * @return string
86
     */
87
    public function eraseToEnd()
88
    {
89
        return static::ESCAPE . static::CODE_ERASE_TO_END_OF_LINE;
90
    }
91
92
    /**
93
     * @return string
94
     */
95
    public function eraseToStart()
96
    {
97
        return static::ESCAPE . static::CODE_ERASE_TO_START_OF_LINE;
98
    }
99
100
    /**
101
     * @return string
102
     */
103
    public function eraseDown()
104
    {
105
        return static::ESCAPE . static::CODE_ERASE_DOWN;
106
    }
107
108
    /**
109
     * @return string
110
     */
111
    public function eraseUp()
112
    {
113
        return static::ESCAPE . static::CODE_ERASE_UP;
114
    }
115
116
    /**
117
     * @return string
118
     */
119
    public function eraseScreen()
120
    {
121
        return static::ESCAPE . static::CODE_ERASE_SCREEN;
122
    }
123
}
124