Class: GitPrompt
- Inherits:
-
Object
- Object
- GitPrompt
- Defined in:
- lib/git_prompt.rb
Constant Summary collapse
- SELECT_OPTIONS_PER_PAGE =
10
Instance Attribute Summary collapse
-
#extractor ⇒ Object
readonly
Returns the value of attribute extractor.
-
#git ⇒ Object
readonly
Returns the value of attribute git.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#prompt ⇒ Object
readonly
Returns the value of attribute prompt.
Instance Method Summary collapse
- #define_key_events ⇒ Object
-
#initialize(git: nil) ⇒ GitPrompt
constructor
A new instance of GitPrompt.
Constructor Details
#initialize(git: nil) ⇒ GitPrompt
Returns a new instance of GitPrompt.
14 15 16 17 18 19 20 21 |
# File 'lib/git_prompt.rb', line 14 def initialize(git: nil) @git = git || Git.open(Dir.pwd) @extractor = TreeishExtractor.new(git: git) create_prompt define_key_events display_select(:branch, extractor.recent_branch_names) end |
Instance Attribute Details
#extractor ⇒ Object (readonly)
Returns the value of attribute extractor.
12 13 14 |
# File 'lib/git_prompt.rb', line 12 def extractor @extractor end |
#git ⇒ Object (readonly)
Returns the value of attribute git.
12 13 14 |
# File 'lib/git_prompt.rb', line 12 def git @git end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
12 13 14 |
# File 'lib/git_prompt.rb', line 12 def logger @logger end |
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
12 13 14 |
# File 'lib/git_prompt.rb', line 12 def prompt @prompt end |
Instance Method Details
#define_key_events ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/git_prompt.rb', line 23 def define_key_events prompt.on(:keypress) do |event| if event.value == 'q' exit end # move up/down in the list if event.value == 'j' prompt.trigger(:keydown) end if event.value == 'k' prompt.trigger(:keyup) end # Select a mode if event.value == 'b' clear_prompt display_select(:branch, extractor.recent_branch_names) end if event.value == 't' clear_prompt display_select(:tag, extractor.recent_tag_names) end end end |