License:
BSD style: see license.txt
Version:
Initial release: Feb 2005
Version:
Heavily revised for unicode; November 2005
Outback release: December 2006
author:
Kris
- struct
Console
;
- low level console IO support.
Note that for a while this was templated for each of char, wchar,
and dchar. It became clear after some usage that the console is
more useful if it sticks to Utf8 only. See ConsoleConduit below
for details.
Redirecting the standard IO handles (via a shell) operates as one
would expect, though the redirected content should likely restrict
itself to utf8
- class
Input
;
- Model console input as a buffer. Note that we read utf8
only.
- final char[]
copyln
(bool raw = false);
- Return the next line available from the console,
or null when there is nothing available. The value
returned is a duplicate of the buffer content (it
has .dup applied).
Each line ending is removed unless parameter raw is
set to true
- final bool
readln
(ref char[] content, bool raw = false);
- Retreive a line of text from the console and map
it to the given argument. The input is sliced,
not copied, so use .dup appropriately. Each line
ending is removed unless parameter raw is set to
true.
Returns false when there is no more input.
- final InputStream
stream
();
- Return the associated
stream
- final bool
redirected
();
- Is this device
redirected
?
Returns:
True if
redirected
, false otherwise.
Remarks:
Reflects the console redirection status from when
this module was instantiated
- final Input
redirected
(bool yes);
- Set redirection state to the provided boolean
Remarks:
Configure the console redirection status, where
a
redirected
console is more efficient (dictates
whether newline() performs automatic flushing or
not)
- final InputStream
input
();
- Returns the configured source
Remarks:
Provides access to the underlying mechanism for
console
input
. Use this to retain prior state
when temporarily switching inputs
- final Input
input
(InputStream source);
- Divert
input
to an alternate source
- class
Output
;
- Console output accepts utf8 only, by default
- final Output
append
(char[] x);
- Append to the console. We accept UTF8 only, so
all other encodings should be handled via some
higher level API
- final Output
append
(Object other);
- Append content
Params:
| Object other |
an object with a useful toString() method |
Returns:
Returns a chaining reference if all content was
written. Throws an IOException indicating eof or
eob if not.
Remarks:
Append the result of other.toString() to the console
- final Output
newline
();
- Append a
newline
and flush the console buffer. If
the output is redirected, flushing does not occur
automatically.
Returns:
Returns a chaining reference if content was written.
Throws an IOException indicating eof or eob if not.
Remarks:
Emit a
newline
into the buffer, and autoflush the
current buffer content for an interactive console.
Redirected consoles do not flush automatically on
a
newline
.
- final Output
flush
();
- Explicitly
flush
console output
Returns:
Returns a chaining reference if content was written.
Throws an IOException indicating eof or eob if not.
Remarks:
Flushes the console buffer to attached conduit
- final OutputStream
stream
();
- Return the associated
stream
- final bool
redirected
();
- Is this device
redirected
?
Returns:
True if
redirected
, false otherwise.
Remarks:
Reflects the console redirection status
- final Output
redirected
(bool yes);
- Set redirection state to the provided boolean
Remarks:
Configure the console redirection status, where
a
redirected
console is more efficient (dictates
whether newline() performs automatic flushing or
not)
- final OutputStream
output
();
- Returns the configured
output
sink
Remarks:
Provides access to the underlying mechanism for
console
output
. Use this to retain prior state
when temporarily switching outputs
- final Output
output
(OutputStream sink);
- Divert
output
to an alternate sink
- class
Conduit
: tango.io.DeviceConduit.DeviceConduit;
-
Conduit
for specifically handling the console devices. This
takes care of certain implementation details on the Win32
platform.
Note that the console is fixed at Utf8 for both linux and
Win32. The latter is actually Utf16 native, but it's just
too much hassle for a developer to handle the distinction
when it really should be a no-brainer. In particular, the
Win32 console functions don't work with redirection. This
causes additional difficulties that can be ameliorated by
asserting console I/O is always Utf8, in all modes.
- char[]
toString
();
- Return the name of this conduit
- static Console.Input
Cin
;
- the standard input stream
Globals representing Console IO
the standard input stream
- static Console.Output
Cout
;
- the standard output stream
the standard error stream
- static Console.Output
Cerr
;
- the standard error stream
|