Metadata-Version: 2.1
Name: term
Version: 2.3
Summary: An enhanced version of the tty module
Home-page: https://github.com/stefanholek/term
Author: Stefan H. Holek
Author-email: stefan@epy.co.at
License: PSFL
Keywords: terminal tty raw cbreak opentty getyx cursor position
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Python Software Foundation License
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 3

=====
term
=====
--------------------------------------
An enhanced version of the tty module
--------------------------------------

Overview
========

The **term** package is an enhanced version of the standard library's
tty_ module.
It provides context managers for temporarily switching the terminal
to *raw* or *cbreak* mode and allows to retrieve the cursor position
without having to resort to curses.

.. _tty: https://docs.python.org/3/library/tty.html

Package Contents
================

setraw(fd, when=TCSAFLUSH, min=1, time=0)
    Put the terminal in raw mode.

setcbreak(fd, when=TCSAFLUSH, min=1, time=0)
    Put the terminal in cbreak mode.

rawmode(fd, when=TCSAFLUSH, min=1, time=0)
    Context manager to put the terminal in raw mode.

cbreakmode(fd, when=TCSAFLUSH, min=1, time=0)
    Context manager to put the terminal in cbreak mode.

opentty(bufsize=1)
    Context manager returning an rw stream connected to /dev/tty.
    The stream is None if the device could not be opened.

getyx()
    Return the cursor position as 1-based (line, col) tuple.
    Line and col are 0 if the device cannot be opened or the terminal
    does not support DSR 6.

Examples
========

To resize the terminal window we enter cbreak mode and write the new
dimensions to the tty::

    from term import opentty, cbreakmode

    with opentty() as tty:
        if tty is not None:
            with cbreakmode(tty, min=0):
                tty.write(b'\033[8;25;80t');

            print('terminal resized')

You may also want to look at the `source code`_ of getyx().

.. _`source code`: https://github.com/stefanholek/term/blob/master/term/__init__.py#L143

Caveat
======

The terminal must be in canonical mode before any of the functions and
context managers can be used. They are not meant for switching between
raw and cbreak modes. Nesting context managers of the same type is allowed
though.

Documentation
=============

Please also see the `API Documentation`_.

.. _`API Documentation`: https://term.readthedocs.io/en/stable/


Changelog
=========

2.3 - 2019-02-08
----------------

- Add MANIFEST.in.
  [stefan]

- Release as wheel.
  [stefan]

- Drop explicit GPL because the PSF license is GPL-compatible anyway.
  [stefan]

2.2 - 2017-02-05
----------------

- Support Python 2.6-3.6 without 2to3.
  [stefan]

2.1 - 2014-04-19
----------------

- Remove setuptools from install_requires because it isn't.
  [stefan]

2.0 - 2012-04-27
----------------

- Open /dev/tty in binary mode under Python 3.
  [stefan]

- Disable buffering if the device is not seekable.
  [stefan]

- Remove getmaxyx since it cannot be implemented reliably.
  [stefan]

- Support Python 2.5.
  [stefan]

- Change license to GPL or PSF to avoid relicensing of PSF code.
  [stefan]

1.0 - 2012-04-11
----------------

- Initial release.
  [stefan]


