tty_string 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/tty_string/cell.rb +0 -4
- data/lib/tty_string/row.rb +30 -0
- data/lib/tty_string/screen.rb +27 -17
- data/lib/tty_string/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fed365cd62d837aec3621a4c1a1f9055871aaf7050d4c136206ca1b6ef6e6a5b
|
4
|
+
data.tar.gz: adfbc75cc2f3ec31be690d30a26848ba9ca6b43f83612f8a9ccf698bfc8a7d1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edf12a947a46e36cdb82ec8f2b8ba26c111b189a78d1f35e7136771499605d4bfba8c96b251595555c5b83bfaa0f3059aec868958590d3ae5d012c37772a3145
|
7
|
+
data.tar.gz: 3a4487855eecdb533dd8f3382752c3f7b35bcd119a2516c7a02dba077580dff64837f1374a86bb4aa88628dc93eb51a1b9296873df53c19022a8ab75ba8505f7
|
data/CHANGELOG.md
CHANGED
data/lib/tty_string/cell.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TTYString
|
4
|
+
class Row
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
attr_accessor :newline_style
|
8
|
+
|
9
|
+
def initialize(newline_style: NullStyle)
|
10
|
+
@array = []
|
11
|
+
self.newline_style = newline_style
|
12
|
+
end
|
13
|
+
|
14
|
+
def each(&block)
|
15
|
+
@array.each(&block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def []=(index, value)
|
19
|
+
@array[index] = value
|
20
|
+
end
|
21
|
+
|
22
|
+
def slice!(*args)
|
23
|
+
@array.slice!(*args)
|
24
|
+
end
|
25
|
+
|
26
|
+
def fill(*args)
|
27
|
+
@array.fill(*args)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/tty_string/screen.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require_relative 'cursor'
|
4
4
|
require_relative 'cell'
|
5
5
|
require_relative 'style'
|
6
|
+
require_relative 'row'
|
6
7
|
|
7
8
|
module TTYString
|
8
9
|
# a grid to draw on
|
@@ -15,40 +16,49 @@ module TTYString
|
|
15
16
|
@current_style = @initial_style = initial_style
|
16
17
|
end
|
17
18
|
|
18
|
-
def to_s # rubocop:disable Metrics/MethodLength
|
19
|
+
def to_s # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
19
20
|
style_context = initial_style
|
20
|
-
|
21
|
-
|
21
|
+
str = +''
|
22
|
+
screen.each_with_index do |row, index|
|
23
|
+
unless index.zero?
|
24
|
+
str << row.newline_style.to_s(context: style_context) if row
|
25
|
+
str << "\n"
|
26
|
+
style_context = row.newline_style if row
|
27
|
+
end
|
28
|
+
|
29
|
+
Array(row).each do |cell|
|
22
30
|
if cell
|
23
|
-
|
31
|
+
str << cell.style.to_s(context: style_context)
|
32
|
+
str << cell.value
|
24
33
|
style_context = cell.style
|
25
|
-
value
|
26
34
|
else
|
27
|
-
' '
|
35
|
+
str << ' '
|
28
36
|
end
|
29
|
-
end
|
30
|
-
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
str << current_style.to_s(context: style_context)
|
40
|
+
str
|
31
41
|
end
|
32
42
|
|
33
43
|
def []=((row, col), value)
|
34
|
-
screen[row] ||=
|
44
|
+
screen[row] ||= Row.new(newline_style: current_style)
|
35
45
|
screen[row][col] = value
|
36
46
|
end
|
37
47
|
|
38
48
|
def clear_at_cursor
|
39
|
-
self[cursor] =
|
49
|
+
self[cursor] = Cell.new(' ', style: current_style)
|
40
50
|
end
|
41
51
|
|
42
52
|
def clear_line_forward
|
43
|
-
screen[row].
|
53
|
+
screen[row].slice!(col..-1)
|
44
54
|
end
|
45
55
|
|
46
56
|
def clear_line_backward
|
47
|
-
screen[row].fill(
|
57
|
+
screen[row].fill(Cell.new(' ', style: current_style), 0..col)
|
48
58
|
end
|
49
59
|
|
50
60
|
def clear_line
|
51
|
-
screen[row] =
|
61
|
+
screen[row] = Row.new(newline_style: current_style)
|
52
62
|
end
|
53
63
|
|
54
64
|
def clear
|
@@ -56,17 +66,17 @@ module TTYString
|
|
56
66
|
end
|
57
67
|
|
58
68
|
def scroll_up
|
59
|
-
screen.push(
|
69
|
+
screen.push(Row.new(newline_style: current_style))
|
60
70
|
screen.shift
|
61
71
|
end
|
62
72
|
|
63
73
|
def scroll_down
|
64
|
-
screen.unshift(
|
74
|
+
screen.unshift(Row.new(newline_style: current_style))
|
65
75
|
screen.pop
|
66
76
|
end
|
67
77
|
|
68
78
|
def clear_lines_before
|
69
|
-
screen.fill(
|
79
|
+
screen.fill(Row.new(newline_style: current_style), 0...row)
|
70
80
|
end
|
71
81
|
|
72
82
|
def clear_lines_after
|
@@ -84,7 +94,7 @@ module TTYString
|
|
84
94
|
end
|
85
95
|
|
86
96
|
def ensure_row
|
87
|
-
screen[row] ||=
|
97
|
+
screen[row] ||= Row.new(newline_style: current_style)
|
88
98
|
end
|
89
99
|
|
90
100
|
def write(string)
|
data/lib/tty_string/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty_string
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dana Sherson
|
@@ -210,6 +210,7 @@ files:
|
|
210
210
|
- lib/tty_string/cursor.rb
|
211
211
|
- lib/tty_string/null_style.rb
|
212
212
|
- lib/tty_string/parser.rb
|
213
|
+
- lib/tty_string/row.rb
|
213
214
|
- lib/tty_string/screen.rb
|
214
215
|
- lib/tty_string/style.rb
|
215
216
|
- lib/tty_string/version.rb
|