Module: LanguageOperator::CLI::Helpers::EditorHelper
- Defined in:
- lib/language_operator/cli/helpers/editor_helper.rb
Overview
Helper module for editing content in the user's preferred editor. Handles tempfile creation, cleanup, and editor invocation.
Class Method Summary collapse
-
.edit_content(content, filename_prefix, extension = '.txt', default_editor: 'vi') ⇒ String
Edit content in the user's preferred editor.
Class Method Details
.edit_content(content, filename_prefix, extension = '.txt', default_editor: 'vi') ⇒ String
Edit content in the user's preferred editor
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/language_operator/cli/helpers/editor_helper.rb', line 34 def self.edit_content(content, filename_prefix, extension = '.txt', default_editor: 'vi') editor = ENV['EDITOR'] || default_editor tempfile = Tempfile.new([filename_prefix, extension]) begin # Write content and flush to ensure it's on disk tempfile.write(content) tempfile.flush tempfile.close # Open in editor success = system("#{editor} #{tempfile.path}") raise "Editor command failed: #{editor}" unless success # Read edited content File.read(tempfile.path) ensure # Clean up temp file tempfile.unlink end end |