FormatOutput

A bridge between a Layout instance and a stream. This is used for the Stdout & Stderr globals, but can be used for general purpose buffer-formatting as desired.

FormatOutput exposes this style of usage:

auto print = new FormatOutput(...);

print.format ("abc {}", 1);         // => abc 1
print.format ("abc {}:{}", 1, 2);   // => abc 1:2
print.format ("abc {1}:{0}", 1, 2); // => abc 2:1
print.format ("abc ", 1);           // => abc

Note that the last example does not throw an exception. There are several use-cases where dropping an argument is legitimate, so we're currently not enforcing any particular trap mechanism.

Flushing the output is achieved through the flush() method:

print.format ("hello {}", "world").flush;

Special character sequences, such as "\n", are written directly to the output without any translation (though an output-filter could be inserted to perform translation as required). Platform-specific newlines are generated instead via the newline() method, which also flushes the output when configured to do so:

print.format ("hello {}", "world").newline;
print.formatln ("hello {}", "world");

Note that FormatOutput is *not* intended to be thread-safe.

Constructors

this
this(OutputStream output, cstring eol)

Construct a FormatOutput instance, tying the provided stream to a layout formatter.

Members

Aliases

flush
alias flush = OutputFilter.flush
Undocumented in source.
nl
alias nl = newline
Undocumented in source.

Functions

emit
void emit(cstring s)

Sink for passing to the formatter.

flush
FormatOutput flush(bool yes)

Control implicit flushing of newline(), where true enables flushing. An explicit flush() will always flush the output.

format
typeof(this) format(cstring fmt, Args args)

Format the provided arguments to the stream according to the format string

formatln
typeof(this) formatln(cstring fmt, Args args)

Format the provided arguments to the stream according to the format string, and append a newline to the output.

newline
FormatOutput newline()

Output a newline and optionally flush.

stream
OutputStream stream()

Return the associated output stream.

stream
FormatOutput stream(OutputStream output)

Set the associated output stream.

Static variables

Eol
auto Eol;
Undocumented in source.

Inherited Members

From OutputFilter

sink
OutputStream sink;
Undocumented in source.
conduit
IConduit conduit()

Return the hosting conduit.

write
size_t write(const(void)[] src)

Write to conduit from a source array. The provided src content will be written to the conduit.

copy
OutputStream copy(InputStream src, size_t max)

Transfer the content of another conduit to this one. Returns a reference to this class, or throws IOException on failure.

flush
IOStream flush()

Emit/purge buffered content.

seek
long seek(long offset, Anchor anchor)

Seek on this stream. Target conduits that don't support seeking will throw an IOException.

output
OutputStream output()

Return the upstream host of this filter.

close
void close()

Close the output.

Meta