fancy_buff 2.1.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fancy_buff.rb +42 -3
- metadata +16 -2
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
@@ -13,12 +13,19 @@ class FancyBuff
|
|
13
13
|
attr_accessor :win
|
14
14
|
|
15
15
|
# gives you a default, empty, zero slice
|
16
|
-
|
16
|
+
#
|
17
|
+
# formatter - a Rouge formatter
|
18
|
+
# lexer - a Rouge lexer
|
19
|
+
def initialize(formatter, lexer)
|
20
|
+
@formatter = formatter
|
21
|
+
@lexer = lexer
|
22
|
+
|
17
23
|
# size tracking
|
18
24
|
@chars = 0 # the number of characters in the buffer (not the same as the number of bytes)
|
19
25
|
@bytes = 0 # the number of bytes in the buffer (not the same as the number of characters)
|
20
26
|
@lines = []
|
21
27
|
@max_char_width = 0
|
28
|
+
@all_buff = @lines.join("\n")
|
22
29
|
|
23
30
|
@marks = {}
|
24
31
|
@selections = {}
|
@@ -52,11 +59,43 @@ class FancyBuff
|
|
52
59
|
|
53
60
|
return [] if h == 0 || w == 0
|
54
61
|
|
55
|
-
@lines
|
56
|
-
|
62
|
+
line_no_width = @lines.length.to_s.length
|
63
|
+
text = @formatter
|
64
|
+
.format(@lexer.lex(@lines.join("\n")))
|
65
|
+
.lines[r..(r + visible_lines - 1)]
|
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)}" }
|
67
|
+
.map{|l| l.chomp + "\e[0K" } +
|
57
68
|
Array.new(blank_lines) { "\e[0K" }
|
58
69
|
end
|
59
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
|
+
|
60
99
|
# the number of visible lines from @lines at any given time
|
61
100
|
def visible_lines
|
62
101
|
[h, @lines.length - r].min
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fancy_buff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Lunt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rouge
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.1'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: minitest
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|