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



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)

See Also:

  • IO#<<


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.

Parameters:



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

See Also:

  • IO#close


98
99
100
# File 'lib/nanoc/cli/cleaning_stream.rb', line 98

def close
  @stream.close
end

- (Boolean) exist?

Returns:

  • (Boolean)

See Also:

  • File#exist?


103
104
105
# File 'lib/nanoc/cli/cleaning_stream.rb', line 103

def exist?
  @stream.exist?
end

- (Boolean) exists?

Returns:

  • (Boolean)

See Also:

  • File.exists?


108
109
110
# File 'lib/nanoc/cli/cleaning_stream.rb', line 108

def exists?
  @stream.exists?
end

- (Object) flush

See Also:

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

See Also:

  • IO#print


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)

See Also:

  • IO#puts


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.

Parameters:



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)

See Also:

  • IO#reopen


93
94
95
# File 'lib/nanoc/cli/cleaning_stream.rb', line 93

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

- (Object) string

See Also:

  • StringIO#string


88
89
90
# File 'lib/nanoc/cli/cleaning_stream.rb', line 88

def string
  @stream.string
end

- (Object) tell

See Also:

  • IO#tell


69
70
71
# File 'lib/nanoc/cli/cleaning_stream.rb', line 69

def tell
  @stream.tell
end

- (Boolean) tty?

Returns:

  • (Boolean)

See Also:

  • IO#tty?


57
58
59
# File 'lib/nanoc/cli/cleaning_stream.rb', line 57

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

- (Object) winsize

See Also:

  • IO.winsize


113
114
115
# File 'lib/nanoc/cli/cleaning_stream.rb', line 113

def winsize
  @stream.winsize
end

- (Object) winsize=(arg)

See Also:

  • IO.winsize=


118
119
120
# File 'lib/nanoc/cli/cleaning_stream.rb', line 118

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

- (Object) write(s)

See Also:

  • IO#write


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