Class: Twterm::Tab::Preferences::NotificationBackend

Inherits:
AbstractTab
  • Object
show all
Includes:
Publisher, Scrollable
Defined in:
lib/twterm/tab/preferences/notification_backend.rb

Instance Attribute Summary

Attributes inherited from AbstractTab

#window

Instance Method Summary collapse

Methods included from Publisher

#publish

Methods included from Utils

check_type

Methods included from Scrollable

#scroller, #total_item_count

Methods inherited from AbstractTab

#==, #close, #find_or_fetch_list, #find_or_fetch_status, #find_or_fetch_user, #initialize, #render

Methods included from Subscriber

included, #subscribe, #unsubscribe

Constructor Details

This class inherits a constructor from Twterm::Tab::AbstractTab

Instance Method Details

#drawable_item_countObject



14
15
16
# File 'lib/twterm/tab/preferences/notification_backend.rb', line 14

def drawable_item_count
  (window.maxy - 1) / 2
end

#imageObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/twterm/tab/preferences/notification_backend.rb', line 18

def image
  drawable_items.map.with_index do |item, i|
    curr = scroller.current_index?(i)
    cursor = Image.cursor(1, curr)
    checkbox = Image.checkbox(app.preferences[:notification_backend, item])
    desc =
      case item
      when :inline
        'Inline backend'
      when :tmux
        'Tmux backend'
      when :terminal_notifier
        'Terminal Notifier backend'
      end

      cursor - Image.whitespace - checkbox - Image.whitespace - Image.string(desc).bold(curr)
  end
    .intersperse(Image.blank_line)
    .reduce(Image.empty) { |acc, x| acc | x }
end

#itemsObject



39
40
41
42
43
44
45
46
47
# File 'lib/twterm/tab/preferences/notification_backend.rb', line 39

def items
  env = app.environment

  [
    :inline,
    (:tmux if env.with_tmux?),
    (:terminal_notifier if env.terminal_notifier_available?),
  ].compact
end

#respond_to_key(key) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/twterm/tab/preferences/notification_backend.rb', line 49

def respond_to_key(key)
  return true if scroller.respond_to_key(key)

  case key
  when 10
    perform_selected_action
  end

  false
end

#titleObject



60
61
62
# File 'lib/twterm/tab/preferences/notification_backend.rb', line 60

def title
  'Notification backend preferences'
end