kittikrb-cursor 0.1.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmNlYmQ1YTNkYWY0YmNhMTVjMGRkOTdjN2ZlZTgxYmFhZmRjMTliNg==
4
+ MmFlMDllM2FjZDMyMDhkZjE2ZGNmMjdlNTY2YWVlNTY4NDNiMDNmNg==
5
5
  data.tar.gz: !binary |-
6
- MDg2ODQ1ZTUyMDU2Mjk3ODIwMGJiZGNjOTU1MjJmZjQ3NWMzN2MyZQ==
6
+ MmUyMTIzNGJhYjZiYzdjYTQ3ODQ1NGIzZjExMWZjZjg0NTJhODg4Yg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODUyZjI5YjQ1MjZlNmVmMWQ2NTJhM2JiYTI2MzA1YTk4Y2RmZGM5OGQ5OGU1
10
- NDhmYThlZmUzNGQ2MDVlMGNiNDJkOWFiNmRhYmU5Njc5ZTkxMTBkMDBiNzBj
11
- MmMxMDMxZTBmNTA4YTMwMDk2ZTFkYWQzMDNmNDM4YmFhMDAwZjc=
9
+ ZmMwYTFjMmIyZTcwMjI4MWQxMDM0NDM5YjY5Yjk3YmMyNjkyNDVmNzhlMjQz
10
+ YWRiZmZjMGUyY2UzMTRlZDc5ZDczMzg1ZjMzZDVlNmZmYTE5YmUwNjljZDIz
11
+ ZDI3ZjIxYjZjOWJmODM5MzUyMjBjZDZkZGViNmJiNDA4YzNmNzQ=
12
12
  data.tar.gz: !binary |-
13
- ZjIwMTk1YzFjNmI5NzEzNDIyNjFmYmJlMDNiNTg4MzI4OTFjZGJhZDcxYzkw
14
- Yzg2OGFmZWQ3MDUzNDAyMGU5YzdjZjVkOThjMmIxZDVkNTI3YjIyOTIwNTEz
15
- NjkzYjE0MWM5MThjZTE1ZmM5ODNiOWRiNzA0MzZkMWUyODhmYzE=
13
+ ZTE4NDAyMDU5YjMxZWExZjgyMmY2YzJkYWI5MmYxNDk0ZWZhY2ZmNGI0NGUy
14
+ MjBkODAyNThkOWE1YTFmNzJiMGQ3Y2RmMGNjN2Q3ZmYyZWZhMWU5MGExZjYx
15
+ OTNmNmVhYjM1ODQ3OTk1ZmVmYjY4ZDEwNGZkOTYyZGZkODczNjE=
@@ -10,10 +10,10 @@ Gem::Specification.new do |spec|
10
10
  spec.authors = ['Vladyslav Siriniok']
11
11
  spec.email = ['siriniok@gmail.com']
12
12
  spec.license = 'MIT'
13
- spec.summary = %q{ Low-level API for cursor in terminal.' }
13
+ spec.summary = %q{ Low-level API for cursor in terminal. }
14
14
  spec.description = %q{ Implements low-level API for access to cursor in
15
15
  terminal.' }
16
- spec.homepage = 'https://github.com/kittikjs/cursor'
16
+ spec.homepage = 'https://github.com/kittikrb/cursor'
17
17
  spec.required_ruby_version = '~> 2.2'
18
18
  spec.required_rubygems_version = '~> 2.2'
19
19
 
@@ -1,4 +1,4 @@
1
- require 'kittikrb/cursor/core_ext/hash'
1
+ require 'kittikrb/cursor/core_patches/hash'
2
2
 
3
3
  require 'kittikrb/cursor/version'
4
4
  require 'kittikrb/cursor/colors'
@@ -17,6 +17,7 @@ require 'io/console'
17
17
 
18
18
  module KittikRb
19
19
  module Cursor
20
+ using CorePatches::HashPatch
20
21
 
21
22
  def self.create
22
23
  Cursor.new
@@ -36,7 +37,6 @@ module KittikRb
36
37
  }
37
38
  ESCAPE_CHAR = "\e"
38
39
 
39
- # Only for compatibility with KittikJs API
40
40
  def self.encode_to_vt100(str)
41
41
  ESCAPE_CHAR + str
42
42
  end
@@ -89,7 +89,7 @@ module KittikRb
89
89
 
90
90
  # Get index of the buffer from (x, y) coordinates.
91
91
  def get_pointer_from_xy(x = @x, y = @y)
92
- y * @width + x;
92
+ y * @width + x
93
93
  end
94
94
 
95
95
  # Get (x, y) coordinate from the buffer pointer.
@@ -103,6 +103,150 @@ module KittikRb
103
103
  self
104
104
  end
105
105
 
106
+ def move_by(x, y)
107
+ x > 0 ? right(x) : left(x.abs)
108
+ y > 0 ? down(y) : up(y.abs)
109
+
110
+ self
111
+ end
112
+
113
+ def up(y = 1)
114
+ @y -= y.floor
115
+
116
+ self
117
+ end
118
+
119
+ def down(y = 1)
120
+ @y += y.floor
121
+
122
+ self
123
+ end
124
+
125
+ def left(x = 1)
126
+ @x -= x.floor
127
+
128
+ self
129
+ end
130
+
131
+ def right(x = 1)
132
+ @x += x.floor
133
+
134
+ self
135
+ end
136
+
137
+ # Erase the specified region.
138
+ # The region describes the rectangle shape which need to erase.
139
+ def erase(x1, y1, x2, y2)
140
+ y1.floor.upto(y2.floor) do |y|
141
+ x1.floor.upto(x2.floor) do |x|
142
+ @buffer[get_pointer_from_xy(x, y)] = self.class.wrap ' ', { x: x,
143
+ y: y }
144
+ end
145
+ end
146
+
147
+ self
148
+ end
149
+
150
+ # Erase from current position to end of the line.
151
+ def erase_to_end
152
+ erase @x, @y, @width - 1, @y
153
+
154
+ self
155
+ end
156
+
157
+ # Erase from current position to start of the line.
158
+ def erase_to_start
159
+ erase 0, @y, @x, @y
160
+
161
+ self
162
+ end
163
+
164
+ # Erase from current line to down.
165
+ def erase_to_down
166
+ erase 0, @y, @width - 1, @height - 1
167
+
168
+ self
169
+ end
170
+
171
+ # Erase from current line to up.
172
+ def erase_to_up
173
+ erase 0, 0, @width - 1, @y
174
+
175
+ self
176
+ end
177
+
178
+ def erase_line
179
+ erase 0, @y, @width - 1, @y
180
+
181
+ self
182
+ end
183
+
184
+ def erase_screen
185
+ erase 0, 0, @width - 1, @height - 1
186
+
187
+ self
188
+ end
189
+
190
+ def foreground(color)
191
+ @foreground = color
192
+
193
+ self
194
+ end
195
+
196
+ def background(color)
197
+ @background = color
198
+
199
+ self
200
+ end
201
+
202
+ def bold(is_bold = true)
203
+ @display[:bold] = is_bold
204
+
205
+ self
206
+ end
207
+
208
+ def dim(is_dim = true)
209
+ @display[:dim] = is_dim
210
+
211
+ self
212
+ end
213
+
214
+ def underlined(is_underlined = true)
215
+ @display[:underlined] = is_underlined
216
+
217
+ self
218
+ end
219
+
220
+ def blink(is_blink = true)
221
+ @display[:blink] = is_blink
222
+
223
+ self
224
+ end
225
+
226
+ def reverse(is_reverse = true)
227
+ @display[:reverse] = is_reverse
228
+
229
+ self
230
+ end
231
+
232
+ def hidden(is_hidden = true)
233
+ @display[:hidden] = is_hidden
234
+
235
+ self
236
+ end
237
+
238
+ def hide_cursor
239
+ write_control('[?25l')
240
+
241
+ self
242
+ end
243
+
244
+ def show_cursor
245
+ write_control('[?25h')
246
+
247
+ self
248
+ end
249
+
106
250
  def write_control(str)
107
251
  $stdout.write(ESCAPE_CHAR + str)
108
252
  end
@@ -0,0 +1,20 @@
1
+ module KittikRb
2
+ module Cursor
3
+ module CorePatches
4
+ module HashPatch
5
+ refine Hash do
6
+ # From ActiveSupport v5.0.0.beta3
7
+ def slice(*keys)
8
+ if respond_to?(:convert_key, true)
9
+ keys.map! { |key| convert_key(key) }
10
+ end
11
+
12
+ keys.each_with_object(self.class.new) do |k, hash|
13
+ hash[k] = self[k] if has_key?(k)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  module KittikRb
2
2
  module Cursor
3
- VERSION = '0.1.0'
3
+ VERSION = '3.0.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kittikrb-cursor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladyslav Siriniok
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-04 00:00:00.000000000 Z
11
+ date: 2016-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -129,11 +129,11 @@ files:
129
129
  - kittikrb-cursor.gemspec
130
130
  - lib/kittikrb/cursor.rb
131
131
  - lib/kittikrb/cursor/colors.rb
132
- - lib/kittikrb/cursor/core_ext/hash.rb
132
+ - lib/kittikrb/cursor/core_patches/hash.rb
133
133
  - lib/kittikrb/cursor/display_modes.rb
134
134
  - lib/kittikrb/cursor/version.rb
135
135
  - lib/kittikrb_cursor.rb
136
- homepage: https://github.com/kittikjs/cursor
136
+ homepage: https://github.com/kittikrb/cursor
137
137
  licenses:
138
138
  - MIT
139
139
  metadata: {}
@@ -156,5 +156,5 @@ rubyforge_project:
156
156
  rubygems_version: 2.4.5
157
157
  signing_key:
158
158
  specification_version: 4
159
- summary: Low-level API for cursor in terminal.'
159
+ summary: Low-level API for cursor in terminal.
160
160
  test_files: []
@@ -1,7 +0,0 @@
1
- class Hash
2
- # From ActiveSupport v5.0.0.beta3
3
- def slice(*keys)
4
- keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
5
- keys.each_with_object(self.class.new) { |k, hash| hash[k] = self[k] if has_key?(k) }
6
- end
7
- end