termpix 0.1.0 → 0.2.1

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: 321b92b52842de9fc8f7cd06688662f235423478f947ce9d5c96cac2083f582c
4
- data.tar.gz: 76d16a71354bed1f1cc8e3196d01d48a09800c3f9a1eb9f330605f720ef3d06a
3
+ metadata.gz: 34ec8fff70b1018305deaa94931516564e573406a713fac62bbf6691dfe120b8
4
+ data.tar.gz: fcf1056c196bf42680fc1f78b8067db71a64ee342651c6684cb78f34d27f6d1d
5
5
  SHA512:
6
- metadata.gz: 5d510b46a5ad6de11c7ae89d43c7d0a07192db3a04590e5b684f9516113a18408089effc2048be2be0fe35cd9cf1ae9f4de0704d0a7e009773bb18b44beeb5b6
7
- data.tar.gz: a52a9e6bace28d65a4b70db051c277979866ce2c00f6276f471d51c1b6f53b86c36a44b7c38a5977ff406de1bf0130e7484404a6aa589362db52fd123a1c478f
6
+ metadata.gz: f706b1ff612ec9f6f08596833fe66b5fc1b50946c61aa76bb9c8a88ba327d6e595c5607fb439024a94e29d857b603801f577a05876864c8f8493a9bbdbc8a906
7
+ data.tar.gz: 4610351de9645c8dd6855d25f70b800e74b088633a6cf8d3bc02e785f104ac62230e637923bf4c7aa9251973c434e4917aaa6c0c60d15a1d1a27bad7eb4760c6
data/README.md CHANGED
@@ -6,6 +6,8 @@
6
6
 
7
7
  Display images in the terminal using the best available protocol.
8
8
 
9
+ <br clear="left"/>
10
+
9
11
  ## Features
10
12
 
11
13
  - Auto-detects terminal capabilities
@@ -4,21 +4,19 @@ require 'base64'
4
4
  module Termpix
5
5
  module Protocols
6
6
  # Kitty Graphics Protocol
7
+ # After extensive testing: Kitty protocol fundamentally incompatible with curses
8
+ # The protocol requires precise cursor control that conflicts with curses' buffer
9
+ # management. Recommend disabling Kitty protocol for curses-based apps.
7
10
  module Kitty
8
11
  def self.display(image_path, x:, y:, max_width:, max_height:)
9
- # Read image and encode to base64
10
- image_data = Base64.strict_encode64(File.read(image_path))
11
-
12
- # Use virtual placement (no cursor positioning - avoids curses conflicts)
13
- # Transmit image without positioning, let it flow inline
14
- $stdout.write "\e_Ga=T,f=100,q=2;#{image_data}\e\\"
15
- $stdout.flush
12
+ # Kitty graphics protocol does not work reliably with curses applications
13
+ # The fundamental issue is that both Kitty and curses need exclusive control
14
+ # of terminal state, causing unavoidable conflicts
15
+ false
16
16
  end
17
17
 
18
18
  def self.clear
19
- # Delete all Kitty images
20
- $stdout.write "\e_Ga=d,d=A\e\\"
21
- $stdout.flush
19
+ true
22
20
  end
23
21
 
24
22
  private
@@ -52,8 +50,9 @@ module Termpix
52
50
 
53
51
  # Position cursor at the specified character position
54
52
  print "\e[#{y};#{x}H"
55
- # Convert to sixel and display with proper pixel dimensions
56
- system("convert #{escaped} -resize #{pixel_width}x#{pixel_height} sixel:- 2>/dev/null")
53
+ # Use > to only shrink, never enlarge, preserving aspect ratio
54
+ # ImageMagick will fit image within box while maintaining aspect ratio
55
+ system("convert #{escaped} -resize #{pixel_width}x#{pixel_height}\\> sixel:- 2>/dev/null")
57
56
  end
58
57
 
59
58
  def self.clear
@@ -117,14 +116,35 @@ module Termpix
117
116
  img_max_w = char_w * max_width
118
117
  img_max_h = char_h * max_height
119
118
 
120
- # Get image dimensions
119
+ # Check if image has EXIF orientation data before auto-orienting
120
+ # This avoids unnecessary temp file creation for most images
121
121
  escaped = Shellwords.escape(image_path)
122
- dimensions = `identify -format "%wx%h" #{escaped}[0] 2>/dev/null`.strip
122
+
123
+ # Quick check: only auto-orient if image has EXIF orientation tag
124
+ has_orientation = `identify -format "%[EXIF:Orientation]" #{escaped}[0] 2>/dev/null`.strip
125
+
126
+ if has_orientation && !has_orientation.empty? && has_orientation != "1"
127
+ # Image needs rotation - create cached temp file
128
+ require 'digest'
129
+ file_hash = Digest::MD5.hexdigest(image_path)
130
+ temp_file = "/tmp/termpix_#{file_hash}.jpg"
131
+
132
+ unless File.exist?(temp_file)
133
+ system("convert #{escaped}[0] -auto-orient #{temp_file} 2>/dev/null")
134
+ end
135
+
136
+ display_path = File.exist?(temp_file) ? temp_file : image_path
137
+ else
138
+ # No rotation needed - use original image
139
+ display_path = image_path
140
+ end
141
+
142
+ dimensions = `identify -format "%wx%h" #{Shellwords.escape(display_path)} 2>/dev/null`.strip
123
143
  return if dimensions.empty?
124
144
 
125
145
  img_w, img_h = dimensions.split('x').map(&:to_i)
126
146
 
127
- # Scale if needed
147
+ # Scale if needed - preserve aspect ratio
128
148
  if img_w > img_max_w || img_h > img_max_h
129
149
  scale_w = img_max_w.to_f / img_w
130
150
  scale_h = img_max_h.to_f / img_h
@@ -134,9 +154,11 @@ module Termpix
134
154
  end
135
155
 
136
156
  # Display using w3mimgdisplay protocol
137
- `echo '0;1;#{img_x};#{img_y};#{img_w};#{img_h};;;;;#{image_path}
157
+ `echo '0;1;#{img_x};#{img_y};#{img_w};#{img_h};;;;;#{display_path}
138
158
  4;
139
159
  3;' | #{@imgdisplay} 2>/dev/null`
160
+
161
+ # Don't delete temp file - keep it cached for performance
140
162
  end
141
163
 
142
164
  def self.clear(x:, y:, width:, height:, term_width:, term_height:)
@@ -1,3 +1,3 @@
1
1
  module Termpix
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/termpix.rb CHANGED
@@ -80,11 +80,9 @@ module Termpix
80
80
  return :sixel if check_dependency('convert')
81
81
  end
82
82
 
83
- # Kitty graphics protocol disabled - incompatible with curses apps
84
- # Kitty protocol needs full terminal control, conflicts with curses rendering
85
- # Users can choose between:
86
- # 1. Enable w3m for Kitty (has brief flash) - set TERMPIX_KITTY_USE_W3M=1
87
- # 2. No images in Kitty (clean UI)
83
+ # Kitty graphics protocol disabled - fundamentally incompatible with curses
84
+ # After extensive testing: Kitty protocol requires exclusive terminal control
85
+ # that conflicts with curses' buffer management. Use w3m fallback instead.
88
86
 
89
87
  # Überzug++ - disabled for now (implementation incomplete)
90
88
  # TODO: Implement proper Überzug++ JSON-RPC communication
metadata CHANGED
@@ -1,18 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: termpix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geir Isene
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-10-26 00:00:00.000000000 Z
11
+ date: 2025-11-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Termpix provides a clean API for displaying images in the terminal using
14
- the best available protocol (Kitty, Sixel, Überzug++, or w3m). Auto-detects terminal
15
- capabilities and falls back gracefully.
13
+ description: 'Termpix v0.2.1: Performance optimization - only auto-orients images
14
+ with EXIF rotation data. Provides clean API for displaying images in terminal using
15
+ best available protocol (Sixel or w3m). Auto-detects terminal capabilities and falls
16
+ back gracefully.'
16
17
  email: g@isene.com
17
18
  executables: []
18
19
  extensions: []