Kamaelia docs : Kamaelia.Util.Console

Console Input/Output

The ConsoleEchoer component outputs whatever it receives to the console.

The ConsoleReader component outputs whatever is typed at the console, a line at a time.

Example Usage

Whatever it typed is echoed back, a line at a time:

Pipeline( ConsoleReader(),
          ConsoleEchoer()
        ).run()

How does it work?

ConsoleReader is a threaded component. It provides a 'prompt' at which you can type. Your input is taken, a line a a time, and output to its "outbox" outbox, with the specified end-of-line character(s) suffixed onto it.

The ConsoleReader component ignores any input on its "inbox" and "control" inboxes. It does not output anything from its "signal" outbox.

The ConsoleReader component does not terminate.

The ConsoleEchoer component receives data on its "inbox" inbox. Anything it receives this way is displayed on standard output. All items are passed through the str() builtin function to convert them to strings suitable for display.

However, if the 'use_repr' argument is set to True during initialization, then repr() will be used instead of str().

If the 'forwarder' argument is set to True during initialisation, then whatever is received is not only displayed, but also set on to the "outbox" outbox (unchanged).

If a producerFinished or shutdownMicroprocess message is received on the ConsoleEchoer component's "control" inbox, then it is sent on to the "signal" outbox and the component then terminates.


Kamaelia.Util.Console.ConsoleEchoer

class ConsoleEchoer(Axon.Component.component)

ConsoleEchoer([forwarder][,use_repr]) -> new ConsoleEchoer component.

A component that outputs anything it is sent to standard output (the console).

Keyword arguments:

  • forwarder -- incoming data is also forwarded to "outbox" outbox if True (default=False)
  • use_repr -- use repr() instead of str() if True (default=False)

Inboxes

  • control : Shutdown signalling
  • inbox : Stuff that will be echoed to standard output

Outboxes

  • outbox : Stuff forwarded from 'inbox' inbox (if enabled)
  • signal : Shutdown signalling

Methods defined here

__init__(self[, forwarder][, use_repr])

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

main(self)

Main loop body.

Kamaelia.Util.Console.ConsoleReader

class ConsoleReader(Axon.ThreadedComponent.threadedcomponent)

ConsoleReader([prompt][,eol]) -> new ConsoleReader component.

Component that provides a console for typing in stuff. Each line is output from the "outbox" outbox one at a time.

Keyword arguments:

  • prompt -- Command prompt (default=">>> ")
  • eol -- End of line character(s) to put on end of every line outputted (default is newline)

Inboxes

  • control : NOT USED
  • inbox : NOT USED

Outboxes

  • outbox : Lines that were typed at the console
  • signal : NOT USED

Methods defined here

__init__(self[, prompt][, eol])

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

main(self)

Main thread loop.

Feedback

Got a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording!

Please leave you feedback here in reply to the documentation thread in the Kamaelia blog.

-- Automatic documentation generator, 19 Oct 2008 at 14:29:09 UTC/GMT

This is a page from the Kamaelia website. You can find the original here: