Method: Commander::UI.ask_editor
- Defined in:
- lib/commander/user_interaction.rb
.ask_editor(input = nil, preferred_editor = nil) ⇒ Object
Prompt an editor for input. Optionally supply initial input which is written to the editor.
preferred_editor can be hinted.
Examples
ask_editor # => prompts EDITOR with no input
ask_editor('foo') # => prompts EDITOR with default text of 'foo'
ask_editor('foo', 'mate -w') # => prompts TextMate with default text of 'foo'
256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/commander/user_interaction.rb', line 256 def ask_editor input = nil, preferred_editor = nil editor = available_editor preferred_editor program = Commander::Runner.instance.program(:name).downcase rescue 'commander' tmpfile = Tempfile.new program begin tmpfile.write input if input tmpfile.close system("#{editor} #{tmpfile.path.shellescape}") ? IO.read(tmpfile.path) : nil ensure tmpfile.unlink end end |