Sha256: eae22e00728b78c5c6792bc525800db4e273178075915cbafef9c0f61566bbc9

Contents?: true

Size: 989 Bytes

Versions: 8

Compression:

Stored size: 989 Bytes

Contents

# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.

module Console
	module Terminal
		module Formatter
			# Format spawn events.
			class Spawn
				KEY = :spawn
				
				def initialize(terminal)
					@terminal = terminal
					@terminal[:spawn_command] ||= @terminal.style(:blue, nil, :bold)
				end
				
				def format(event, output, verbose: false, width: 80)
					environment, arguments, options = event.values_at(:environment, :arguments, :options)
					
					arguments = arguments.flatten.collect(&:to_s)
					
					output.puts "#{@terminal[:spawn_command]}#{arguments.join(' ')}#{@terminal.reset}#{chdir_string(options)}"
					
					if verbose and environment
						environment.each do |key, value|
							output.puts "export #{key}=#{value}"
						end
					end
				end
				
				private
				
				def chdir_string(options)
					if options and chdir = options[:chdir]
						" in #{chdir}"
					end
				end
			end
		end
	end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
console-1.29.0 lib/console/terminal/formatter/spawn.rb
console-1.28.1 lib/console/terminal/formatter/spawn.rb
console-1.28.0 lib/console/terminal/formatter/spawn.rb
console-1.27.0 lib/console/terminal/formatter/spawn.rb
console-1.26.0 lib/console/terminal/formatter/spawn.rb
console-1.25.2 lib/console/terminal/formatter/spawn.rb
console-1.25.1 lib/console/terminal/formatter/spawn.rb
console-1.25.0 lib/console/terminal/formatter/spawn.rb