Skip to main content

A small Python package to hide or show the terminal cursor

Project description

License: GPL v3

PyPI version

cursor

A small Python package to hide or show the terminal cursor. Works on Linux and Windows, on both Python 2 and Python 3.

demonstration

Disclaimer

The code is almost entirely a copy of James Spencer's answer on StackOverflow.

Installation

The preferred way of installing cursor is via pip. You can install pip with your package manager:

On Ubuntu:

sudo apt-get install python-pip
pip install --user cursor

On Arch:

git clone https://aur.archlinux.org/python-cursor.git
cd python-cursor
makepkg -si

Usage

import cursor
cursor.hide() ## Hides the cursor
cursor.show() ## Shows the cursor

Note that the cursor will stay hidden until you call cursor.show() — even after exiting your python script!

Because of that, pip will install two scripts, which can be run from the command line: cursor_hide and cursor_show.

An alternative is using the HiddenCursor() class in conjunction with Python's with statement. This will make sure that the cursor is shown again after running your code, even if exceptions are raised:

import cursor
with cursor.HiddenCursor():     ## Cursor will stay hidden
    import time                 ## while code is being executed;
    for a in range(1,100):      ## afterwards it will show up again
        print(a)
        time.sleep(0.05)
    

You could also use Python's atexit module:

import cursor
import atexit
import time

atexit.register(cursor.show)    ## Make sure cursor.show() is called
                                ## when exiting

cursor.hide()                   ## Hides cursor
for a in range(1,100):
    print(a)
    time.sleep(0.05)
exit()                          ## Cursor will show again

Contributors

Manraj Singh: allowed setting a customisable stream

Alexander Seiler: packaging for Arch

Patrik Kopkan: packaging for Fedora

Projects using cursor

halo: beautiful terminal spinners in Python

pipenv: a tool that aims to bring the best of all packaging worlds to the Python world

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

cursor-1.3.5.tar.gz (15.7 kB view details)

Uploaded Source

File details

Details for the file cursor-1.3.5.tar.gz.

File metadata

  • Download URL: cursor-1.3.5.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.5

File hashes

Hashes for cursor-1.3.5.tar.gz
Algorithm Hash digest
SHA256 6758cae6ac14765ec85d9ce3f14fcb98fff5045f06d8398f1e8da8ce3acd2f20
MD5 dec469fad4a8f0cd586c16b26a05374e
BLAKE2b-256 591bae231e1f9a8e1f970453f92fcb20a3fce87fa38753915477c26bc1655d86

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