class Dev::UI::StdoutRouter::Writer
Public Class Methods
new(stream, name)
click to toggle source
# File lib/dev/ui/stdout_router.rb, line 12 def initialize(stream, name) @stream = stream @name = name end
Public Instance Methods
write(*args)
click to toggle source
# File lib/dev/ui/stdout_router.rb, line 17 def write(*args) if auto_frame_inset? str = args[0].dup # unfreeze str = str.force_encoding(Encoding::UTF_8) str = apply_line_prefix(str, Dev::UI::Frame.prefix) args[0] = str else @pending_newline = false end hook = Thread.current[:devui_output_hook] # hook return of false suppresses output. if !hook || hook.call(args.first, @name) != false args.first @stream.write_without_dev_ui(*args) if dup = StdoutRouter.duplicate_output_to dup.write(*args) end end end
Private Instance Methods
apply_line_prefix(str, prefix)
click to toggle source
# File lib/dev/ui/stdout_router.rb, line 44 def apply_line_prefix(str, prefix) return '' if str.empty? prefixed = String.new str.force_encoding(Encoding::UTF_8).lines.each do |line| if @pending_newline prefixed << line @pending_newline = false else prefixed << prefix << line end end @pending_newline = !str.end_with?("\n") prefixed end
auto_frame_inset?()
click to toggle source
# File lib/dev/ui/stdout_router.rb, line 40 def auto_frame_inset? !Thread.current[:no_devui_frame_inset] end