tty-cursor 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -11
- data/CHANGELOG.md +19 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +2 -1
- data/README.md +105 -59
- data/appveyor.yml +23 -0
- data/lib/tty/cursor.rb +76 -47
- data/lib/tty/version.rb +1 -1
- data/spec/unit/clear_lines_spec.rb +27 -12
- data/spec/unit/cursor_spec.rb +17 -5
- data/tty-cursor.gemspec +2 -2
- metadata +15 -14
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21bae31e727bfc59faaf59b29fe458f9d6c96463
|
4
|
+
data.tar.gz: 145f6e5308fc50a95c51e76bff5b076114d6bc06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38785d325d0a77807bfdc213b87e90e6786a1508c4416a8ecf68bf92d1227e9cdb35aa7fcc43116e1e49759dc07e10bddcd321eb1f5fc4e70d89a5e6cbeca0fd
|
7
|
+
data.tar.gz: 12c6e6be868e68e6f0f3bd50b02eea8c409940ed9189d3d99910eeab43c6c4ccd3c85e4d0bd789e04a8b66262e58fe79dfc9198e7abc449c4df500d66231b662
|
data/.travis.yml
CHANGED
@@ -6,22 +6,21 @@ bundler_args: --without yard benchmarks
|
|
6
6
|
script: "bundle exec rake ci"
|
7
7
|
rvm:
|
8
8
|
- 1.9.3
|
9
|
-
- 2.0
|
10
|
-
- 2.1
|
11
|
-
- 2.2
|
12
|
-
- 2.3.
|
9
|
+
- 2.0.0
|
10
|
+
- 2.1.10
|
11
|
+
- 2.2.6
|
12
|
+
- 2.3.3
|
13
|
+
- 2.4.0
|
13
14
|
- ruby-head
|
15
|
+
- jruby-9000
|
16
|
+
- jruby-head
|
17
|
+
- rbx-3
|
14
18
|
matrix:
|
15
|
-
include:
|
16
|
-
- rvm: jruby-19mode
|
17
|
-
- rvm: jruby-20mode
|
18
|
-
- rvm: jruby-21mode
|
19
|
-
- rvm: jruby-9000
|
20
|
-
- rvm: jruby-head
|
21
|
-
- rvm: rbx-2
|
22
19
|
allow_failures:
|
20
|
+
- rvm: 2.4.0
|
23
21
|
- rvm: ruby-head
|
24
22
|
- rvm: jruby-head
|
23
|
+
- rvm: rbx-3
|
25
24
|
fast_finish: true
|
26
25
|
branches:
|
27
26
|
only: master
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.4.0] - 2017-01-08
|
4
|
+
|
5
|
+
### Added
|
6
|
+
* Add #clear_char for erasing characters
|
7
|
+
* Add #clear_line_before for erasing line before the cursor
|
8
|
+
* Add #clear_line_after for erasing line after the cursor
|
9
|
+
* Add #column to move the cursor horizontally in the current line
|
10
|
+
* Add #row to move the cursor vertically in the current column
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
* Remove #move_start
|
14
|
+
* Change #next_line to move the cursor to beginning of the line
|
15
|
+
* Change #clear_line to move the cursor to beginning of the line
|
16
|
+
* Change alias_method to alias
|
17
|
+
|
18
|
+
### Fixed
|
19
|
+
* Fix #clear_line to correctly clear whole line
|
20
|
+
|
3
21
|
## [v0.3.0] - 2016-05-21
|
4
22
|
|
5
23
|
### Fixed
|
@@ -14,6 +32,7 @@
|
|
14
32
|
|
15
33
|
* Initial implementation and release
|
16
34
|
|
35
|
+
[v0.4.0]: https://github.com/peter-murach/tty-cursor/compare/v0.3.0...v0.4.0
|
17
36
|
[v0.3.0]: https://github.com/peter-murach/tty-cursor/compare/v0.2.0...v0.3.0
|
18
37
|
[v0.2.0]: https://github.com/peter-murach/tty-cursor/compare/v0.1.0...v0.2.0
|
19
38
|
[v0.1.0]: https://github.com/peter-murach/tty-cursor/compare/v0.1.0
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at [email]. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
CHANGED
@@ -4,7 +4,7 @@ gemspec
|
|
4
4
|
|
5
5
|
group :development do
|
6
6
|
gem 'rake', '~> 10.4.2'
|
7
|
-
gem 'rspec', '~> 3.
|
7
|
+
gem 'rspec', '~> 3.5.0'
|
8
8
|
gem 'yard', '~> 0.8.7'
|
9
9
|
gem 'benchmark-ips', '~> 2.0.0'
|
10
10
|
end
|
@@ -13,4 +13,5 @@ group :metrics do
|
|
13
13
|
gem 'coveralls', '~> 0.8.9'
|
14
14
|
gem 'simplecov', '~> 0.10.0'
|
15
15
|
gem 'yardstick', '~> 0.9.9'
|
16
|
+
gem 'term-ansicolor', '=1.3.2'
|
16
17
|
end
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# TTY::Cursor [![Gitter](https://badges.gitter.im/Join%20Chat.svg)][gitter]
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/tty-cursor.svg)][gem]
|
3
3
|
[![Build Status](https://secure.travis-ci.org/piotrmurach/tty-cursor.svg?branch=master)][travis]
|
4
|
+
[![Build status](https://ci.appveyor.com/api/projects/status/4k7cd69jscwg7fl7?svg=true)][appveyor]
|
4
5
|
[![Code Climate](https://codeclimate.com/github/piotrmurach/tty-cursor/badges/gpa.svg)][codeclimate]
|
5
6
|
[![Coverage Status](https://coveralls.io/repos/piotrmurach/tty-cursor/badge.svg)][coverage]
|
6
7
|
[![Inline docs](http://inch-ci.org/github/piotrmurach/tty-cursor.svg?branch=master)][inchpages]
|
@@ -8,13 +9,14 @@
|
|
8
9
|
[gitter]: https://gitter.im/piotrmurach/tty
|
9
10
|
[gem]: http://badge.fury.io/rb/tty-cursor
|
10
11
|
[travis]: http://travis-ci.org/piotrmurach/tty-cursor
|
12
|
+
[appveyor]: https://ci.appveyor.com/project/piotrmurach/tty-cursor
|
11
13
|
[codeclimate]: https://codeclimate.com/github/piotrmurach/tty-cursor
|
12
14
|
[coverage]: https://coveralls.io/r/piotrmurach/tty-cursor
|
13
15
|
[inchpages]: http://inch-ci.org/github/piotrmurach/tty-cursor
|
14
16
|
|
15
|
-
> Terminal cursor
|
17
|
+
> Terminal cursor positioning, visibility and text manipulation.
|
16
18
|
|
17
|
-
The purpose of this library is to help move terminal cursor around
|
19
|
+
The purpose of this library is to help move the terminal cursor around and manipulate text by using intuitive method calls.
|
18
20
|
|
19
21
|
**TTY::Cursor** provides independent cursor movement component for [TTY](https://github.com/piotrmurach/tty) toolkit.
|
20
22
|
|
@@ -38,27 +40,33 @@ Or install it yourself as:
|
|
38
40
|
|
39
41
|
* [1. Usage](#1-usage)
|
40
42
|
* [2. Interface](#2-interface)
|
41
|
-
* [2.1 Cursor
|
43
|
+
* [2.1 Cursor Positioning](#21-cursor-positioning)
|
42
44
|
* [2.1.1 move_to(x, y)](#211-move_tox-y)
|
43
45
|
* [2.1.2 move(x, y)](#212-movex-y)
|
44
|
-
* [2.1.3 up(
|
45
|
-
* [2.1.4 down(
|
46
|
-
* [2.1.5 forward(
|
47
|
-
* [2.1.6 backward(
|
48
|
-
* [2.1.7
|
49
|
-
* [2.1.8
|
50
|
-
* [2.1.9
|
51
|
-
* [2.1.10
|
52
|
-
* [2.1.11
|
53
|
-
* [2.1.12
|
54
|
-
* [2.1.13
|
55
|
-
|
56
|
-
|
57
|
-
* [2.2.
|
58
|
-
* [2.2.
|
59
|
-
|
60
|
-
* [2.
|
61
|
-
* [2.2
|
46
|
+
* [2.1.3 up(n)](#213-upn)
|
47
|
+
* [2.1.4 down(n)](#214-downn)
|
48
|
+
* [2.1.5 forward(n)](#215-forwardn)
|
49
|
+
* [2.1.6 backward(n)](#216-backwardn)
|
50
|
+
* [2.1.7 column(n)](#217-columnn)
|
51
|
+
* [2.1.8 row(n)](#218-rown)
|
52
|
+
* [2.1.9 next_line](#219-next_line)
|
53
|
+
* [2.1.10 prev_line](#2110-prev_line)
|
54
|
+
* [2.1.11 save](#2111-save)
|
55
|
+
* [2.1.12 restore](#2112-restore)
|
56
|
+
* [2.1.13 current](#2113-current)
|
57
|
+
* [2.2 Cursor Visibility](#22-cursor-visibility)
|
58
|
+
* [2.2.1 show](#221-show)
|
59
|
+
* [2.2.2 hide](#222-hide)
|
60
|
+
* [2.2.3 invisible(stream)](#2114-invisiblestream)
|
61
|
+
* [2.3 Text Modification](#23-text-modification)
|
62
|
+
* [2.3.1 clear_char(n)](#231-clear_charn)
|
63
|
+
* [2.3.2 clear_line](#232-clear_line)
|
64
|
+
* [2.3.3 clear_line_before](#233-clear_line)
|
65
|
+
* [2.3.4 clear_line_after](#234-clear_line)
|
66
|
+
* [2.3.5 clear_lines(n, direction)](#235-clear_linesn-direction)
|
67
|
+
* [2.3.6 clear_screen_down](#236-clear_screen_down)
|
68
|
+
* [2.3.7 clear_screen_up](#237-clear_screen_up)
|
69
|
+
* [2.3.8 clear_screen](#238-clear_screen)
|
62
70
|
|
63
71
|
## 1. Usage
|
64
72
|
|
@@ -68,21 +76,31 @@ Or install it yourself as:
|
|
68
76
|
cursor = TTY::Cursor
|
69
77
|
```
|
70
78
|
|
71
|
-
and
|
79
|
+
and to move the cursor current position by 5 rows up and 2 columns right do:
|
72
80
|
|
73
81
|
```ruby
|
74
82
|
print cursor.up(5) + cursor.forward(2)
|
75
83
|
```
|
76
84
|
|
77
|
-
or
|
85
|
+
or call `move` to move cursor relative to current position:
|
78
86
|
|
79
87
|
```ruby
|
80
88
|
print cursor.move(5, 2)
|
81
89
|
```
|
82
90
|
|
91
|
+
to remove text from the current line do:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
print cursor.clear_line
|
95
|
+
```
|
96
|
+
|
83
97
|
## 2. Interface
|
84
98
|
|
85
|
-
### 2.1 Cursor
|
99
|
+
### 2.1 Cursor Positioning
|
100
|
+
|
101
|
+
All methods in this section allow to position the cursor around the terminal viewport.
|
102
|
+
|
103
|
+
Cursor movement will be bounded by the current viewport into the buffer. Scrolling (if available) will not occur.
|
86
104
|
|
87
105
|
#### 2.1.1 move_to(x, y)
|
88
106
|
|
@@ -98,53 +116,65 @@ cursor.move_to
|
|
98
116
|
|
99
117
|
Move cursor by x columns and y rows relative to its current position.
|
100
118
|
|
101
|
-
#### 2.1.3 up(
|
119
|
+
#### 2.1.3 up(n)
|
120
|
+
|
121
|
+
Move the cursor up by `n` rows; the default n is `1`.
|
122
|
+
|
123
|
+
#### 2.1.4 down(n)
|
102
124
|
|
103
|
-
Move the cursor
|
125
|
+
Move the cursor down by `n` rows; the default n is `1`.
|
104
126
|
|
105
|
-
#### 2.1.
|
127
|
+
#### 2.1.5 forward(n)
|
106
128
|
|
107
|
-
Move the cursor
|
129
|
+
Move the cursor forward by `n` columns; the default n is `1`.
|
108
130
|
|
109
|
-
#### 2.1.
|
131
|
+
#### 2.1.6 backward(n)
|
110
132
|
|
111
|
-
Move the cursor
|
133
|
+
Move the cursor backward by `n` columns; the default n is `1`.
|
112
134
|
|
113
|
-
#### 2.1.
|
135
|
+
#### 2.1.7 column(n)
|
114
136
|
|
115
|
-
|
137
|
+
Cursor moves to `<n>`th position horizontally in the current line.
|
116
138
|
|
117
|
-
#### 2.1.
|
139
|
+
#### 2.1.8 row(n)
|
140
|
+
|
141
|
+
Cursor moves the the `<n>`th position vertically in the current column.
|
142
|
+
|
143
|
+
#### 2.1.9 next_line
|
144
|
+
|
145
|
+
Move the cursor down to the beginning of the next line.
|
146
|
+
|
147
|
+
#### 2.1.10 prev_line
|
148
|
+
|
149
|
+
Move the cursor up to the beginning of the previous line.
|
150
|
+
|
151
|
+
#### 2.1.11 save
|
118
152
|
|
119
153
|
Save current cursor position.
|
120
154
|
|
121
|
-
#### 2.1.
|
155
|
+
#### 2.1.12 restore
|
122
156
|
|
123
157
|
Restore cursor position after a save cursor was called.
|
124
158
|
|
125
|
-
#### 2.1.
|
159
|
+
#### 2.1.13 current
|
126
160
|
|
127
161
|
Query current cursor position
|
128
162
|
|
129
|
-
|
130
|
-
|
131
|
-
Move the cursor to the next line.
|
163
|
+
### 2.2 Cursor Visibility
|
132
164
|
|
133
|
-
|
165
|
+
The following methods control the visibility of the cursor.
|
134
166
|
|
135
|
-
|
167
|
+
#### 2.2.1 show
|
136
168
|
|
137
|
-
|
169
|
+
Show the cursor.
|
138
170
|
|
139
|
-
|
171
|
+
#### 2.2.2 hide
|
140
172
|
|
141
|
-
|
173
|
+
Hide the cursor.
|
142
174
|
|
143
|
-
|
175
|
+
#### 2.2.3 invisible(stream)
|
144
176
|
|
145
|
-
|
146
|
-
|
147
|
-
To hide cursor for the duration of the block do:
|
177
|
+
To hide the cursor for the duration of the block do:
|
148
178
|
|
149
179
|
```ruby
|
150
180
|
cursor.invisible { ... }
|
@@ -156,31 +186,45 @@ By default standard output will be used but you can change that by passing a dif
|
|
156
186
|
cursor.invisible($stderr) { .... }
|
157
187
|
```
|
158
188
|
|
159
|
-
### 2.
|
189
|
+
### 2.3 Text Modification
|
190
|
+
|
191
|
+
All methods in this section provide APIs to modify text buffer contents.
|
192
|
+
|
193
|
+
#### 2.3.1 clear_char(n)
|
194
|
+
|
195
|
+
Erase `<n>` characters from the current cursor position by overwritting them with space character.
|
196
|
+
|
197
|
+
#### 2.3.2 clear_line
|
198
|
+
|
199
|
+
Erase the entire current line and return cursor to beginning of the line.
|
200
|
+
|
201
|
+
#### 2.3.3 clear_line_before
|
202
|
+
|
203
|
+
Erase from the beginning of the line up to and including the current position.
|
160
204
|
|
161
|
-
#### 2.
|
205
|
+
#### 2.3.4 clear_line_after
|
162
206
|
|
163
|
-
Erase the
|
207
|
+
Erase from the current position (inclusive) to the end of the line/display.
|
164
208
|
|
165
|
-
#### 2.
|
209
|
+
#### 2.3.5 clear_lines(n, direction)
|
166
210
|
|
167
|
-
Erase `
|
211
|
+
Erase `n` rows in given direction; the default direction is `:up`.
|
168
212
|
|
169
213
|
```ruby
|
170
214
|
cursor.clear_lines(5, :down)
|
171
215
|
```
|
172
216
|
|
173
|
-
#### 2.
|
217
|
+
#### 2.3.6 clear_screen
|
174
218
|
|
175
|
-
Erase the screen
|
219
|
+
Erase the screen with the background colour and moves the cursor to home.
|
176
220
|
|
177
|
-
#### 2.
|
221
|
+
#### 2.3.7 clear_screen_down
|
178
222
|
|
179
|
-
Erase the screen from the current line
|
223
|
+
Erase the screen from the current line down to the bottom of the screen.
|
180
224
|
|
181
|
-
#### 2.
|
225
|
+
#### 2.3.8 clear_screen_up
|
182
226
|
|
183
|
-
Erase the screen
|
227
|
+
Erase the screen from the current line up to the top of the screen.
|
184
228
|
|
185
229
|
## Contributing
|
186
230
|
|
@@ -190,6 +234,8 @@ Erase the screen with the background colour and moves the cursor to home.
|
|
190
234
|
4. Push to the branch (`git push origin my-new-feature`)
|
191
235
|
5. Create a new Pull Request
|
192
236
|
|
237
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
238
|
+
|
193
239
|
## Copyright
|
194
240
|
|
195
|
-
Copyright (c) 2015-
|
241
|
+
Copyright (c) 2015-2017 Piotr Murach. See LICENSE for further details.
|
data/appveyor.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
install:
|
3
|
+
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
|
4
|
+
- ruby --version
|
5
|
+
- gem --version
|
6
|
+
- bundle install
|
7
|
+
build: off
|
8
|
+
test_script:
|
9
|
+
- bundle exec rake ci
|
10
|
+
environment:
|
11
|
+
matrix:
|
12
|
+
- ruby_version: "193"
|
13
|
+
- ruby_version: "200"
|
14
|
+
- ruby_version: "200-x64"
|
15
|
+
- ruby_version: "21"
|
16
|
+
- ruby_version: "21-x64"
|
17
|
+
- ruby_version: "22"
|
18
|
+
- ruby_version: "22-x64"
|
19
|
+
- ruby_version: "23"
|
20
|
+
- ruby_version: "23-x64"
|
21
|
+
matrix:
|
22
|
+
allow_failures:
|
23
|
+
- ruby_version: "193"
|
data/lib/tty/cursor.rb
CHANGED
@@ -5,22 +5,22 @@ module TTY
|
|
5
5
|
module Cursor
|
6
6
|
module_function
|
7
7
|
|
8
|
-
|
8
|
+
ESC = "\e".freeze
|
9
|
+
CSI = "\e[".freeze
|
9
10
|
DEC_RST = 'l'.freeze
|
10
11
|
DEC_SET = 'h'.freeze
|
11
12
|
DEC_TCEM = '?25'.freeze
|
12
|
-
ECMA_CLR = 'K'.freeze
|
13
13
|
|
14
14
|
# Make cursor visible
|
15
15
|
# @api public
|
16
16
|
def show
|
17
|
-
|
17
|
+
CSI + DEC_TCEM + DEC_SET
|
18
18
|
end
|
19
19
|
|
20
20
|
# Hide cursor
|
21
21
|
# @api public
|
22
22
|
def hide
|
23
|
-
|
23
|
+
CSI + DEC_TCEM + DEC_RST
|
24
24
|
end
|
25
25
|
|
26
26
|
# Switch off cursor for the block
|
@@ -35,19 +35,19 @@ module TTY
|
|
35
35
|
# Save current position
|
36
36
|
# @api public
|
37
37
|
def save
|
38
|
-
|
38
|
+
CSI + 's'
|
39
39
|
end
|
40
40
|
|
41
41
|
# Restore cursor position
|
42
42
|
# @api public
|
43
43
|
def restore
|
44
|
-
|
44
|
+
CSI + 'u'
|
45
45
|
end
|
46
46
|
|
47
47
|
# Query cursor current position
|
48
48
|
# @api public
|
49
49
|
def current
|
50
|
-
|
50
|
+
CSI + '6n'
|
51
51
|
end
|
52
52
|
|
53
53
|
# Set the cursor absolute position
|
@@ -55,8 +55,8 @@ module TTY
|
|
55
55
|
# @param [Integer] column
|
56
56
|
# @api public
|
57
57
|
def move_to(row = nil, column = nil)
|
58
|
-
return
|
59
|
-
|
58
|
+
return CSI + 'H' if row.nil? && column.nil?
|
59
|
+
CSI + "#{column + 1};#{row + 1}H"
|
60
60
|
end
|
61
61
|
|
62
62
|
# Move cursor relative to its current position
|
@@ -70,95 +70,124 @@ module TTY
|
|
70
70
|
(y < 0 ? down(-y) : (y > 0 ? up(y) : ''))
|
71
71
|
end
|
72
72
|
|
73
|
-
# Move cursor up by
|
74
|
-
#
|
75
|
-
# @param [Integer] count
|
76
|
-
#
|
73
|
+
# Move cursor up by n
|
74
|
+
# @param [Integer] n
|
77
75
|
# @api public
|
78
|
-
def up(
|
79
|
-
|
76
|
+
def up(n = nil)
|
77
|
+
CSI + "#{(n || 1)}A"
|
80
78
|
end
|
81
|
-
|
79
|
+
alias cursor_up up
|
82
80
|
|
83
|
-
# Move cursor down by
|
84
|
-
#
|
85
|
-
# @param [Integer] count
|
86
|
-
#
|
81
|
+
# Move the cursor down by n
|
82
|
+
# @param [Integer] n
|
87
83
|
# @api public
|
88
|
-
def down(
|
89
|
-
|
84
|
+
def down(n = nil)
|
85
|
+
CSI + "#{(n || 1)}B"
|
90
86
|
end
|
91
|
-
|
87
|
+
alias cursor_down down
|
92
88
|
|
93
|
-
# Move
|
94
|
-
#
|
89
|
+
# Move the cursor backward by n
|
90
|
+
# @param [Integer] n
|
95
91
|
# @api public
|
96
|
-
def
|
97
|
-
|
92
|
+
def backward(n = nil)
|
93
|
+
CSI + "#{n || 1}D"
|
98
94
|
end
|
95
|
+
alias cursor_backward backward
|
99
96
|
|
100
|
-
#
|
101
|
-
#
|
97
|
+
# Move the cursor forward by n
|
98
|
+
# @param [Integer] n
|
102
99
|
# @api public
|
103
|
-
def
|
104
|
-
|
100
|
+
def forward(n = nil)
|
101
|
+
CSI + "#{n || 1}C"
|
105
102
|
end
|
106
|
-
|
103
|
+
alias cursor_forward forward
|
107
104
|
|
105
|
+
# Cursor moves to nth position horizontally in the current line
|
106
|
+
# @param [Integer] n
|
107
|
+
# the nth aboslute position in line
|
108
108
|
# @api public
|
109
|
-
def
|
110
|
-
|
109
|
+
def column(n = nil)
|
110
|
+
CSI + "#{n || 1}G"
|
111
111
|
end
|
112
|
-
alias_method :cursor_forward, :forward
|
113
112
|
|
113
|
+
# Cursor moves to the nth position vertically in the current column
|
114
|
+
# @param [Integer] n
|
115
|
+
# the nth absolute position in column
|
116
|
+
# @api public
|
117
|
+
def row(n = nil)
|
118
|
+
CSI + "#{n || 1}d"
|
119
|
+
end
|
120
|
+
|
121
|
+
# Move cursor down to beginning of next line
|
114
122
|
# @api public
|
115
123
|
def next_line
|
116
|
-
|
124
|
+
CSI + 'E' + column(1)
|
117
125
|
end
|
118
126
|
|
127
|
+
# Move cursor up to beginning of previous line
|
119
128
|
# @api public
|
120
129
|
def prev_line
|
121
|
-
|
130
|
+
CSI + 'A' + column(1)
|
122
131
|
end
|
123
132
|
|
124
|
-
#
|
133
|
+
# Erase n characters from the current cursor position
|
134
|
+
# @api public
|
135
|
+
def clear_char(n = nil)
|
136
|
+
CSI + "#{n}X"
|
137
|
+
end
|
138
|
+
|
139
|
+
# Erase the entire current line and return to beginning of the line
|
125
140
|
# @api public
|
126
141
|
def clear_line
|
127
|
-
|
142
|
+
CSI + '2K' + column(1)
|
143
|
+
end
|
144
|
+
|
145
|
+
# Erase from the beginning of the line up to and including
|
146
|
+
# the current cursor position.
|
147
|
+
# @api public
|
148
|
+
def clear_line_before
|
149
|
+
CSI + '0K'
|
150
|
+
end
|
151
|
+
|
152
|
+
# Erase from the current position (inclusive) to
|
153
|
+
# the end of the line
|
154
|
+
# @api public
|
155
|
+
def clear_line_after
|
156
|
+
CSI + '1K'
|
128
157
|
end
|
129
158
|
|
130
159
|
# Clear a number of lines
|
131
160
|
#
|
132
|
-
# @param [Integer]
|
161
|
+
# @param [Integer] n
|
133
162
|
# the number of lines to clear
|
134
163
|
# @param [Symbol] :direction
|
135
164
|
# the direction to clear, default :up
|
136
165
|
#
|
137
166
|
# @api public
|
138
|
-
def clear_lines(
|
139
|
-
|
167
|
+
def clear_lines(n, direction = :up)
|
168
|
+
n.times.reduce('') do |acc, i|
|
140
169
|
dir = direction == :up ? up : down
|
141
|
-
acc << clear_line + ((i ==
|
170
|
+
acc << clear_line + ((i == n - 1) ? '' : dir)
|
142
171
|
end
|
143
172
|
end
|
144
|
-
|
173
|
+
alias clear_rows clear_lines
|
145
174
|
|
146
175
|
# Clear screen down from current position
|
147
176
|
# @api public
|
148
177
|
def clear_screen_down
|
149
|
-
|
178
|
+
CSI + 'J'
|
150
179
|
end
|
151
180
|
|
152
181
|
# Clear screen up from current position
|
153
182
|
# @api public
|
154
183
|
def clear_screen_up
|
155
|
-
|
184
|
+
CSI + '1J'
|
156
185
|
end
|
157
186
|
|
158
187
|
# Clear the screen with the background colour and moves the cursor to home
|
159
188
|
# @api public
|
160
189
|
def clear_screen
|
161
|
-
|
190
|
+
CSI + '2J'
|
162
191
|
end
|
163
192
|
end # Cursor
|
164
193
|
end # TTY
|
data/lib/tty/version.rb
CHANGED
@@ -3,27 +3,43 @@
|
|
3
3
|
RSpec.describe TTY::Cursor, '#clear_lines' do
|
4
4
|
subject(:cursor) { described_class }
|
5
5
|
|
6
|
+
it "clears character" do
|
7
|
+
expect(cursor.clear_char).to eq("\e[X")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "clears few characters" do
|
11
|
+
expect(cursor.clear_char(5)).to eq("\e[5X")
|
12
|
+
end
|
13
|
+
|
6
14
|
it "clears line" do
|
7
|
-
expect(cursor.clear_line).to eq("\e[
|
15
|
+
expect(cursor.clear_line).to eq("\e[2K\e[1G")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "clears the line before the cursor" do
|
19
|
+
expect(cursor.clear_line_before).to eq("\e[0K")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "clears the line after the cursor" do
|
23
|
+
expect(cursor.clear_line_after).to eq("\e[1K")
|
8
24
|
end
|
9
25
|
|
10
26
|
it "clears 5 lines up" do
|
11
27
|
expect(cursor.clear_lines(5)).to eq([
|
12
|
-
"\e[
|
13
|
-
"\e[
|
14
|
-
"\e[
|
15
|
-
"\e[
|
16
|
-
"\e[
|
28
|
+
"\e[2K\e[1G\e[1A",
|
29
|
+
"\e[2K\e[1G\e[1A",
|
30
|
+
"\e[2K\e[1G\e[1A",
|
31
|
+
"\e[2K\e[1G\e[1A",
|
32
|
+
"\e[2K\e[1G"
|
17
33
|
].join)
|
18
34
|
end
|
19
35
|
|
20
36
|
it "clears 5 lines down" do
|
21
37
|
expect(cursor.clear_lines(5, :down)).to eq([
|
22
|
-
"\e[
|
23
|
-
"\e[
|
24
|
-
"\e[
|
25
|
-
"\e[
|
26
|
-
"\e[
|
38
|
+
"\e[2K\e[1G\e[1B",
|
39
|
+
"\e[2K\e[1G\e[1B",
|
40
|
+
"\e[2K\e[1G\e[1B",
|
41
|
+
"\e[2K\e[1G\e[1B",
|
42
|
+
"\e[2K\e[1G"
|
27
43
|
].join)
|
28
44
|
end
|
29
45
|
|
@@ -35,7 +51,6 @@ RSpec.describe TTY::Cursor, '#clear_lines' do
|
|
35
51
|
expect(cursor.clear_screen_up).to eq("\e[1J")
|
36
52
|
end
|
37
53
|
|
38
|
-
|
39
54
|
it "clears entire screen" do
|
40
55
|
expect(cursor.clear_screen).to eq("\e[2J")
|
41
56
|
end
|
data/spec/unit/cursor_spec.rb
CHANGED
@@ -39,10 +39,6 @@ RSpec.describe TTY::Cursor do
|
|
39
39
|
expect(cursor.down(5)).to eq("\e[5B")
|
40
40
|
end
|
41
41
|
|
42
|
-
it "moves to line start" do
|
43
|
-
expect(cursor.move_start).to eq("\e[1000D")
|
44
|
-
end
|
45
|
-
|
46
42
|
it "moves cursorleft by 1 line default" do
|
47
43
|
expect(cursor.backward).to eq("\e[1D")
|
48
44
|
end
|
@@ -59,8 +55,24 @@ RSpec.describe TTY::Cursor do
|
|
59
55
|
expect(cursor.forward(5)).to eq("\e[5C")
|
60
56
|
end
|
61
57
|
|
58
|
+
it "moves cursor horizontal to start" do
|
59
|
+
expect(cursor.column).to eq("\e[1G")
|
60
|
+
end
|
61
|
+
|
62
|
+
it "moves cursor horizontally to 66th position" do
|
63
|
+
expect(cursor.column(66)).to eq("\e[66G")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "moves cursor vertically to start" do
|
67
|
+
expect(cursor.row).to eq("\e[1d")
|
68
|
+
end
|
69
|
+
|
70
|
+
it "moves cursor vertically to 50th row" do
|
71
|
+
expect(cursor.row(50)).to eq("\e[50d")
|
72
|
+
end
|
73
|
+
|
62
74
|
it "moves cursor to next line" do
|
63
|
-
expect(cursor.next_line).to eq("\e[E")
|
75
|
+
expect(cursor.next_line).to eq("\e[E\e[1G")
|
64
76
|
end
|
65
77
|
|
66
78
|
it "moves cursor to previous line" do
|
data/tty-cursor.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = TTY::Cursor::VERSION
|
9
9
|
spec.authors = ["Piotr Murach"]
|
10
10
|
spec.email = [""]
|
11
|
-
spec.summary = %q{Terminal cursor
|
12
|
-
spec.description = %q{The purpose of this library is to help move terminal cursor around
|
11
|
+
spec.summary = %q{Terminal cursor positioning, visibility and text manipulation.}
|
12
|
+
spec.description = %q{The purpose of this library is to help move the terminal cursor around and manipulate text by using intuitive method calls.}
|
13
13
|
spec.homepage = 'http://piotrmurach.github.io/tty/'
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
metadata
CHANGED
@@ -1,46 +1,47 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty-cursor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
|
-
description: The purpose of this library is to help move terminal cursor around
|
28
|
-
|
27
|
+
description: The purpose of this library is to help move the terminal cursor around
|
28
|
+
and manipulate text by using intuitive method calls.
|
29
29
|
email:
|
30
30
|
- ''
|
31
31
|
executables: []
|
32
32
|
extensions: []
|
33
33
|
extra_rdoc_files: []
|
34
34
|
files:
|
35
|
-
- .gitignore
|
36
|
-
- .rspec
|
37
|
-
- .
|
38
|
-
- .travis.yml
|
35
|
+
- ".gitignore"
|
36
|
+
- ".rspec"
|
37
|
+
- ".travis.yml"
|
39
38
|
- CHANGELOG.md
|
39
|
+
- CODE_OF_CONDUCT.md
|
40
40
|
- Gemfile
|
41
41
|
- LICENSE.txt
|
42
42
|
- README.md
|
43
43
|
- Rakefile
|
44
|
+
- appveyor.yml
|
44
45
|
- lib/tty-cursor.rb
|
45
46
|
- lib/tty/cursor.rb
|
46
47
|
- lib/tty/version.rb
|
@@ -63,20 +64,20 @@ require_paths:
|
|
63
64
|
- lib
|
64
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
65
66
|
requirements:
|
66
|
-
- -
|
67
|
+
- - ">="
|
67
68
|
- !ruby/object:Gem::Version
|
68
69
|
version: '0'
|
69
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
71
|
requirements:
|
71
|
-
- -
|
72
|
+
- - ">="
|
72
73
|
- !ruby/object:Gem::Version
|
73
74
|
version: '0'
|
74
75
|
requirements: []
|
75
76
|
rubyforge_project:
|
76
|
-
rubygems_version: 2.
|
77
|
+
rubygems_version: 2.5.1
|
77
78
|
signing_key:
|
78
79
|
specification_version: 4
|
79
|
-
summary: Terminal cursor
|
80
|
+
summary: Terminal cursor positioning, visibility and text manipulation.
|
80
81
|
test_files:
|
81
82
|
- spec/spec_helper.rb
|
82
83
|
- spec/unit/clear_lines_spec.rb
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.0.0
|