Bext


NameBext JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/asweigart/bext
SummaryA cross-platform Python 2/3 module for colorful, boring, text-based terminal programs.
upload_time2024-04-17 13:50:19
maintainerNone
docs_urlNone
authorAl Sweigart
requires_pythonNone
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Bext
======

A cross-platform Python 2/3 module for colorful, boring, text-based terminal programs.

Basically, use Bext if you want to move the cursor around the terminal window and have colorful text, like some kind of limited curses module (but it works on Windows also.)

Bext does not currently work in the new Windows Terminal. It does work in the older Command Prompt.

Note: Currently something in Colorama 0.4.6 causes Bext to fail. Please use 0.4.5 or earlier.

Installation
------------

To install with pip, run:

    pip install bext

Functions
---------

* ``fg(color)``

Sets the foreground color, that is, the color of the text. The color is a string of one of the following colors: black, red, green, yellow, blue, purple, cyan, white, reset, random.

* ``bg(color)``

Sets the background color, that is, the color of the cell behind the text characters. You "paint" a cell with the background color by printing a space character.

* ``size()``

Returns a tuple of the (width, height) of the current terminal.

* ``resize(columns, rows)``

Resizes the terminal window to the given number of columns and rows. Returns `True` if the resize was a success and `False` if not. Note that on Ubuntu Linux, this function doesn't work if the Terminal window is maximized. On Windows, if the Command Prompt is maximized the window won't change size but the screen buffer size will be resized. This function is not very reliable.

* ``clear()``

Erase all the text on the screen, paint the entire terminal to the background color, and moves the cursor to (0, 0) at the top-left corner of the screen.

* ``clear_line()``

Erases the line where the cursor is located.

* ``goto(x, y)``

Move the cursor to x, y coordinates on the screen. (0, 0) is the top-left corner of the screen.

* ``title(text)``

Sets the title of the terminal window to `text`.

* ``hide_cursor()``

Hides the cursor.

* ``show_cursor()``

Shows the cursor after hiding it.

* ``get_key(blocking=True)``

Waits until the user presses a single key on the keyboard, then returns that key as a string. If `blocking` is `False`, the function returns immediately (returning `None` if no key has been pressed.)

Example
-------

```python

    import bext, random

    width, height = bext.size()

    try:
        while True:
            bext.fg('random')
            bext.bg('random')
            x = random.randint(0, width - 1)
            y = random.randint(0, height - 1)

            if x == width -1 and y == height - 1:
                continue # Windows has weird behavior where a character at the end of the row always moves the cursor to the next row.
            bext.goto(x, y)
            print('*', end='')
    except KeyboardInterrupt:
        pass

```

Contribute
----------

If you'd like to contribute to Bext, check out https://github.com/asweigart/bext

Support
-------

If you find this project helpful and would like to support its development, [consider donating to its creator on Patreon](https://www.patreon.com/AlSweigart).
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/asweigart/bext",
    "name": "Bext",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Al Sweigart",
    "author_email": "al@inventwithpython.com",
    "download_url": "https://files.pythonhosted.org/packages/98/eb/b4eb3170b1fd0ae4be1da5644bf022daa7e6a48e157c596b4a8525fccfaf/Bext-0.1.1.tar.gz",
    "platform": null,
    "description": "Bext\n======\n\nA cross-platform Python 2/3 module for colorful, boring, text-based terminal programs.\n\nBasically, use Bext if you want to move the cursor around the terminal window and have colorful text, like some kind of limited curses module (but it works on Windows also.)\n\nBext does not currently work in the new Windows Terminal. It does work in the older Command Prompt.\n\nNote: Currently something in Colorama 0.4.6 causes Bext to fail. Please use 0.4.5 or earlier.\n\nInstallation\n------------\n\nTo install with pip, run:\n\n    pip install bext\n\nFunctions\n---------\n\n* ``fg(color)``\n\nSets the foreground color, that is, the color of the text. The color is a string of one of the following colors: black, red, green, yellow, blue, purple, cyan, white, reset, random.\n\n* ``bg(color)``\n\nSets the background color, that is, the color of the cell behind the text characters. You \"paint\" a cell with the background color by printing a space character.\n\n* ``size()``\n\nReturns a tuple of the (width, height) of the current terminal.\n\n* ``resize(columns, rows)``\n\nResizes the terminal window to the given number of columns and rows. Returns `True` if the resize was a success and `False` if not. Note that on Ubuntu Linux, this function doesn't work if the Terminal window is maximized. On Windows, if the Command Prompt is maximized the window won't change size but the screen buffer size will be resized. This function is not very reliable.\n\n* ``clear()``\n\nErase all the text on the screen, paint the entire terminal to the background color, and moves the cursor to (0, 0) at the top-left corner of the screen.\n\n* ``clear_line()``\n\nErases the line where the cursor is located.\n\n* ``goto(x, y)``\n\nMove the cursor to x, y coordinates on the screen. (0, 0) is the top-left corner of the screen.\n\n* ``title(text)``\n\nSets the title of the terminal window to `text`.\n\n* ``hide_cursor()``\n\nHides the cursor.\n\n* ``show_cursor()``\n\nShows the cursor after hiding it.\n\n* ``get_key(blocking=True)``\n\nWaits until the user presses a single key on the keyboard, then returns that key as a string. If `blocking` is `False`, the function returns immediately (returning `None` if no key has been pressed.)\n\nExample\n-------\n\n```python\n\n    import bext, random\n\n    width, height = bext.size()\n\n    try:\n        while True:\n            bext.fg('random')\n            bext.bg('random')\n            x = random.randint(0, width - 1)\n            y = random.randint(0, height - 1)\n\n            if x == width -1 and y == height - 1:\n                continue # Windows has weird behavior where a character at the end of the row always moves the cursor to the next row.\n            bext.goto(x, y)\n            print('*', end='')\n    except KeyboardInterrupt:\n        pass\n\n```\n\nContribute\n----------\n\nIf you'd like to contribute to Bext, check out https://github.com/asweigart/bext\n\nSupport\n-------\n\nIf you find this project helpful and would like to support its development, [consider donating to its creator on Patreon](https://www.patreon.com/AlSweigart).",
    "bugtrack_url": null,
    "license": null,
    "summary": "A cross-platform Python 2/3 module for colorful, boring, text-based terminal programs.",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/asweigart/bext"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "98ebb4eb3170b1fd0ae4be1da5644bf022daa7e6a48e157c596b4a8525fccfaf",
                "md5": "77ff91e6d2986ce4b18bcd3fc2a7c651",
                "sha256": "591a237dab859211ad884d374b826205b846eb81d5bd058eb12c113cbc2ed9d6"
            },
            "downloads": -1,
            "filename": "Bext-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "77ff91e6d2986ce4b18bcd3fc2a7c651",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10393,
            "upload_time": "2024-04-17T13:50:19",
            "upload_time_iso_8601": "2024-04-17T13:50:19.770546Z",
            "url": "https://files.pythonhosted.org/packages/98/eb/b4eb3170b1fd0ae4be1da5644bf022daa7e6a48e157c596b4a8525fccfaf/Bext-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-17 13:50:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "asweigart",
    "github_project": "bext",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "bext"
}
        
Elapsed time: 0.25491s