lib/scide/screen.rb in scide-0.0.6 vs lib/scide/screen.rb in scide-0.0.7

- old
+ new

@@ -1,7 +1,5 @@ -require 'tempfile' - module Scide # Configuration of a GNU Screen session (windows for a specific project). # # The configuration will disable the startup message and display a hardstatus line. @@ -9,10 +7,13 @@ class Screen # The default screen hardstatus line. DEFAULT_HARDSTATUS = '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]' + # Options for this screen. + attr_accessor :options + # Returns a screen configuration for the given project. # # ==== Arguments # * <tt>project</tt> - The project. # * <tt>options</tt> - Screen-specific options (see below). @@ -23,30 +24,20 @@ # * <tt>hardstatus</tt> - Hardstatus line configuration (defaults to #DEFAULT_HARDSTATUS). def initialize project, options raise ArgumentError, 'screen configuration must be a hash' unless options.nil? or options.kind_of?(Hash) @project = project - @options = options || {} + @options = options.try(:dup) || {} end - # Runs screen with this configuration. - # - # The configuration is saved to a temporary file, then removed. - def run - file = Tempfile.new 'scide' - save file.path - system to_command(file.path) - file.unlink - end - # Returns the command that will be used to run screen with this configuration. # # ==== Arguments # * <tt>tmp_file</tt> - The temporary file in which the configuration will be stored. # (Optional for dry-run.) def to_command tmp_file = 'TEMPORARY_FILE' - "cd #{@project.path} && #{binary} #{args} -c #{tmp_file}" + [ "cd #{@project.path} &&", binary, args, "-c #{tmp_file}" ].select(&:present?).join(' ') end # Verifies that the screen binary is there. If not, causes scide # to fail with a <tt>screen_not_found</tt> error (see Scide#fail}. def check_binary @@ -62,30 +53,23 @@ s << "hardstatus string '#{hardstatus}'\n\n" s << @project.to_screen end end - private - # Returns the screen hardstatus line given as option, or # the default #DEFAULT_HARDSTATUS. def hardstatus - @options[:hardstatus] || DEFAULT_HARDSTATUS + @options[:hardstatus].try(:to_s) || DEFAULT_HARDSTATUS end # Returns the screen binary given as option, or the # default (<tt>screen</tt>). def binary - @options[:binary] || 'screen' + @options[:binary].try(:to_s) || 'screen' end # Returns the screen command-line arguments given as options. def args - @options[:args] - end - - # Saves this configuration to the file at the given path. - def save file - File.open(file, 'w'){ |f| f.write to_s } + @options[:args].try(:to_s) end end end