16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/inlay/terminal_output.rb', line 16
def write(image, width: nil, height: nil, scale: :auto, protocol: nil, output: $stdout, env: ENV)
selected = (protocol || self.protocol(output: output, env: env)).to_sym
return false unless enabled?(output: output, env: env) && selected != :none
return false if selected == :blocks && env.key?("NO_COLOR")
return false if image.width * image.height > Inlay.config.max_pixels
return false if image.width.zero? || image.height.zero?
image = Sizer.fit(image, width: width, height: height, scale: scale, protocol: selected, env: env)
bytes = image.bytes
encoded = case selected.to_sym
when :blocks then Termvas::Encoders::Blocks.encode(bytes, image.width, image.height)
when :kitty then Termvas::Encoders::Kitty.encode(bytes, image.width, image.height, id: next_kitty_id)
when :iterm2
png = Tessel::PNG.encode(image)
Termvas::Encoders::ITerm2.encode(png, width: image.width, height: image.height)
when :sixel then Termvas::Encoders::Sixel.encode(bytes, image.width, image.height)
else return false
end
output.write(encoded)
output.write("\n")
true
end
|