Skip to main content

An enhanced version of the tty module

Project description

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.

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 terminal does not support DSR 6.

Examples

from term import getyx

print 'The cursor is in line %d column %d' % getyx()

You may also want to look at the source code of getyx.

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, say, raw and cbreak modes. Nesting context managers of the same type is ok though.

Changelog

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]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

term-2.0.zip (8.6 kB view details)

Uploaded Source

File details

Details for the file term-2.0.zip.

File metadata

  • Download URL: term-2.0.zip
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for term-2.0.zip
Algorithm Hash digest
SHA256 16892fd4cace3c805ade99443ac706ad8b239fadf424da925eeceea0c86771b1
MD5 fc8fab733cd1d08e5110b7195d2d4930
BLAKE2b-256 e99613a15108d8f38ee7c948bb0c85729fc62b7394ffbda34624d1d239ecfea5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page