Class: Dex::UI::StdoutRouter::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/dex/ui/stdout_router.rb

Instance Method Summary collapse

Constructor Details

#initialize(stream, name) ⇒ Writer

Returns a new instance of Writer.



11
12
13
14
# File 'lib/dex/ui/stdout_router.rb', line 11

def initialize(stream, name)
  @stream = stream
  @name = name
end

Instance Method Details

#write(*args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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