Class: Twterm::Tab::KeyAssignmentsCheatsheet

Inherits:
Object
  • Object
show all
Includes:
Base, Scrollable
Defined in:
lib/twterm/tab/key_assignments_cheatsheet.rb

Constant Summary collapse

SHORTCUTS =
{
  'General' => {
    '[d] [C-d]'         => 'Scroll down',
    '[g]'               => 'Move to top',
    '[G]'               => 'Move to bottom',
    '[j] [C-p] [DOWN]'  => 'Move down',
    '[k] [C-n] [UP]'    => 'Move up',
    '[u] [C-u]'         => 'Scroll up',
    '[Q]'               => 'Quit twterm'
  },
  'Tabs' => {
    '[h] [C-b] [LEFT]'  => 'Previous tab',
    '[l] [C-f] [RIGHT]' => 'Next tab',
    '[N]'               => 'New tab',
    '[C-R]'             => 'Reload',
    '[w]'               => 'Close tab',
    '[q]'               => 'Quit filter mode',
    '[/]'               => 'Filter mode'
  },
  'Tweets' => {
    '[c]'               => 'Conversation',
    '[D]'               => 'Delete',
    '[F]'               => 'Add to favorite',
    '[n]'               => 'New tweet',
    '[o]'               => 'Open URLs',
    '[r]'               => 'Reply',
    '[R]'               => 'Retweet',
    '[U]'               => 'User'
  },
  'Others' => {
    '[P]'               => 'My profile',
    '[?]'               => 'Key assignments cheatsheet'
  }
}

Instance Attribute Summary

Attributes included from Scrollable

#scroller

Attributes included from Base

#window

Instance Method Summary collapse

Methods included from Base

#close, #refresh, #resize

Constructor Details

#initializeKeyAssignmentsCheatsheet

Returns a new instance of KeyAssignmentsCheatsheet.



50
51
52
53
# File 'lib/twterm/tab/key_assignments_cheatsheet.rb', line 50

def initialize
  super
  scroller.set_no_cursor_mode!
end

Instance Method Details

#==(other) ⇒ Object



7
8
9
# File 'lib/twterm/tab/key_assignments_cheatsheet.rb', line 7

def ==(other)
  other.is_a?(self.class)
end

#drawable_item_countObject



46
47
48
# File 'lib/twterm/tab/key_assignments_cheatsheet.rb', line 46

def drawable_item_count
  window.maxy - 3
end

#respond_to_key(key) ⇒ Object



55
56
57
58
59
# File 'lib/twterm/tab/key_assignments_cheatsheet.rb', line 55

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

  false
end

#titleObject



61
62
63
# File 'lib/twterm/tab/key_assignments_cheatsheet.rb', line 61

def title
  'Key assignments'.freeze
end

#total_item_countObject



65
66
67
# File 'lib/twterm/tab/key_assignments_cheatsheet.rb', line 65

def total_item_count
  @count ||= SHORTCUTS.count * 4 + SHORTCUTS.values.map(&:count).reduce(0, :+) + 1
end

#updateObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/twterm/tab/key_assignments_cheatsheet.rb', line 69

def update
  offset = scroller.offset
  line = 0

  window.setpos(line - offset + 2, 3)
  window.bold { window.addstr('Key assignments') } if scroller.nth_item_drawable?(line)

  SHORTCUTS.each do |category, shortcuts|
    line += 3
    window.setpos(line - offset + 2, 5)
    window.bold { window.addstr("<#{category}>") } if scroller.nth_item_drawable?(line)
    line += 1

    shortcuts.each do |key, description|
      line += 1
      next unless scroller.nth_item_drawable?(line)

      window.setpos(line - offset + 2, 7)
      window.bold { window.addstr(key.rjust(17)) }
      window.setpos(line - offset + 2, 25)
      window.addstr(": #{description}")
    end
  end
end