termpix 0.3.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f02b355cf61a8cfd00292a79423a428d071cbc333674c1e2324901f62bd10a38
4
- data.tar.gz: d55c9be1b6e0e2de2b0d093ec25cfc4bb462f165197db5cbae20039eee4d7d53
3
+ metadata.gz: e311d6ce62bc8230d38d93a80b5e93af7422c1d9b9ec06f1bd746d18244c4901
4
+ data.tar.gz: 35400b9a97498b45855a3c9dda743454a2c0a4d68138dbbfb33d0108fdd6415d
5
5
  SHA512:
6
- metadata.gz: 8d4d33f281c9fb9346f978dc764c3ce66f9c42b6be11c5a1cc1869f1054798ac8a3230a76450f0be66c063efda2284ad28dcfb0e9c5f34155a07a2bcfb79a19a
7
- data.tar.gz: e155d39ed7003b6c5c405a5f703d526d54c6732add1494e0a0f4eae1390660c591f257e0e44114da1aa9c3801d63979b8405a56047a7194bdafca5d9fb86130c
6
+ metadata.gz: fe0e449f3bc2674e55418bd7fc8194eaef1f5d249824c99eedc006f23e5e8dc15477a21b9b31e33a6ff87f848c1c168822385461091d88d235e3577ffba40cae
7
+ data.tar.gz: 10bb9db43f2b54f8826f719f9e9a12a5c024564e0f72558949f1ffeb31b1b69cc6812ea5f9ae04a1478da662ebff86e6aab975aa54c47b9c79041b0e38f483a7
@@ -21,8 +21,9 @@ module Termpix
21
21
  pixel_width = max_width * cell_width
22
22
  pixel_height = max_height * cell_height
23
23
 
24
- # Check if we have this image cached
25
- cache_key = "#{image_path}:#{pixel_width}x#{pixel_height}"
24
+ # Check if we have this image cached (include mtime to detect overwrites)
25
+ mtime = File.mtime(image_path).to_i rescue 0
26
+ cache_key = "#{image_path}:#{pixel_width}x#{pixel_height}:#{mtime}"
26
27
  image_id = @image_cache[cache_key]
27
28
 
28
29
  unless image_id
@@ -104,7 +105,7 @@ module Termpix
104
105
  end
105
106
  # Fall back to common defaults (10x20 pixels per cell)
106
107
  [10, 20]
107
- rescue
108
+ rescue LoadError, IOError, StandardError
108
109
  [10, 20]
109
110
  end
110
111
  end
@@ -114,7 +115,7 @@ module Termpix
114
115
  def self.get_dimensions(image_path)
115
116
  escaped = Shellwords.escape(image_path)
116
117
  dimensions = `identify -format "%wx%h" #{escaped}[0] 2>/dev/null`.strip
117
- return nil if dimensions.empty?
118
+ return nil if dimensions.empty? || !dimensions.match?(/\A\d+x\d+\z/)
118
119
  dimensions.split('x').map(&:to_i)
119
120
  end
120
121
 
@@ -153,35 +154,6 @@ module Termpix
153
154
  end
154
155
  end
155
156
 
156
- # Überzug++ Protocol
157
- module Ueberzug
158
- def self.display(image_path, x:, y:, max_width:, max_height:)
159
- # Get terminal pixel dimensions
160
- terminfo = `xwininfo -id $(xdotool getactivewindow 2>/dev/null) 2>/dev/null`
161
- return unless terminfo && !terminfo.empty?
162
-
163
- term_w = terminfo.match(/Width: (\d+)/)[1].to_i
164
- term_h = terminfo.match(/Height: (\d+)/)[1].to_i
165
-
166
- # Calculate character dimensions
167
- char_w = term_w / `tput cols`.to_i
168
- char_h = term_h / `tput lines`.to_i
169
-
170
- # Convert character positions to pixels
171
- img_x = char_w * x
172
- img_y = char_h * y
173
- img_w = char_w * max_width
174
- img_h = char_h * max_height
175
-
176
- # TODO: Implement actual Überzug++ protocol
177
- # For now, placeholder
178
- end
179
-
180
- def self.clear
181
- system('clear')
182
- end
183
- end
184
-
185
157
  # w3mimgdisplay Protocol
186
158
  module W3m
187
159
  @imgdisplay = '/usr/lib/w3m/w3mimgdisplay'
@@ -191,12 +163,17 @@ module Termpix
191
163
  terminfo = `xwininfo -id $(xdotool getactivewindow 2>/dev/null) 2>/dev/null`
192
164
  return unless terminfo && !terminfo.empty?
193
165
 
194
- term_w = terminfo.match(/Width: (\d+)/)[1].to_i
195
- term_h = terminfo.match(/Height: (\d+)/)[1].to_i
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
196
171
 
197
172
  # Calculate character dimensions
198
173
  cols = `tput cols`.to_i
174
+ cols = 80 if cols <= 0
199
175
  lines = `tput lines`.to_i
176
+ lines = 24 if lines <= 0
200
177
  char_w = term_w / cols
201
178
  char_h = term_h / lines
202
179
 
@@ -229,8 +206,8 @@ module Termpix
229
206
  display_path = image_path
230
207
  end
231
208
 
232
- dimensions = `identify -format "%wx%h" #{Shellwords.escape(display_path)} 2>/dev/null`.strip
233
- 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/)
234
211
 
235
212
  img_w, img_h = dimensions.split('x').map(&:to_i)
236
213
 
@@ -244,9 +221,8 @@ module Termpix
244
221
  end
245
222
 
246
223
  # Display using w3mimgdisplay protocol
247
- `echo '0;1;#{img_x};#{img_y};#{img_w};#{img_h};;;;;#{display_path}
248
- 4;
249
- 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) }
250
226
 
251
227
  # Don't delete temp file - keep it cached for performance
252
228
  end
@@ -256,8 +232,11 @@ module Termpix
256
232
  terminfo = `xwininfo -id $(xdotool getactivewindow 2>/dev/null) 2>/dev/null`
257
233
  return true unless terminfo && !terminfo.empty?
258
234
 
259
- term_w = terminfo.match(/Width: (\d+)/)[1].to_i
260
- term_h = terminfo.match(/Height: (\d+)/)[1].to_i
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
261
240
 
262
241
  # Calculate character dimensions
263
242
  char_w = term_w / term_width
@@ -270,7 +249,8 @@ module Termpix
270
249
  img_max_h = char_h * height + 2
271
250
 
272
251
  # Use w3mimgdisplay command "6" to clear just the image area
273
- `echo "6;#{img_x};#{img_y};#{img_max_w};#{img_max_h};\n4;\n3;" | #{@imgdisplay} 2>/dev/null`
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) }
274
254
  true
275
255
  end
276
256
  end
@@ -1,3 +1,3 @@
1
1
  module Termpix
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
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,19 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: termpix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
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-01-16 00:00:00.000000000 Z
11
+ date: 2026-03-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: 'Termpix v0.3.1: WezTerm support added. Uses Kitty graphics protocol
14
- for kitty, WezTerm, and Ghostty terminals. Provides clean API for displaying images
15
- in terminal using best available protocol (Kitty, Sixel, or w3m). Auto-detects terminal
16
- capabilities 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.'
17
16
  email: g@isene.com
18
17
  executables: []
19
18
  extensions: []