github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

stefanholek / rl

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 1
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (3)
  • Downloads (12)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (2)
    • master ✓
    • rl-static
  • Tags (12)
    • 1.3
    • 1.2
    • 1.1
    • 1.0a8
    • 1.0a7
    • 1.0a6
    • 1.0a5
    • 1.0a4
    • 1.0a3
    • 1.0a2
    • 1.0a1
    • 1.0
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Python readline interface focusing on completion — Read more

  cancel

http://pypi.python.org/pypi/rl

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Fix OS classifier: Unix -> POSIX. 
stefanholek (author)
Thu Feb 04 05:14:29 -0800 2010
commit  b1afca936f719776c99f29775061b7338112c694
tree    83ca513f78368c009ada836f12f10d8d03398a60
parent  62b835e1c58127bc6f0ebd5b18a48f9941e305f0
rl /
name age
history
message
file .gitignore Loading commit data...
file CHANGES.txt
file README.txt
file epydoc.conf
file epydoc.css
directory rl/
file setup.cfg
file setup.py
README.txt
==
rl
==
------------------------------------------------
Python readline interface focusing on completion
------------------------------------------------

Introduction
============

The rl package aims to provide a full implementation of the
GNU Readline `Custom Completer`_ interface.

.. _`Custom Completer`: http://tiswww.case.edu/php/chet/readline/readline.html#SEC44

Package Contents
----------------

rl exports the following components:

completer
    Interface to the readline completer. Used to configure the completion
    aspects of readline.

completion
    Interface to the active readline completion. Used to interact
    with readline when a completion is in progress.

generator
    A factory turning any callable into a `completion entry function` that
    can be handed to readline.

print_exc
    A decorator printing exceptions to stderr. Useful when writing Python
    completions and hooks, as exceptions occurring there are usually
    swallowed by the in-between C code.

history
    Interface to the readline history. Used to read and write history files
    and to manipulate history entries.

readline
    The readline interface module. Contains everything known from the standard
    library plus extensions specific to the rl package.  The `completer`,
    `completion`, and `history` interfaces make use of this module, and
    you should rarely need to interact with it directly.

For further details, please refer to the `API Documentation`_.

.. _`API Documentation`: http://packages.python.org/rl/

Example Code
------------

The code below implements system command completion similar to bash::

    import os
    from rl import completer
    from rl import generator

    def complete(text):
        # Return executables matching 'text'
        for dir in os.environ.get('PATH').split(':'):
            dir = os.path.expanduser(dir)
            if os.path.isdir(dir):
                for name in os.listdir(dir):
                    if name.startswith(text):
                        if os.access(os.path.join(dir, name), os.R_OK|os.X_OK):
                            yield name

    def main():
        # Set the completion function
        completer.completer = generator(complete)

        # Enable TAB completion
        completer.parse_and_bind('tab: complete')

        command = raw_input('command: ')
        print 'You typed:', command

More elaborate examples can be found here_ and in the gpgkeys_ package.

.. _here: http://github.com/stefanholek/rl/tree/master/rl/examples
.. _gpgkeys: http://pypi.python.org/pypi/gpgkeys

Repository Access
-----------------

rl development is hosted on github_.

.. _github: http://github.com/stefanholek/rl

Installation
============

rl has been tested with GNU Readline versions 5 and 6.

On Linux, install libreadline5-dev (or equivalent) before attempting to build
rl. On Mac OS X, you need a Python built with MacPorts or Fink, as the system
Python is linked to the BSD editline library and not GNU readline.

rl requires distribute >= 0.6.8. If you have not upgraded your setuptools
yet, type::

    /path/to/easy_install distribute

Then type::

    /path/to/easy_install rl

and watch the console. When it reads::

    Finished processing dependencies for rl

you are done and rl is ready to use.

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server