Module: AIGit::Prompt
- Defined in:
- lib/ai_git/prompt.rb
Constant Summary collapse
- ACTIONS =
{ "" => :accept, "a" => :accept, "accept" => :accept, "y" => :accept, "yes" => :accept, "e" => :edit, "edit" => :edit, "r" => :regenerate, "regen" => :regenerate, "regenerate" => :regenerate, "q" => :abort, "quit" => :abort, "n" => :abort, "no" => :abort, "abort" => :abort }.freeze
- QUESTION =
"Commit this message? [A]ccept / [e]dit / [r]egenerate / [q]uit: "
Class Method Summary collapse
Class Method Details
.ask_action ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ai_git/prompt.rb', line 38 def ask_action loop do $stdout.print AIGit::UI.bold(QUESTION) $stdout.flush answer = $stdin.gets return :abort if answer.nil? action = ACTIONS[answer.strip.downcase] return action if action AIGit::UI.info("Please answer a, e, r or q.") end end |
.edit(message) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ai_git/prompt.rb', line 53 def edit() editor = ENV["VISUAL"] || ENV["EDITOR"] raise "Cannot edit: set $EDITOR or $VISUAL first." if editor.to_s.strip.empty? Tempfile.create(["ai_git_commit_msg", ".txt"]) do |file| file.write() file.flush raise "Editor #{editor} exited with an error." unless system(*Shellwords.split(editor), file.path) File.read(file.path) end end |
.interactive? ⇒ Boolean
34 35 36 |
# File 'lib/ai_git/prompt.rb', line 34 def interactive? $stdin.tty? && $stdout.tty? end |