Module: Legion::TTY::Notify

Extended by:
Logging::Helper
Defined in:
lib/legion/tty/notify.rb

Overview

Notify — OS-level terminal notification dispatcher with auto-detection.

Auto-detects the terminal environment via TERM_PROGRAM and TERM env vars, then dispatches notifications using the most appropriate backend:

- iTerm2:   OSC 9 escape sequence
- kitty:    kitten notify subprocess
- Ghostty:  OSC 99 escape sequence
- Linux:    notify-send subprocess
- macOS:    osascript subprocess
- fallback: terminal bell (\a)

Settings integration (read from Legion::Settings when available):

notifications.terminal.enabled  (default: true)
notifications.terminal.backend  (default: 'auto')

Constant Summary collapse

BACKENDS =
%w[iterm2 kitty ghostty notify_send osascript bell].freeze

Class Method Summary collapse

Class Method Details

.detect_terminalString

Detect the current terminal program from environment variables.

Returns:

  • (String)

    one of: ‘iterm2’, ‘kitty’, ‘ghostty’, ‘linux’, ‘macos’, ‘unknown’



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/legion/tty/notify.rb', line 39

def detect_terminal
  term_prog = ::ENV.fetch('TERM_PROGRAM', '').downcase
  term = ::ENV.fetch('TERM', '').downcase

  return 'iterm2'  if term_prog == 'iterm.app'
  return 'kitty'   if term_prog == 'kitty' || term == 'xterm-kitty'
  return 'ghostty' if term_prog == 'ghostty'
  return 'linux'   if linux?
  return 'macos'   if macos?

  'unknown'
end

.send(message, title: 'LegionIO') ⇒ Object

Send a notification.

Parameters:

  • message (String)

    notification body

  • title (String) (defaults to: 'LegionIO')

    notification title



30
31
32
33
34
35
# File 'lib/legion/tty/notify.rb', line 30

def send(message, title: 'LegionIO')
  return unless enabled?

  backend = configured_backend
  dispatch(backend, message: message, title: title)
end