class Dex::UI::StdoutRouter::Writer
Public Class Methods
new(stream, name)
click to toggle source
# File lib/dex/ui/stdout_router.rb, line 11 def initialize(stream, name) @stream = stream @name = name end
Public Instance Methods
write(*args)
click to toggle source
# File lib/dex/ui/stdout_router.rb, line 16 def write(*args) if auto_frame_inset? str = args[0].dup # unfreeze str = str.force_encoding(Encoding::UTF_8) str = apply_line_prefix(str, Dex::UI::Frame.prefix) args[0] = str else @pending_newline = false end hook = Thread.current[:dexui_output_hook] # hook return of false suppresses output. if !hook || hook.call(args.first, @name) != false args.first @stream.write_without_dex_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/dex/ui/stdout_router.rb, line 43 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/dex/ui/stdout_router.rb, line 39 def auto_frame_inset? !Thread.current[:no_dexui_frame_inset] end