rlane-libcurses


Namerlane-libcurses JSON
Version 1.0.7 PyPI version JSON
download
home_pageNone
SummaryCurses based boxes, menus, loggers
upload_time2024-10-26 02:34:57
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT
keywords curses python xterm-256color mouse
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## libcurses

Framework and tools for multi-threaded, curses(3)-based, terminal applications.

* Write to screen from multiple threads.

    * Use `libcurses.wrapper` instead of `curses.wrapper`.
    * Use `libcurses.getkey` instead of `curses.getch`.
    * Use `libcurses.getline` instead of `curses.getstr`.
    * Preserve the cursor with context manager `libcurses.preserve_cursor`.

* Register callbacks with `register_fkey` to handle function-keys pressed
  during `getkey` and `getline` processing.

* Register callbacks with `add_mouse_handler` to handle mouse events
  during `getkey` and `getline` processing.

* Manage a logger destination, `LogSink`, to write to a curses window.

* A `Grid` framework.


### class Grid

Grid of windows.

A rectangular collection of windows with shared (collapsed) borders that
resize the windows to either side (syncronized shrink/expand) when moused upon.

        +-------+---+------+    example `Grid`, 9 windows.
        |       |   |      |
        +-------+---+------+
        |           |      |
        +------+----+------+
        |      |           |
        +------+--+--------+
        |         |        |
        +---------+--------+

Drag and drop an interior border to resize the windows on either side.

Double-click an interior border to enter Resize Mode:
    * scroll-wheel and arrow-keys move the border, and
    * click anywhere, Enter and Esc to exit Resize Mode.

Grids also provide a wrapper around `curses.newwin` that takes positioning
parameters that describe the spatial-relationship to other windows on the
screen, instead of (y,x) coordinates:

          +--------+                 +--------+
          |        |                 |  ^     |
          |        |<------ left2r --|  |     |
          |        |                 |  |     |
          |<---------------- left ---|  |     |
          |        |                 |  |     |
          +--------+                 +--|-----+
             |  |                       |  ^
    bottom2t |  | bottom            top |  | top2b
             v  |                       |  |
          +-----|--+                 +--------+
          |     |  |                 |        |
          |     |  |-- right ---------------->|
          |     |  |                 |        |
          |     |  |-- right2l ----->|        |
          |     v  |                 |        |
          +--------+                 +--------+

For example, this 3x13 grid with three 3x5 boxes may be described at least
three different ways:

            +---+---+---+
            | a | b | c |
            +---+---+---+

    grid = Grid(curses.newwin(3, 13))

    1)  a = grid.box('a', 3, 5)
        b = grid.box('b', 3, 5, left2r=a)
        c = grid.box('c', 3, 5, left2r=b)

    2)  c = grid.box('c', 3, 5, right=grid)
        b = grid.box('b', 3, 5, right=c)
        a = grid.box('a', 3, 5, right=b)

    3)  a = grid.box('a', 3, 5, left=grid)
        c = grid.box('c', 3, 5, right=grid)
        b = grid.box('b', 3, 0, left2r=a, right=c)

If two endpoints are given (such as 3b), the length will be calculated to
fill the gap between the endpoints.


### class LogSink

Logger sink to curses window.

The `LogSink` class provides a logger destination that writes log
messages to a curses window, and methods that control various
logging features.


### class MouseEvent

Wrap `curses.getmouse` with additional, convenience-properties.

`MouseEvent` encapsulates the results of `curses.getmouse`,

    x               x-coordinate.
    y               y-coordinate.
    bstate          bitmask describing the type of event.

and provides these additional properties:

    button          button number (1-5).
    nclicks         number of clicks (1-3).
    is_pressed      True if button is pressed.
    is_released     True if button was just released.
    is_alt          True if Alt key is held.
    is_ctrl         True if Ctrl key is held.
    is_shift        True if Shift key is held.
    is_moving       True if mouse is moving.


### method add_mouse_handler

Call `func` with `args` when mouse event happens at (y, x).

### method clear_mouse_handlers

Remove all mouse handlers.

### function get_colormap

Return map of `loguru-level-name` to `curses-color/attr`.

Call after creating all custom levels with `logger.level()`.
Map is build once and cached; repeated calls return same map.


### function getkey

Read and return a character from window.

Args:
    win: curses window to read from.
    no_mouse: ignore mouse events (for internal use).

Return:
    -1 when no-input in no-delay mode, or
    None on end of file, or
    >=0 int character read.


### function getline

Read and return a line of input from window.

A line is terminated with CR, LF or KEY_ENTER.
Backspace deletes the previous character.
NAK (ctrl-U) kills the line.
Mouse events are handled.


### function preserve_cursor

Context manager to save and restore the cursor.

### function register_fkey

Register `func` to be called when `key` is pressed.

Args:
    func: callable, to be called on receipt of `key`.
    key: the key to be captured, e.g., `curses.KEY_F1`,
    or zero (0) for all keys.

`func` is appended to a list for the `key`;
pass func=None to remove list of funcs for `key` from registry.


### function wrapper

Use instead of `curses.wrapper`.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "rlane-libcurses",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "curses, python, xterm-256color, mouse",
    "author": null,
    "author_email": "Russel Lane <russel@rlane.com>",
    "download_url": "https://files.pythonhosted.org/packages/a1/7a/55a3d099653596a6666a58476c5d76fbe59506c1ddca3c8ffa026905d8c4/rlane_libcurses-1.0.7.tar.gz",
    "platform": null,
    "description": "## libcurses\n\nFramework and tools for multi-threaded, curses(3)-based, terminal applications.\n\n* Write to screen from multiple threads.\n\n    * Use `libcurses.wrapper` instead of `curses.wrapper`.\n    * Use `libcurses.getkey` instead of `curses.getch`.\n    * Use `libcurses.getline` instead of `curses.getstr`.\n    * Preserve the cursor with context manager `libcurses.preserve_cursor`.\n\n* Register callbacks with `register_fkey` to handle function-keys pressed\n  during `getkey` and `getline` processing.\n\n* Register callbacks with `add_mouse_handler` to handle mouse events\n  during `getkey` and `getline` processing.\n\n* Manage a logger destination, `LogSink`, to write to a curses window.\n\n* A `Grid` framework.\n\n\n### class Grid\n\nGrid of windows.\n\nA rectangular collection of windows with shared (collapsed) borders that\nresize the windows to either side (syncronized shrink/expand) when moused upon.\n\n        +-------+---+------+    example `Grid`, 9 windows.\n        |       |   |      |\n        +-------+---+------+\n        |           |      |\n        +------+----+------+\n        |      |           |\n        +------+--+--------+\n        |         |        |\n        +---------+--------+\n\nDrag and drop an interior border to resize the windows on either side.\n\nDouble-click an interior border to enter Resize Mode:\n    * scroll-wheel and arrow-keys move the border, and\n    * click anywhere, Enter and Esc to exit Resize Mode.\n\nGrids also provide a wrapper around `curses.newwin` that takes positioning\nparameters that describe the spatial-relationship to other windows on the\nscreen, instead of (y,x) coordinates:\n\n          +--------+                 +--------+\n          |        |                 |  ^     |\n          |        |<------ left2r --|  |     |\n          |        |                 |  |     |\n          |<---------------- left ---|  |     |\n          |        |                 |  |     |\n          +--------+                 +--|-----+\n             |  |                       |  ^\n    bottom2t |  | bottom            top |  | top2b\n             v  |                       |  |\n          +-----|--+                 +--------+\n          |     |  |                 |        |\n          |     |  |-- right ---------------->|\n          |     |  |                 |        |\n          |     |  |-- right2l ----->|        |\n          |     v  |                 |        |\n          +--------+                 +--------+\n\nFor example, this 3x13 grid with three 3x5 boxes may be described at least\nthree different ways:\n\n            +---+---+---+\n            | a | b | c |\n            +---+---+---+\n\n    grid = Grid(curses.newwin(3, 13))\n\n    1)  a = grid.box('a', 3, 5)\n        b = grid.box('b', 3, 5, left2r=a)\n        c = grid.box('c', 3, 5, left2r=b)\n\n    2)  c = grid.box('c', 3, 5, right=grid)\n        b = grid.box('b', 3, 5, right=c)\n        a = grid.box('a', 3, 5, right=b)\n\n    3)  a = grid.box('a', 3, 5, left=grid)\n        c = grid.box('c', 3, 5, right=grid)\n        b = grid.box('b', 3, 0, left2r=a, right=c)\n\nIf two endpoints are given (such as 3b), the length will be calculated to\nfill the gap between the endpoints.\n\n\n### class LogSink\n\nLogger sink to curses window.\n\nThe `LogSink` class provides a logger destination that writes log\nmessages to a curses window, and methods that control various\nlogging features.\n\n\n### class MouseEvent\n\nWrap `curses.getmouse` with additional, convenience-properties.\n\n`MouseEvent` encapsulates the results of `curses.getmouse`,\n\n    x               x-coordinate.\n    y               y-coordinate.\n    bstate          bitmask describing the type of event.\n\nand provides these additional properties:\n\n    button          button number (1-5).\n    nclicks         number of clicks (1-3).\n    is_pressed      True if button is pressed.\n    is_released     True if button was just released.\n    is_alt          True if Alt key is held.\n    is_ctrl         True if Ctrl key is held.\n    is_shift        True if Shift key is held.\n    is_moving       True if mouse is moving.\n\n\n### method add_mouse_handler\n\nCall `func` with `args` when mouse event happens at (y, x).\n\n### method clear_mouse_handlers\n\nRemove all mouse handlers.\n\n### function get_colormap\n\nReturn map of `loguru-level-name` to `curses-color/attr`.\n\nCall after creating all custom levels with `logger.level()`.\nMap is build once and cached; repeated calls return same map.\n\n\n### function getkey\n\nRead and return a character from window.\n\nArgs:\n    win: curses window to read from.\n    no_mouse: ignore mouse events (for internal use).\n\nReturn:\n    -1 when no-input in no-delay mode, or\n    None on end of file, or\n    >=0 int character read.\n\n\n### function getline\n\nRead and return a line of input from window.\n\nA line is terminated with CR, LF or KEY_ENTER.\nBackspace deletes the previous character.\nNAK (ctrl-U) kills the line.\nMouse events are handled.\n\n\n### function preserve_cursor\n\nContext manager to save and restore the cursor.\n\n### function register_fkey\n\nRegister `func` to be called when `key` is pressed.\n\nArgs:\n    func: callable, to be called on receipt of `key`.\n    key: the key to be captured, e.g., `curses.KEY_F1`,\n    or zero (0) for all keys.\n\n`func` is appended to a list for the `key`;\npass func=None to remove list of funcs for `key` from registry.\n\n\n### function wrapper\n\nUse instead of `curses.wrapper`.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Curses based boxes, menus, loggers",
    "version": "1.0.7",
    "project_urls": {
        "Homepage": "https://github.com/russellane/libcurses"
    },
    "split_keywords": [
        "curses",
        " python",
        " xterm-256color",
        " mouse"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2d638583a553b47d3c451fb8023369a95e85856bd8851829a232c51790852db5",
                "md5": "36c25f4ed96f3c770a7f75d052d2be52",
                "sha256": "e982a6170f1b0200334d4fee4dc1b0c7d3ce2c64ff4a9d2356d4f672baa69189"
            },
            "downloads": -1,
            "filename": "rlane_libcurses-1.0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "36c25f4ed96f3c770a7f75d052d2be52",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 24412,
            "upload_time": "2024-10-26T02:34:55",
            "upload_time_iso_8601": "2024-10-26T02:34:55.735604Z",
            "url": "https://files.pythonhosted.org/packages/2d/63/8583a553b47d3c451fb8023369a95e85856bd8851829a232c51790852db5/rlane_libcurses-1.0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a17a55a3d099653596a6666a58476c5d76fbe59506c1ddca3c8ffa026905d8c4",
                "md5": "0a60333b0fac4a389128e07e4f5ed2c2",
                "sha256": "9f50c98d53028410ac7353672e705e48c7f62833cedb2a23fd3610f29bbdf229"
            },
            "downloads": -1,
            "filename": "rlane_libcurses-1.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "0a60333b0fac4a389128e07e4f5ed2c2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 26962,
            "upload_time": "2024-10-26T02:34:57",
            "upload_time_iso_8601": "2024-10-26T02:34:57.157200Z",
            "url": "https://files.pythonhosted.org/packages/a1/7a/55a3d099653596a6666a58476c5d76fbe59506c1ddca3c8ffa026905d8c4/rlane_libcurses-1.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-26 02:34:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "russellane",
    "github_project": "libcurses",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "rlane-libcurses"
}
        
Elapsed time: 0.38692s