Module: Termpix::Protocols::Sixel

Defined in:
lib/termpix/protocols.rb

Overview

Sixel Protocol

Class Method Summary collapse

Class Method Details

.clearObject



135
136
137
138
139
140
# File 'lib/termpix/protocols.rb', line 135

def self.clear
  # Sixel images are inline - they don't need explicit clearing
  # The terminal will handle this when content is redrawn
  # Don't use \e[2J as that clears the entire screen including curses content!
  true
end

.display(image_path, x:, y:, max_width:, max_height:) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/termpix/protocols.rb', line 120

def self.display(image_path, x:, y:, max_width:, max_height:)
  escaped = Shellwords.escape(image_path)

  # Convert character dimensions to approximate pixel dimensions
  # Average character cell is roughly 10x20 pixels in most terminals
  pixel_width = max_width * 10
  pixel_height = max_height * 20

  # Position cursor at the specified character position
  print "\e[#{y};#{x}H"
  # Use > to only shrink, never enlarge, preserving aspect ratio
  # ImageMagick will fit image within box while maintaining aspect ratio
  system("convert #{escaped} -resize #{pixel_width}x#{pixel_height}\\> sixel:- 2>/dev/null")
end