Class: Nanoc::CLI::CleaningStream

Inherits:
Object
  • Object
show all
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)

Instance Method Summary (collapse)

Constructor Details

- (CleaningStream) initialize(stream)

Returns a new instance of CleaningStream

Parameters:

  • stream (IO, StringIO)

    The stream to wrap



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)

See Also:

  • IO#<<


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.

Parameters:



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

See Also:

  • IO#close


96
97
98
# File 'lib/nanoc/cli/cleaning_stream.rb', line 96

def close
  @stream.close
end

- (Boolean) exist?

Returns:

  • (Boolean)

See Also:

  • File#exist?


101
102
103
# File 'lib/nanoc/cli/cleaning_stream.rb', line 101

def exist?
  @stream.exist?
end

- (Boolean) exists?

Returns:

  • (Boolean)

See Also:

  • File.exists?


106
107
108
# File 'lib/nanoc/cli/cleaning_stream.rb', line 106

def exists?
  @stream.exists?
end

- (Object) flush

See Also:

  • IO#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

See Also:

  • IO#print


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)

See Also:

  • IO#puts


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.

Parameters:



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)

See Also:

  • IO#reopen


91
92
93
# File 'lib/nanoc/cli/cleaning_stream.rb', line 91

def reopen(*a)
  @stream.reopen(*a)
end

- (Object) string

See Also:

  • StringIO#string


86
87
88
# File 'lib/nanoc/cli/cleaning_stream.rb', line 86

def string
  @stream.string
end

- (Object) tell

See Also:

  • IO#tell


67
68
69
# File 'lib/nanoc/cli/cleaning_stream.rb', line 67

def tell
  @stream.tell
end

- (Boolean) tty?

Returns:

  • (Boolean)

See Also:

  • IO#tty?


55
56
57
# File 'lib/nanoc/cli/cleaning_stream.rb', line 55

def tty?
  @cached_is_tty ||= @stream.tty?
end

- (Object) winsize

See Also:

  • IO.winsize


111
112
113
# File 'lib/nanoc/cli/cleaning_stream.rb', line 111

def winsize
  @stream.winsize
end

- (Object) winsize=(arg)

See Also:

  • IO.winsize=


116
117
118
# File 'lib/nanoc/cli/cleaning_stream.rb', line 116

def winsize=(arg)
  @stream.winsize = (arg)
end

- (Object) write(s)

See Also:

  • IO#write


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