textbringer-presentation 2 → 4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12491d20e8d1e9de9ab44cdcbbe2020596de71ad5dd356bbd7815c02911dc095
4
- data.tar.gz: 7ed617f25461dd6db1c7693da54b1263daa799a2595c252077aad34d8163085c
3
+ metadata.gz: ebd0aea8f6c194787d2c18b1259b797632bdc4107be882047ceff4008297c7d3
4
+ data.tar.gz: 14b4c4f2fc7a97b4fcda575f6160763447184f4b35964d75abb3586a337fe863
5
5
  SHA512:
6
- metadata.gz: 4a56a97e1bae76bc0dfefa9977cb147384aa11318c9c1169baec27760035b170e886e63aa2d2ccb0ca51d82798c615d3aea2cbc9a724d2b9a72b3adf41bb50df
7
- data.tar.gz: e29a0e8e2707f2403c882e7273d6c285062dc9c5a52642a2904a893ef761f40c90efdb7380ec447b476a99df3befbdc91364fa663b33a85bd1e9f05482008fd0
6
+ metadata.gz: 84da4841008a52448cd2f7311c44f84cfd9d127901ff89fdf82c62a11d3440a9c72b914adcda6d42d33b4285122d1f6b97d97e695174571e172804983a7f06fd
7
+ data.tar.gz: e50fb46d7227f35881e14d22a873dfddff5d6f692bc3325a9f1424c031a53302d4780b8f0a69c0184112007ea5ba63f6667110616b17020e398c4efd980ae07a
@@ -103,25 +103,43 @@ module Textbringer
103
103
  width = CONFIG[:presentation_window_width]
104
104
  height = CONFIG[:presentation_window_height]
105
105
  if width.nil? || height.nil?
106
- wininfo = `xwininfo -id $WINDOWID`
107
- width = wininfo.slice(/Width: (\d+)/, 1).to_i
108
- height = wininfo.slice(/Height: (\d+)/, 1).to_i
106
+ width, height = terminal_window_size
109
107
  end
110
108
  lines = Window.lines
111
109
  columns = Window.columns
112
110
  y = @buffer[:presentation_top_margin] +
113
111
  (/\A\s*\z/.match(body) ? 3 : body.count("\n") + 5)
114
112
  left_margin = @buffer[:presentation_image_left_margin]
115
- img_width = width * (columns - left_margin * 2) / columns
116
- img_height = height * (lines - y - 2) / lines
117
- STDOUT.printf("\e[%d;%dH", y, left_margin + 1)
118
- img_size = "#{img_width}x#{img_height}"
113
+ if width > 0 && height > 0
114
+ img_width = width * (columns - left_margin * 2) / columns
115
+ img_height = height * (lines - y - 2) / lines
116
+ STDOUT.printf("\e[%d;%dH", y, left_margin + 1)
117
+ img_size="#{img_width}x#{img_height}"
118
+ resize_option = "-resize #{img_size} -extent #{img_size}"
119
+ else
120
+ STDOUT.printf("\e[%d;%dH", y, 1)
121
+ resize_option = ""
122
+ end
119
123
  img_bg = @buffer[:presentation_image_background]
120
124
  options = CONFIG.fetch(:presentation_img2sixel_options, "")
121
- STDOUT.print(`convert -resize #{img_size} -gravity center -background '#{img_bg}' -extent #{img_size} '#{img}' - | img2sixel #{options} 2> /dev/null`)
125
+ STDOUT.print(`convert #{resize_option} -gravity center -background '#{img_bg}' '#{img}' - | img2sixel #{options} 2> /dev/null`)
122
126
  STDOUT.flush
123
127
  end
124
128
 
129
+ TIOCGWINSZ = 0x5413
130
+
131
+ def terminal_window_size
132
+ buffer = [0, 0, 0, 0].pack('SSSS')
133
+
134
+ if STDOUT.ioctl(TIOCGWINSZ, buffer) >= 0
135
+ rows, cols, xpixel, ypixel = buffer.unpack('SSSS')
136
+ return xpixel, ypixel if xpixel > 0
137
+ end
138
+ nil
139
+ rescue
140
+ nil
141
+ end
142
+
125
143
  def show_code(code, lang)
126
144
  Window.current.split
127
145
  Window.current.shrink_if_larger_than_buffer
@@ -27,7 +27,7 @@ module Textbringer
27
27
  i = 1
28
28
  @buffer.save_excursion do
29
29
  @buffer.beginning_of_buffer
30
- while @buffer.re_search_forward(/^(?:#+[ \t]*([^\r\n]*)|```.*```)/m,
30
+ while @buffer.re_search_forward(/^(?:#+[ \t]*([^\r\n]*)|```.*?```)/m,
31
31
  raise_error: false)
32
32
  title = match_string(1)
33
33
  if title
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Textbringer
4
4
  module Presentation
5
- VERSION = "2"
5
+ VERSION = "4"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: textbringer-presentation
3
3
  version: !ruby/object:Gem::Version
4
- version: '2'
4
+ version: '4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shugo Maeda