Class: CLI::UI::StdoutRouter::Writer

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

Instance Method Summary collapse

Constructor Details

#initialize(stream, name) ⇒ Writer

Returns a new instance of Writer.



12
13
14
15
# File 'lib/cli/ui/stdout_router.rb', line 12

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

Instance Method Details

#write(*args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cli/ui/stdout_router.rb', line 17

def write(*args)
  args = args.map do |str|
    if auto_frame_inset?
      str = str.dup # unfreeze
      str = str.force_encoding(Encoding::UTF_8)
      apply_line_prefix(str, CLI::UI::Frame.prefix)
    else
      @pending_newline = false
      str
    end
  end

  hook = Thread.current[:cliui_output_hook]
  # hook return of false suppresses output.
  if !hook || hook.call(args.first, @name) != false
    @stream.write_without_cli_ui(*prepend_id(@stream, args))
    if dup = StdoutRouter.duplicate_output_to
      dup.write(*prepend_id(dup, args))
    end
  end
end