Class: GitPrepareBranch::Screen

Inherits:
Object
  • Object
show all
Defined in:
lib/git-prepare-branch/screen.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Screen

Returns a new instance of Screen.



11
12
13
# File 'lib/git-prepare-branch/screen.rb', line 11

def initialize(name)
  @name = name
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



8
9
10
# File 'lib/git-prepare-branch/screen.rb', line 8

def context
  @context
end

#descriptionObject

Returns the value of attribute description.



9
10
11
# File 'lib/git-prepare-branch/screen.rb', line 9

def description
  @description
end

#displayObject

Returns the value of attribute display.



9
10
11
# File 'lib/git-prepare-branch/screen.rb', line 9

def display
  @display
end

#headingObject

Returns the value of attribute heading.



9
10
11
# File 'lib/git-prepare-branch/screen.rb', line 9

def heading
  @heading
end

#heading_styleObject

Returns the value of attribute heading_style.



9
10
11
# File 'lib/git-prepare-branch/screen.rb', line 9

def heading_style
  @heading_style
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/git-prepare-branch/screen.rb', line 8

def name
  @name
end

#titleObject

Returns the value of attribute title.



9
10
11
# File 'lib/git-prepare-branch/screen.rb', line 9

def title
  @title
end

Instance Method Details

#add_command(key, name, command, options = {}) ⇒ Object



15
16
17
# File 'lib/git-prepare-branch/screen.rb', line 15

def add_command(key, name, command, options={})
  commands[key] = Command.new(key, name, command, options)
end

#commandsObject



19
20
21
# File 'lib/git-prepare-branch/screen.rb', line 19

def commands
  @commands ||= {}
end

#handle_keypress(key, context) ⇒ Object



23
24
25
26
27
28
# File 'lib/git-prepare-branch/screen.rb', line 23

def handle_keypress key, context
  help if ['h', '?'].include?(key)
  exit if ['q', CommandKeys::CTRL_C, CommandKeys::CTRL_D].include?(key)
  return unless commands.keys.include?(key)
  commands[key].call(context)
end

#helpObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/git-prepare-branch/screen.rb', line 30

def help
  terminal.clear
  terminal.say "DESCRIPTION"
  terminal.hr
  terminal.say "#{description}\n\n"
  terminal.say "COMMANDS"
  terminal.hr
  commands.each_with_object('') do |(key, command), result|
    terminal.say "#{key}   #{command.name.ljust(longest_command_name_length)}     #{command.description}"
    terminal.say "\n"
  end
  terminal.prompt_to_continue
end

#longest_command_name_lengthObject



44
45
46
# File 'lib/git-prepare-branch/screen.rb', line 44

def longest_command_name_length
  @longest_command_name_length ||= commands.collect{|(_, c)| c.name.length}.max
end