Module: Przn::KittyText

Defined in:
lib/przn/kitty_text.rb

Constant Summary collapse

HEADING_SCALES =
{
  1 => 4,
  2 => 3,
  3 => 2
}.freeze

Class Method Summary collapse

Class Method Details

.echoes?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/przn/kitty_text.rb', line 38

def echoes?
  ENV['TERM_PROGRAM'] == 'Echoes'
end

.heading(text, level:) ⇒ Object



42
43
44
45
46
47
# File 'lib/przn/kitty_text.rb', line 42

def heading(text, level:)
  scale = HEADING_SCALES[level]
  return text unless scale

  sized(text, s: scale, h: 1)
end

.sized(text, s:, h: nil, v: nil, n: nil, d: nil, f: nil, flip: nil) ⇒ Object

Emit sized multicell text. The ‘s/w/n/d/v/h` params are standard kitty OSC 66 (portable). The `f=` (font family) and `flip=` params are Echoes-only extensions — when one of them is set AND we’re running inside Echoes, they ride on the private OSC 7772 ;multicell frame so that strict kitty terminals never see unknown params on OSC 66. Otherwise the extensions are silently dropped and we emit plain OSC 66, which renders without the flip / custom font on any kitty- compatible terminal (better than emitting an OSC 7772 frame the terminal would ignore entirely).



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/przn/kitty_text.rb', line 22

def sized(text, s:, h: nil, v: nil, n: nil, d: nil, f: nil, flip: nil)
  params = +"s=#{s}"
  params << ":n=#{n}" if n
  params << ":d=#{d}" if d
  params << ":h=#{h}" if h
  params << ":v=#{v}" if v

  if (f || flip) && echoes?
    params << ":f=#{f}" if f
    params << ":flip=#{flip}" if flip
    "\e]7772;multicell;#{params};#{text}\a"
  else
    "\e]66;#{params};#{text}\a"
  end
end