Module iotools


[Contents] [Prev] [Next]
Table of Contents

Overview

This module provides a simple interface for KPs that would like to use the simpleio plugin for their console I/O if available, falling back to the KSS console. This is mostly useful for interactive demos (a simpleio window looks a bit nicer than a standard shell window).

Classes

tty_io_mechanism ()
A file-like object that redirects its read(), readline() and readlines() methods to sys.stdin, and its write() and writelines() methods to sys.stdout. Its close() method does nothing. This is returned by get_io_mechanism() below if a tty device is requested.

null_io_mechanism ()
A file-like object that discards all output and always returns an EOF indicator (empty string or list) on input. Its close() method does nothing. This is returned by get_io_mechanism() below if a null device is requested.

Functions

This module defines the following functions:

get_io_mechanism (kos[, use_dev[, height[, width]]]) -> file-like instance
Return a object that behaves like an interactive console. The returned object has methods read(), readline(), readlines(), write(), writelines(), and close(), that behave like the corresponding methods of a standard open file object connected to an interactive I/O device (like a console).

The kos argument must be the KOS bastion passed to the KP's __main__() method.

The optional use_dev argument specifies a preference for the style I/O mechanism. If specified, it should be one of the strings 'X', 'tty' or 'null'. If 'null' is specified, an instance of the class null_io_mechanism above is returned. If 'tty' is specified, an instance of the class tty_io_mechanism above is returned. Otherwise, and in the default case, an attempt is made to connect to the current kernel's simpleio plugin, and if successful, an interface to a (new) console window created by that plugin is returned; if the plugin is not configured or does not respond, an instance of the class tty_io_mechanism above is returned.

The optional height and width arguments specify the size of the window (in lines and characters) created by the simpleio plugin. By default, a very large window is created. They are ignored for other device types.


Table of Contents

[Contents] [Prev] [Next]
Copyright © 1998 by the Corporation for National Research Initiatives.