Class: Termpix::Display
- Inherits:
-
Object
- Object
- Termpix::Display
- Defined in:
- lib/termpix.rb
Instance Attribute Summary collapse
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
Instance Method Summary collapse
-
#atomic_replace? ⇒ Boolean
Check if protocol supports atomic replace (show new without clearing first) Kitty can replace images without flash; w3m/sixel need explicit clear.
-
#clear(x: 0, y: 0, width: 80, height: 24, term_width: 80, term_height: 24) ⇒ Object
Clear all displayed images.
-
#info ⇒ Object
Get information about the current protocol.
-
#initialize(protocol: nil) ⇒ Display
constructor
A new instance of Display.
-
#show(image_path, x: 0, y: 0, max_width: 80, max_height: 24) ⇒ Object
Display an image at the specified position.
-
#supported? ⇒ Boolean
Check if image display is supported.
Constructor Details
#initialize(protocol: nil) ⇒ Display
Returns a new instance of Display.
8 9 10 11 |
# File 'lib/termpix.rb', line 8 def initialize(protocol: nil) @protocol = protocol || detect_protocol @current_image = nil end |
Instance Attribute Details
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
6 7 8 |
# File 'lib/termpix.rb', line 6 def protocol @protocol end |
Instance Method Details
#atomic_replace? ⇒ Boolean
Check if protocol supports atomic replace (show new without clearing first) Kitty can replace images without flash; w3m/sixel need explicit clear
60 61 62 |
# File 'lib/termpix.rb', line 60 def atomic_replace? @protocol == :kitty end |
#clear(x: 0, y: 0, width: 80, height: 24, term_width: 80, term_height: 24) ⇒ Object
Clear all displayed images
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/termpix.rb', line 38 def clear(x: 0, y: 0, width: 80, height: 24, term_width: 80, term_height: 24) return false unless @protocol case @protocol when :kitty Protocols::Kitty.clear when :sixel Protocols::Sixel.clear when :w3m Protocols::W3m.clear(x: x, y: y, width: width, height: height, term_width: term_width, term_height: term_height) end true end |
#info ⇒ Object
Get information about the current protocol
65 66 67 68 69 70 71 |
# File 'lib/termpix.rb', line 65 def info { protocol: @protocol, supported: supported?, current_image: @current_image } end |
#show(image_path, x: 0, y: 0, max_width: 80, max_height: 24) ⇒ Object
Display an image at the specified position
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/termpix.rb', line 19 def show(image_path, x: 0, y: 0, max_width: 80, max_height: 24) return false unless @protocol return false unless File.exist?(image_path) case @protocol when :kitty Protocols::Kitty.display(image_path, x: x, y: y, max_width: max_width, max_height: max_height) when :sixel Protocols::Sixel.display(image_path, x: x, y: y, max_width: max_width, max_height: max_height) when :w3m Protocols::W3m.display(image_path, x: x, y: y, max_width: max_width, max_height: max_height) else return false end true end |
#supported? ⇒ Boolean
Check if image display is supported
54 55 56 |
# File 'lib/termpix.rb', line 54 def supported? !@protocol.nil? end |