Class: Nanoc::CLI::CleaningStream
- Inherits:
-
Object
- Object
- Nanoc::CLI::CleaningStream
- Defined in:
- lib/nanoc/cli/cleaning_stream.rb
Overview
An output stream that passes output through stream cleaners. This can be used to strip ANSI color sequences, for instance.
IO proxy methods (collapse)
-
- (Object) <<(s)
-
- (Object) close
-
- (Boolean) exist?
-
- (Boolean) exists?
-
- (Object) flush
-
- (Object) print(s)
-
- (Object) puts(*s)
-
- (Object) reopen(*a)
-
- (Object) string
-
- (Object) tell
-
- (Boolean) tty?
-
- (Object) winsize
-
- (Object) winsize=(arg)
-
- (Object) write(s)
Instance Method Summary (collapse)
-
- (void) add_stream_cleaner(klass)
Adds a stream cleaner for the given class to this cleaning stream.
-
- (CleaningStream) initialize(stream)
constructor
A new instance of CleaningStream.
-
- (void) remove_stream_cleaner(klass)
Removes the stream cleaner for the given class from this cleaning stream.
Constructor Details
- (CleaningStream) initialize(stream)
Returns a new instance of CleaningStream
8 9 10 11 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 8 def initialize(stream) @stream = stream @stream_cleaners = [] end |
Instance Method Details
- (Object) <<(s)
48 49 50 51 52 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 48 def <<(s) _nanoc_swallow_broken_pipe_errors_while do @stream.<<(_nanoc_clean(s)) end end |
- (void) add_stream_cleaner(klass)
This method returns an undefined value.
Adds a stream cleaner for the given class to this cleaning stream. If the cleaning stream already has the given stream cleaner, nothing happens.
20 21 22 23 24 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 20 def add_stream_cleaner(klass) unless @stream_cleaners.map(&:class).include?(klass) @stream_cleaners << klass.new end end |
- (Object) close
96 97 98 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 96 def close @stream.close end |
- (Boolean) exist?
101 102 103 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 101 def exist? @stream.exist? end |
- (Boolean) exists?
106 107 108 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 106 def exists? @stream.exists? end |
- (Object) flush
60 61 62 63 64 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 60 def flush _nanoc_swallow_broken_pipe_errors_while do @stream.flush end end |
- (Object) print(s)
72 73 74 75 76 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 72 def print(s) _nanoc_swallow_broken_pipe_errors_while do @stream.print(_nanoc_clean(s)) end end |
- (Object) puts(*s)
79 80 81 82 83 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 79 def puts(*s) _nanoc_swallow_broken_pipe_errors_while do @stream.puts(*s.map { |ss| _nanoc_clean(ss) }) end end |
- (void) remove_stream_cleaner(klass)
This method returns an undefined value.
Removes the stream cleaner for the given class from this cleaning stream. If the cleaning stream does not have the given stream cleaner, nothing happens.
34 35 36 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 34 def remove_stream_cleaner(klass) @stream_cleaners.delete_if { |c| c.class == klass } end |
- (Object) reopen(*a)
91 92 93 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 91 def reopen(*a) @stream.reopen(*a) end |
- (Object) string
86 87 88 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 86 def string @stream.string end |
- (Object) tell
67 68 69 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 67 def tell @stream.tell end |
- (Boolean) tty?
55 56 57 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 55 def tty? @cached_is_tty ||= @stream.tty? end |
- (Object) winsize
111 112 113 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 111 def winsize @stream.winsize end |
- (Object) winsize=(arg)
116 117 118 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 116 def winsize=(arg) @stream.winsize = (arg) end |
- (Object) write(s)
41 42 43 44 45 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 41 def write(s) _nanoc_swallow_broken_pipe_errors_while do @stream.write(_nanoc_clean(s)) end end |