fancy_buff 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fancy_buff.rb +16 -4
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8121c289daee5a5f2aabbcae53048661536428bfc90b8fbca1f49f2722dea5c
4
- data.tar.gz: ce3507432e0816fb69634ec64086c03543ae79908ebd5aef7c3749119750cdb3
3
+ metadata.gz: 892b50af936bb97a23a873b029d23410320cde8ecfbee5952ca6693f1b2f6e5c
4
+ data.tar.gz: cd5c61bd3f0be2e4463686d0e72fd6594aa362048dfea27423bef03c7a6c46a9
5
5
  SHA512:
6
- metadata.gz: 39155c9822923ebf3a33f676a66eafcc86004d22c760f1d116e8da0c0f80de1c76119753374b7ec8a84933263da1a8c56b96741f8366bbcad86a629f21a2c9ff
7
- data.tar.gz: 0171ca4fa6000da425da34143c1479352c6410e4ffb22ea676893858ac3ec1294ba8bf20491a70b8d76d3959b18e7201ae5d9968059b4e09fa2a1098b14f01f8
6
+ metadata.gz: 68953497b15fc893d68b270dde92799394fbeff68b2f39ce500e90a1a212fcafa0c29c69250bd7242a771901b5467a97535c0339f8e5fb9005688791892d0a30
7
+ data.tar.gz: 0d2b82addc499d165882758b688868495003572975227d3f8a8a9602ea51ff9c5722ef3e5a33714ff629305b8b6efbd7a1bcc87edefcb703ff9ed53a0c8eb7c4
data/lib/fancy_buff.rb CHANGED
@@ -24,6 +24,8 @@ class FancyBuff
24
24
  @chars = 0 # the number of characters in the buffer (not the same as the number of bytes)
25
25
  @bytes = 0 # the number of bytes in the buffer (not the same as the number of characters)
26
26
  @lines = []
27
+ @rendered_lines = [] # fully formatted, syntax highlighted, and transformed
28
+ @edited_since_last_render = true
27
29
  @max_char_width = 0
28
30
  @all_buff = @lines.join("\n")
29
31
 
@@ -60,11 +62,20 @@ class FancyBuff
60
62
  return [] if h == 0 || w == 0
61
63
 
62
64
  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)]
65
+ if @edited_since_last_render
66
+ @rendered_lines = @formatter
67
+ .format(@lexer.lex(@lines.join("\n")))
68
+ .lines
69
+ .map(&:chomp)
70
+
71
+ @edited_since_last_render = false
72
+ else
73
+ @rendered_lines[r..(r + visible_lines - 1)]
74
+ end
75
+
76
+ @rendered_lines[r..(r + visible_lines - 1)]
66
77
  .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" } +
78
+ .map{|l| "#{l}\e[0K" } +
68
79
  Array.new(blank_lines) { "\e[0K" }
69
80
  end
70
81
 
@@ -178,6 +189,7 @@ class FancyBuff
178
189
  @chars += line.chars.length
179
190
  @max_char_width = line.chars.length if line.chars.length > @max_char_width
180
191
 
192
+ @edited_since_last_render = true
181
193
  nil
182
194
  end
183
195
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fancy_buff
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt