dylan-lang / opendylan

Open Dylan compiler and IDE
http://opendylan.org/
Other
456 stars 68 forks source link

tee-stream? #982

Open waywardmonkeys opened 8 years ago

waywardmonkeys commented 8 years ago

I have a situation where I'd like a <tee-stream> which is like a <wrapper-stream>, but only for output streams and has more than one stream that it points at.

This might look something like:

  let tee = make(<tee-stream>, streams: vector(*standard-output*, my-string-stream));
  // ... write to tee and the output will go to both of the target streams

The use case for this is actually roughly what I put above. I'd like to record test output in Testworks, but I don't want to buffer everything and then write it to *standard-output*.

One interesting thing that happens here is that I want to be able to do color output on the *standard-output* but don't really want color on my extra stream storing the output text.

I could handle this by adding a method like:

define method print-object
    (attributes :: <text-attributes>,
     stream :: <tee-stream>)
 => ()
  // Look at the streams in the <tee-stream> and call print-object with
  // the streams that are <coloring-stream>.
end method print-object;

Thoughts? Better way?

waywardmonkeys commented 8 years ago

Alternatively, I could have a <tee-coloring-stream> which wraps the members of the tee in their own separate coloring streams and then it would be a matter of just using do(..., tee-streams(stream)) on them.