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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ebd0aea8f6c194787d2c18b1259b797632bdc4107be882047ceff4008297c7d3
|
|
4
|
+
data.tar.gz: 14b4c4f2fc7a97b4fcda575f6160763447184f4b35964d75abb3586a337fe863
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
|
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]*)
|
|
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
|