fancy_buff 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fancy_buff.rb +30 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8121c289daee5a5f2aabbcae53048661536428bfc90b8fbca1f49f2722dea5c
|
4
|
+
data.tar.gz: ce3507432e0816fb69634ec64086c03543ae79908ebd5aef7c3749119750cdb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39155c9822923ebf3a33f676a66eafcc86004d22c760f1d116e8da0c0f80de1c76119753374b7ec8a84933263da1a8c56b96741f8366bbcad86a629f21a2c9ff
|
7
|
+
data.tar.gz: 0171ca4fa6000da425da34143c1479352c6410e4ffb22ea676893858ac3ec1294ba8bf20491a70b8d76d3959b18e7201ae5d9968059b4e09fa2a1098b14f01f8
|
data/lib/fancy_buff.rb
CHANGED
@@ -59,14 +59,43 @@ class FancyBuff
|
|
59
59
|
|
60
60
|
return [] if h == 0 || w == 0
|
61
61
|
|
62
|
+
line_no_width = @lines.length.to_s.length
|
62
63
|
text = @formatter
|
63
64
|
.format(@lexer.lex(@lines.join("\n")))
|
64
65
|
.lines[r..(r + visible_lines - 1)]
|
65
|
-
.map.with_index{|row, i| "#{(i + r + 1).to_s.rjust(
|
66
|
+
.map.with_index{|row, i| "#{(i + r + 1).to_s.rjust(line_no_width)} #{substr_with_color(row, c, c + w - line_no_width - 2)}" }
|
66
67
|
.map{|l| l.chomp + "\e[0K" } +
|
67
68
|
Array.new(blank_lines) { "\e[0K" }
|
68
69
|
end
|
69
70
|
|
71
|
+
# input - a String that may or may not contain ANSI color codes
|
72
|
+
# start - the starting index of printable characters to keep
|
73
|
+
# finish - the ending index of printable characters to keep
|
74
|
+
#
|
75
|
+
# treats `input' like a String that does
|
76
|
+
def substr_with_color(input, start, finish)
|
77
|
+
ansi_pattern = /\A\e\[[0-9;]+m/
|
78
|
+
printable_counter = 0
|
79
|
+
remaining = input.clone.chomp
|
80
|
+
result = ''
|
81
|
+
|
82
|
+
loop do
|
83
|
+
break if remaining.empty? || printable_counter > finish
|
84
|
+
|
85
|
+
match = remaining.match(ansi_pattern)
|
86
|
+
if match
|
87
|
+
result += match[0]
|
88
|
+
remaining = remaining.sub(match[0], '')
|
89
|
+
else
|
90
|
+
result += remaining[0] if printable_counter >= start
|
91
|
+
remaining = remaining[1..-1]
|
92
|
+
printable_counter += 1
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
result + "\e[0m"
|
97
|
+
end
|
98
|
+
|
70
99
|
# the number of visible lines from @lines at any given time
|
71
100
|
def visible_lines
|
72
101
|
[h, @lines.length - r].min
|