Class: CLI::UI::StdoutRouter::Writer
- Inherits:
-
Object
- Object
- CLI::UI::StdoutRouter::Writer
- Defined in:
- lib/cli/ui/stdout_router.rb
Instance Method Summary collapse
-
#initialize(stream, name) ⇒ Writer
constructor
: (io_like stream, Symbol name) -> void.
-
#write(*args) ⇒ Object
: (*Object args) -> Integer.
Constructor Details
#initialize(stream, name) ⇒ Writer
: (io_like stream, Symbol name) -> void
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
: (*Object args) -> Integer
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cli/ui/stdout_router.rb', line 18 def write(*args) strs = args.map do |obj| str = obj.to_s if auto_frame_inset? str = str.dup # unfreeze str = str.to_s.force_encoding(Encoding::UTF_8) apply_line_prefix(str, CLI::UI::Frame.prefix) else @pending_newline = false str end end # hook return of false suppresses output. if (hook = Thread.current[:cliui_output_hook]) return 0 if hook.call(strs.join, @name) == false end stream_args = prepend_id(@stream, strs) #: as untyped ret = @stream.write_without_cli_ui(*stream_args) #: as Integer if (dup = StdoutRouter.duplicate_output_to) begin dup_args = prepend_id(dup, strs) #: as untyped dup.write(*dup_args) #: as Integer rescue IOError # Ignore end end ret end |