August'24: Kamaelia is in maintenance mode and will recieve periodic updates, about twice a year, primarily targeted around Python 3 and ecosystem compatibility. PRs are always welcome. Latest Release: 1.14.32 (2024/3/24)

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(). Similarly if a "tag" is provided it's prepended before the data.

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][,tag]) -> 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)
  • tag -- Pre-pend this text tag before the data to emit

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

Warning!

You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers.

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

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

main(self)

Main loop body.

shutdown(self)

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

Warning!

You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers.

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

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

main(self)

Main thread loop.

shutdown(self)

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, 05 Jun 2009 at 03:01:38 UTC/GMT