Class: GitPrepareBranch::Screen
- Inherits:
-
Object
- Object
- GitPrepareBranch::Screen
- Defined in:
- lib/git-prepare-branch/screen.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#description ⇒ Object
Returns the value of attribute description.
-
#display ⇒ Object
Returns the value of attribute display.
-
#heading ⇒ Object
Returns the value of attribute heading.
-
#heading_style ⇒ Object
Returns the value of attribute heading_style.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #add_command(key, name, command, options = {}) ⇒ Object
- #commands ⇒ Object
- #handle_keypress(key, context) ⇒ Object
- #help ⇒ Object
-
#initialize(name) ⇒ Screen
constructor
A new instance of Screen.
- #longest_command_name_length ⇒ Object
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
#context ⇒ Object
Returns the value of attribute context.
8 9 10 |
# File 'lib/git-prepare-branch/screen.rb', line 8 def context @context end |
#description ⇒ Object
Returns the value of attribute description.
9 10 11 |
# File 'lib/git-prepare-branch/screen.rb', line 9 def description @description end |
#display ⇒ Object
Returns the value of attribute display.
9 10 11 |
# File 'lib/git-prepare-branch/screen.rb', line 9 def display @display end |
#heading ⇒ Object
Returns the value of attribute heading.
9 10 11 |
# File 'lib/git-prepare-branch/screen.rb', line 9 def heading @heading end |
#heading_style ⇒ Object
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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/git-prepare-branch/screen.rb', line 8 def name @name end |
#title ⇒ Object
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, ={}) commands[key] = Command.new(key, name, command, ) end |
#commands ⇒ Object
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 |
#help ⇒ Object
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_length ⇒ Object
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 |