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
10 11 12 13 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 10 def initialize(stream) @stream = stream @stream_cleaners = [] end |
Instance Method Details
- (Object) <<(s)
50 51 52 53 54 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 50 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.
22 23 24 25 26 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 22 def add_stream_cleaner(klass) unless @stream_cleaners.map { |c| c.class }.include?(klass) @stream_cleaners << klass.new end end |
- (Object) close
98 99 100 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 98 def close @stream.close end |
- (Boolean) exist?
103 104 105 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 103 def exist? @stream.exist? end |
- (Boolean) exists?
108 109 110 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 108 def exists? @stream.exists? end |
- (Object) flush
62 63 64 65 66 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 62 def flush _nanoc_swallow_broken_pipe_errors_while do @stream.flush end end |
- (Object) print(s)
74 75 76 77 78 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 74 def print(s) _nanoc_swallow_broken_pipe_errors_while do @stream.print(_nanoc_clean(s)) end end |
- (Object) puts(*s)
81 82 83 84 85 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 81 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.
36 37 38 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 36 def remove_stream_cleaner(klass) @stream_cleaners.delete_if { |c| c.class == klass } end |
- (Object) reopen(*a)
93 94 95 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 93 def reopen(*a) @stream.reopen(*a) end |
- (Object) string
88 89 90 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 88 def string @stream.string end |
- (Object) tell
69 70 71 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 69 def tell @stream.tell end |
- (Boolean) tty?
57 58 59 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 57 def tty? @cached_is_tty ||= @stream.tty? end |
- (Object) winsize
113 114 115 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 113 def winsize @stream.winsize end |
- (Object) winsize=(arg)
118 119 120 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 118 def winsize=(arg) @stream.winsize = (arg) end |
- (Object) write(s)
43 44 45 46 47 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 43 def write(s) _nanoc_swallow_broken_pipe_errors_while do @stream.write(_nanoc_clean(s)) end end |