Code Coverage
 
Lines
Covered
29.63% covered (danger)
29.63%
8 / 27
1
module TheFox
1
module Timr
1
module Helper
# This class helps with Terminal operations.
1
class TerminalHelper
# All methods in this block are static.
1
class << self
1
include TheFox::Timr::Error
# Run external editor via EDITOR environment variable.
1
def run_external_editor(text = nil)
0
case text
when Array
0
text = text.join("\n")
end
0
if !ENV['EDITOR'] || ENV['EDITOR'].length == 0
0
raise TerminalHelperError, 'EDITOR environment variable not set.'
end
0
tmpfile = Tempfile.new('timr_message')
0
if text
0
tmpfile.write(text)
end
0
tmpfile.close
0
system_s = '%s %s' % [ENV['EDITOR'], tmpfile.path]
0
system(system_s)
0
tmpfile.open
0
tmpfile_lines = tmpfile.read
0
tmpfile.close
tmpfile_lines
.split("\n")
0
.select{ |row| row[0] != '#' }
0
.join("\n")
end
# Print help to external editor.
1
def external_editor_help(edit_text)
0
edit_text << '# This is a comment.'
0
edit_text << '# The first line should be a sentence. Sentence have dots at the end.'
0
edit_text << '# The second line should be empty, if you provide a more detailed'
0
edit_text << '# description from on the third line. Like on Git.'
end
end
end # class TerminalHelper
end # module Helper
end # module Timr
end # module TheFox