termpix 0.3.2 → 0.4.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/termpix/protocols.rb +20 -41
- data/lib/termpix/version.rb +1 -1
- data/lib/termpix.rb +0 -12
- metadata +5 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e311d6ce62bc8230d38d93a80b5e93af7422c1d9b9ec06f1bd746d18244c4901
|
|
4
|
+
data.tar.gz: 35400b9a97498b45855a3c9dda743454a2c0a4d68138dbbfb33d0108fdd6415d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fe0e449f3bc2674e55418bd7fc8194eaef1f5d249824c99eedc006f23e5e8dc15477a21b9b31e33a6ff87f848c1c168822385461091d88d235e3577ffba40cae
|
|
7
|
+
data.tar.gz: 10bb9db43f2b54f8826f719f9e9a12a5c024564e0f72558949f1ffeb31b1b69cc6812ea5f9ae04a1478da662ebff86e6aab975aa54c47b9c79041b0e38f483a7
|
data/lib/termpix/protocols.rb
CHANGED
|
@@ -105,7 +105,7 @@ module Termpix
|
|
|
105
105
|
end
|
|
106
106
|
# Fall back to common defaults (10x20 pixels per cell)
|
|
107
107
|
[10, 20]
|
|
108
|
-
rescue
|
|
108
|
+
rescue LoadError, IOError, StandardError
|
|
109
109
|
[10, 20]
|
|
110
110
|
end
|
|
111
111
|
end
|
|
@@ -115,7 +115,7 @@ module Termpix
|
|
|
115
115
|
def self.get_dimensions(image_path)
|
|
116
116
|
escaped = Shellwords.escape(image_path)
|
|
117
117
|
dimensions = `identify -format "%wx%h" #{escaped}[0] 2>/dev/null`.strip
|
|
118
|
-
return nil if dimensions.empty?
|
|
118
|
+
return nil if dimensions.empty? || !dimensions.match?(/\A\d+x\d+\z/)
|
|
119
119
|
dimensions.split('x').map(&:to_i)
|
|
120
120
|
end
|
|
121
121
|
|
|
@@ -154,35 +154,6 @@ module Termpix
|
|
|
154
154
|
end
|
|
155
155
|
end
|
|
156
156
|
|
|
157
|
-
# Überzug++ Protocol
|
|
158
|
-
module Ueberzug
|
|
159
|
-
def self.display(image_path, x:, y:, max_width:, max_height:)
|
|
160
|
-
# Get terminal pixel dimensions
|
|
161
|
-
terminfo = `xwininfo -id $(xdotool getactivewindow 2>/dev/null) 2>/dev/null`
|
|
162
|
-
return unless terminfo && !terminfo.empty?
|
|
163
|
-
|
|
164
|
-
term_w = terminfo.match(/Width: (\d+)/)[1].to_i
|
|
165
|
-
term_h = terminfo.match(/Height: (\d+)/)[1].to_i
|
|
166
|
-
|
|
167
|
-
# Calculate character dimensions
|
|
168
|
-
char_w = term_w / `tput cols`.to_i
|
|
169
|
-
char_h = term_h / `tput lines`.to_i
|
|
170
|
-
|
|
171
|
-
# Convert character positions to pixels
|
|
172
|
-
img_x = char_w * x
|
|
173
|
-
img_y = char_h * y
|
|
174
|
-
img_w = char_w * max_width
|
|
175
|
-
img_h = char_h * max_height
|
|
176
|
-
|
|
177
|
-
# TODO: Implement actual Überzug++ protocol
|
|
178
|
-
# For now, placeholder
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
def self.clear
|
|
182
|
-
system('clear')
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
|
|
186
157
|
# w3mimgdisplay Protocol
|
|
187
158
|
module W3m
|
|
188
159
|
@imgdisplay = '/usr/lib/w3m/w3mimgdisplay'
|
|
@@ -192,12 +163,17 @@ module Termpix
|
|
|
192
163
|
terminfo = `xwininfo -id $(xdotool getactivewindow 2>/dev/null) 2>/dev/null`
|
|
193
164
|
return unless terminfo && !terminfo.empty?
|
|
194
165
|
|
|
195
|
-
|
|
196
|
-
|
|
166
|
+
w_match = terminfo.match(/Width: (\d+)/)
|
|
167
|
+
h_match = terminfo.match(/Height: (\d+)/)
|
|
168
|
+
return unless w_match && h_match
|
|
169
|
+
term_w = w_match[1].to_i
|
|
170
|
+
term_h = h_match[1].to_i
|
|
197
171
|
|
|
198
172
|
# Calculate character dimensions
|
|
199
173
|
cols = `tput cols`.to_i
|
|
174
|
+
cols = 80 if cols <= 0
|
|
200
175
|
lines = `tput lines`.to_i
|
|
176
|
+
lines = 24 if lines <= 0
|
|
201
177
|
char_w = term_w / cols
|
|
202
178
|
char_h = term_h / lines
|
|
203
179
|
|
|
@@ -230,8 +206,8 @@ module Termpix
|
|
|
230
206
|
display_path = image_path
|
|
231
207
|
end
|
|
232
208
|
|
|
233
|
-
dimensions = `identify -format "%wx%h" #{Shellwords.escape(display_path)} 2>/dev/null`.strip
|
|
234
|
-
return if dimensions.empty?
|
|
209
|
+
dimensions = `identify -format "%wx%h" #{Shellwords.escape(display_path)}[0] 2>/dev/null`.strip
|
|
210
|
+
return if dimensions.empty? || !dimensions.match?(/\A\d+x\d+\z/)
|
|
235
211
|
|
|
236
212
|
img_w, img_h = dimensions.split('x').map(&:to_i)
|
|
237
213
|
|
|
@@ -245,9 +221,8 @@ module Termpix
|
|
|
245
221
|
end
|
|
246
222
|
|
|
247
223
|
# Display using w3mimgdisplay protocol
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
3;' | #{@imgdisplay} 2>/dev/null`
|
|
224
|
+
cmd = "0;1;#{img_x};#{img_y};#{img_w};#{img_h};;;;;#{display_path}\n4;\n3;\n"
|
|
225
|
+
IO.popen([@imgdisplay], 'w', err: '/dev/null') { |io| io.write(cmd) }
|
|
251
226
|
|
|
252
227
|
# Don't delete temp file - keep it cached for performance
|
|
253
228
|
end
|
|
@@ -257,8 +232,11 @@ module Termpix
|
|
|
257
232
|
terminfo = `xwininfo -id $(xdotool getactivewindow 2>/dev/null) 2>/dev/null`
|
|
258
233
|
return true unless terminfo && !terminfo.empty?
|
|
259
234
|
|
|
260
|
-
|
|
261
|
-
|
|
235
|
+
w_match = terminfo.match(/Width: (\d+)/)
|
|
236
|
+
h_match = terminfo.match(/Height: (\d+)/)
|
|
237
|
+
return true unless w_match && h_match
|
|
238
|
+
term_w = w_match[1].to_i
|
|
239
|
+
term_h = h_match[1].to_i
|
|
262
240
|
|
|
263
241
|
# Calculate character dimensions
|
|
264
242
|
char_w = term_w / term_width
|
|
@@ -271,7 +249,8 @@ module Termpix
|
|
|
271
249
|
img_max_h = char_h * height + 2
|
|
272
250
|
|
|
273
251
|
# Use w3mimgdisplay command "6" to clear just the image area
|
|
274
|
-
|
|
252
|
+
cmd = "6;#{img_x};#{img_y};#{img_max_w};#{img_max_h};\n4;\n3;\n"
|
|
253
|
+
IO.popen([@imgdisplay], 'w', err: '/dev/null') { |io| io.write(cmd) }
|
|
275
254
|
true
|
|
276
255
|
end
|
|
277
256
|
end
|
data/lib/termpix/version.rb
CHANGED
data/lib/termpix.rb
CHANGED
|
@@ -25,8 +25,6 @@ module Termpix
|
|
|
25
25
|
Protocols::Kitty.display(image_path, x: x, y: y, max_width: max_width, max_height: max_height)
|
|
26
26
|
when :sixel
|
|
27
27
|
Protocols::Sixel.display(image_path, x: x, y: y, max_width: max_width, max_height: max_height)
|
|
28
|
-
when :ueberzug
|
|
29
|
-
Protocols::Ueberzug.display(image_path, x: x, y: y, max_width: max_width, max_height: max_height)
|
|
30
28
|
when :w3m
|
|
31
29
|
Protocols::W3m.display(image_path, x: x, y: y, max_width: max_width, max_height: max_height)
|
|
32
30
|
else
|
|
@@ -46,8 +44,6 @@ module Termpix
|
|
|
46
44
|
Protocols::Kitty.clear
|
|
47
45
|
when :sixel
|
|
48
46
|
Protocols::Sixel.clear
|
|
49
|
-
when :ueberzug
|
|
50
|
-
Protocols::Ueberzug.clear
|
|
51
47
|
when :w3m
|
|
52
48
|
Protocols::W3m.clear(x: x, y: y, width: width, height: height, term_width: term_width, term_height: term_height)
|
|
53
49
|
end
|
|
@@ -95,14 +91,6 @@ module Termpix
|
|
|
95
91
|
return :sixel if check_dependency('convert')
|
|
96
92
|
end
|
|
97
93
|
|
|
98
|
-
# Überzug++ - disabled for now (implementation incomplete)
|
|
99
|
-
# TODO: Implement proper Überzug++ JSON-RPC communication
|
|
100
|
-
# if command_exists?('ueberzug') || command_exists?('ueberzugpp')
|
|
101
|
-
# if check_dependencies('xwininfo', 'xdotool', 'identify')
|
|
102
|
-
# return :ueberzug
|
|
103
|
-
# end
|
|
104
|
-
# end
|
|
105
|
-
|
|
106
94
|
# Fall back to w3m (works on urxvt, xterm, etc.)
|
|
107
95
|
if command_exists?('/usr/lib/w3m/w3mimgdisplay')
|
|
108
96
|
if check_dependencies('xwininfo', 'xdotool', 'identify')
|
metadata
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: termpix
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Geir Isene
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-03-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
|
-
description: 'Termpix v0.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
best available protocol (Kitty, Sixel, or w3m). Auto-detects terminal capabilities
|
|
17
|
-
and falls back gracefully.'
|
|
13
|
+
description: 'Termpix v0.4.0: Robustness improvements. Fixed bare rescues, added nil-guards
|
|
14
|
+
on xwininfo parsing, tput fallbacks, identify output validation. Removed non-functional
|
|
15
|
+
Ueberzug module. Replaced shell interpolation with IO.popen in W3m protocol.'
|
|
18
16
|
email: g@isene.com
|
|
19
17
|
executables: []
|
|
20
18
|
extensions: []
|