dt-console


Namedt-console JSON
Version 0.1.11 PyPI version JSON
download
home_pagehttps://github.com/JavaWiz1/dt-console
SummaryConsole helper tools for CLIs
upload_time2024-09-28 17:11:22
maintainerNone
docs_urlNone
authorAl DAmico
requires_python<4.0,>=3.10
licenseMIT
keywords python dt-tools cli console command-line status bar progress bar
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # dt-console

dt-console is a Python library to simplify CLI input and output for your python apps/scripts.  It has been tested in Windows and Linux.

Features include:
<ul>
    <li><b>ConsoleHelper</b> - manage window and cursor control</li>
    <ul>
        <li>Set console window title</li>
        <li>Show/Hide console window, set fg/bg colors</li>
        <li>Set cursor style, location, ...</li>
        <li>Routines to print and colorize output text</li>
    </ul>
    <li><b>ConsoleInputHelper</b> - Keyboard input prompts with validation and timeouts.</li>
    <li><b>MessageBox</b> - GUI messsagebox (alert, confirm, input, password)</li>
    <li><b>ProgressBar</b> - Display visual progress on screen via configurable progress bar</li>
    <li><b>Spinner</b> - Display visual progress on screen via configuable spinner control</li>
</ul>

Package donumentation can be found [here](https://htmlpreview.github.io/?https://github.com/JavaWiz1/dt-console/blob/develop/docs/html/index.html).

## Installation

### Download source code from githup via git
```bash
git clone https://github.com/JavaWiz1/dt-console.git
```
Note, when downloading source, [Poetry](https://python-poetry.org/docs/) was used as the package manager.  Poetry 
handles creating the virtual environment and all dependent packages installs with proper versions.

To setup virtual environment with required production __AND__ dev ([sphinx](https://www.sphinx-doc.org/en/master/)) dependencies:
```bash
poetry install
```

with ONLY production packages (no sphinx):
```bash
poetry install --without dev
```


### use the package manager [pip](https://pip.pypa.io/en/stable/) to install dt-console.

```bash
pip install dt-console [--user]
```

## Usage
A demo cli has been included to show how these modules can be used.  The demo selectively displays each control (console tools, input prompt, messagebox, ProgressBar and Spinner) and source is provided to review for implementation details.

See [dt_tools.cli.dt_console_demos.py](https://github.com/JavaWiz1/dt-console/blob/develop/dt_tools/cli/dt_console_demos.py) for detailed demo examples (runnable demo)

To run the demo type:
```bash
python -m dt_tools.cli.dt_console_demos

# or if via source (and poetry)
poetry run python -m dt_tools.cli.dt_console_demos
```

Developer package documentation contains details on all classes and supporting code (i.e. constant namespaces and enums) use for method calls.  Docs can be found [here](https://htmlpreview.github.io/?https://github.com/JavaWiz1/dt-console/blob/develop/docs/html/index.html).


### Main classes/modules Overview

#### ConsoleHelper
ConsoleHelper provides methods for managing the console windows.  

```python
    from dt_tools.console.console_helper import ConsoleHelper
    import time

    console.clear_screen(cursor_home=True)
 
    console_size = console.get_console_size()
    row, col = console.cursor_current_position()
    print(f'Console size: {console_size}, cur pos: {row},{col}')
 
    console.print_at(row=3, col=5, msg="Here we are at row 3, column 5", eol='\n\n')
    time.sleep(.5)
 
    blue = console.cwrap('blue', cc.CBLUE)
    brown = console.cwrap('brown', cc.CBEIGE)
    green = console.cwrap('green', cc.CGREEN)
    text = f"The {blue} skies and the {brown} bear look wonderful in the {green} forest!"
    print(text)
 
    row, col = console.cursor_current_position()
    print(f'         at ({row},{col})', flush=True)
    time.sleep(2)
    console.print_at(row,col,'Finished')
```

#### ConsoleInputHelper
ConsoleInputHelper provides a customizable input prompt.

```python
    from dt_tools.console.console_helper import ConsoleInputHelper

    console_input = ConsoleInputHelper()

    resp = console_input.get_input_with_timeout(prompt='Do you want to continue (y/n) > ', 
                                                valid_responses=console_input.YES_NO_RESPONSE, 
                                                default='y', 
                                                timeout_secs=5)
    print(f'  returns: {resp}')

```

#### MessageBox
Message box implements Alert, Confirmation, Input Prompt, Password Prompt message boxes.  

```python
    import dt_tools.console.msgbox as msgbox

    resp = msgbox.alert(text='This is an alert box', title='ALERT no timeout')
    print(f'  mxgbox returns: {resp}')

    resp = msgbox.alert(text='This is an alert box', title='ALERT w/Timeout', timeout=3000)
    print(f'  mxgbox returns: {resp}')

```

#### ProgressBar
ProgressBar is an easy to use, customizable console ProgressBar which displays percentage complete and elapsed time.

```python
    from dt_tools.console.progress_bar import ProgressBar
    import time

    print('Progress bar...')
    pbar = ProgressBar(caption="Test bar 1", bar_length=40, max_increments=50, show_elapsed=False)
    for incr in range(1,51):
        pbar.display_progress(incr, f'incr [{incr}]')
        time.sleep(.15)    

    print('\nProgress bar with elapsed time...')
    pbar = ProgressBar(caption="Test bar 2", bar_length=40, max_increments=50, show_elapsed=True)
    for incr in range(1,51):
        pbar.display_progress(incr, f'incr [{incr}]')
        time.sleep(.15)
```

#### Spinner
Spinner is an easy to use, customizable console Spinner control which displays spinning icon and elapsed time.

```python
    from dt_tools.console.spinner import Spinner, SpinnerType
    import time

    # Example to display all spinner types for approx 5 sec. apiece
    for spinner_type in SpinnerType:
        spinner = Spinner(caption=spinner_type, spinner=spinner_type, show_elapsed=True)
        spinner.start_spinner()
        
        # Do long task...
        for cnt in range(1,20):
            time.sleep(.25)

        spinner.stop_spinner()
```


## License
[MIT](https://choosealicense.com/licenses/mit/)

The MessageBox code was derived from:  
PyMsgBox - BSD for PyMsgBox (see source for msgbox.py)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/JavaWiz1/dt-console",
    "name": "dt-console",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "python, dt-tools, cli, console, command-line, status bar, progress bar",
    "author": "Al DAmico",
    "author_email": "JavaWiz1@hotmail.com",
    "download_url": "https://files.pythonhosted.org/packages/19/35/9ed0a8b73e7a82a9c8e1c0a4c779d2d5e853d4d073c6f3b7ee27ba8ff56b/dt_console-0.1.11.tar.gz",
    "platform": null,
    "description": "# dt-console\n\ndt-console is a Python library to simplify CLI input and output for your python apps/scripts.  It has been tested in Windows and Linux.\n\nFeatures include:\n<ul>\n    <li><b>ConsoleHelper</b> - manage window and cursor control</li>\n    <ul>\n        <li>Set console window title</li>\n        <li>Show/Hide console window, set fg/bg colors</li>\n        <li>Set cursor style, location, ...</li>\n        <li>Routines to print and colorize output text</li>\n    </ul>\n    <li><b>ConsoleInputHelper</b> - Keyboard input prompts with validation and timeouts.</li>\n    <li><b>MessageBox</b> - GUI messsagebox (alert, confirm, input, password)</li>\n    <li><b>ProgressBar</b> - Display visual progress on screen via configurable progress bar</li>\n    <li><b>Spinner</b> - Display visual progress on screen via configuable spinner control</li>\n</ul>\n\nPackage donumentation can be found [here](https://htmlpreview.github.io/?https://github.com/JavaWiz1/dt-console/blob/develop/docs/html/index.html).\n\n## Installation\n\n### Download source code from githup via git\n```bash\ngit clone https://github.com/JavaWiz1/dt-console.git\n```\nNote, when downloading source, [Poetry](https://python-poetry.org/docs/) was used as the package manager.  Poetry \nhandles creating the virtual environment and all dependent packages installs with proper versions.\n\nTo setup virtual environment with required production __AND__ dev ([sphinx](https://www.sphinx-doc.org/en/master/)) dependencies:\n```bash\npoetry install\n```\n\nwith ONLY production packages (no sphinx):\n```bash\npoetry install --without dev\n```\n\n\n### use the package manager [pip](https://pip.pypa.io/en/stable/) to install dt-console.\n\n```bash\npip install dt-console [--user]\n```\n\n## Usage\nA demo cli has been included to show how these modules can be used.  The demo selectively displays each control (console tools, input prompt, messagebox, ProgressBar and Spinner) and source is provided to review for implementation details.\n\nSee [dt_tools.cli.dt_console_demos.py](https://github.com/JavaWiz1/dt-console/blob/develop/dt_tools/cli/dt_console_demos.py) for detailed demo examples (runnable demo)\n\nTo run the demo type:\n```bash\npython -m dt_tools.cli.dt_console_demos\n\n# or if via source (and poetry)\npoetry run python -m dt_tools.cli.dt_console_demos\n```\n\nDeveloper package documentation contains details on all classes and supporting code (i.e. constant namespaces and enums) use for method calls.  Docs can be found [here](https://htmlpreview.github.io/?https://github.com/JavaWiz1/dt-console/blob/develop/docs/html/index.html).\n\n\n### Main classes/modules Overview\n\n#### ConsoleHelper\nConsoleHelper provides methods for managing the console windows.  \n\n```python\n    from dt_tools.console.console_helper import ConsoleHelper\n    import time\n\n    console.clear_screen(cursor_home=True)\n \n    console_size = console.get_console_size()\n    row, col = console.cursor_current_position()\n    print(f'Console size: {console_size}, cur pos: {row},{col}')\n \n    console.print_at(row=3, col=5, msg=\"Here we are at row 3, column 5\", eol='\\n\\n')\n    time.sleep(.5)\n \n    blue = console.cwrap('blue', cc.CBLUE)\n    brown = console.cwrap('brown', cc.CBEIGE)\n    green = console.cwrap('green', cc.CGREEN)\n    text = f\"The {blue} skies and the {brown} bear look wonderful in the {green} forest!\"\n    print(text)\n \n    row, col = console.cursor_current_position()\n    print(f'         at ({row},{col})', flush=True)\n    time.sleep(2)\n    console.print_at(row,col,'Finished')\n```\n\n#### ConsoleInputHelper\nConsoleInputHelper provides a customizable input prompt.\n\n```python\n    from dt_tools.console.console_helper import ConsoleInputHelper\n\n    console_input = ConsoleInputHelper()\n\n    resp = console_input.get_input_with_timeout(prompt='Do you want to continue (y/n) > ', \n                                                valid_responses=console_input.YES_NO_RESPONSE, \n                                                default='y', \n                                                timeout_secs=5)\n    print(f'  returns: {resp}')\n\n```\n\n#### MessageBox\nMessage box implements Alert, Confirmation, Input Prompt, Password Prompt message boxes.  \n\n```python\n    import dt_tools.console.msgbox as msgbox\n\n    resp = msgbox.alert(text='This is an alert box', title='ALERT no timeout')\n    print(f'  mxgbox returns: {resp}')\n\n    resp = msgbox.alert(text='This is an alert box', title='ALERT w/Timeout', timeout=3000)\n    print(f'  mxgbox returns: {resp}')\n\n```\n\n#### ProgressBar\nProgressBar is an easy to use, customizable console ProgressBar which displays percentage complete and elapsed time.\n\n```python\n    from dt_tools.console.progress_bar import ProgressBar\n    import time\n\n    print('Progress bar...')\n    pbar = ProgressBar(caption=\"Test bar 1\", bar_length=40, max_increments=50, show_elapsed=False)\n    for incr in range(1,51):\n        pbar.display_progress(incr, f'incr [{incr}]')\n        time.sleep(.15)    \n\n    print('\\nProgress bar with elapsed time...')\n    pbar = ProgressBar(caption=\"Test bar 2\", bar_length=40, max_increments=50, show_elapsed=True)\n    for incr in range(1,51):\n        pbar.display_progress(incr, f'incr [{incr}]')\n        time.sleep(.15)\n```\n\n#### Spinner\nSpinner is an easy to use, customizable console Spinner control which displays spinning icon and elapsed time.\n\n```python\n    from dt_tools.console.spinner import Spinner, SpinnerType\n    import time\n\n    # Example to display all spinner types for approx 5 sec. apiece\n    for spinner_type in SpinnerType:\n        spinner = Spinner(caption=spinner_type, spinner=spinner_type, show_elapsed=True)\n        spinner.start_spinner()\n        \n        # Do long task...\n        for cnt in range(1,20):\n            time.sleep(.25)\n\n        spinner.stop_spinner()\n```\n\n\n## License\n[MIT](https://choosealicense.com/licenses/mit/)\n\nThe MessageBox code was derived from:  \nPyMsgBox - BSD for PyMsgBox (see source for msgbox.py)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Console helper tools for CLIs",
    "version": "0.1.11",
    "project_urls": {
        "Homepage": "https://github.com/JavaWiz1/dt-console",
        "Repository": "https://github.com/JavaWiz1/dt-console"
    },
    "split_keywords": [
        "python",
        " dt-tools",
        " cli",
        " console",
        " command-line",
        " status bar",
        " progress bar"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "446d371119249f757bfd7097bf7ef78f2e468904e8976164f470a65ce50c7a93",
                "md5": "b1142905d6ec3f9dc55fa2320aa48455",
                "sha256": "d86b986f5d9b2eb859c1f75de60d5a2dab512f8e56c3e2e8ccd60c2c70d6c1af"
            },
            "downloads": -1,
            "filename": "dt_console-0.1.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b1142905d6ec3f9dc55fa2320aa48455",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 27604,
            "upload_time": "2024-09-28T17:11:20",
            "upload_time_iso_8601": "2024-09-28T17:11:20.755156Z",
            "url": "https://files.pythonhosted.org/packages/44/6d/371119249f757bfd7097bf7ef78f2e468904e8976164f470a65ce50c7a93/dt_console-0.1.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "19359ed0a8b73e7a82a9c8e1c0a4c779d2d5e853d4d073c6f3b7ee27ba8ff56b",
                "md5": "61749d8b496061f353fb9b015ec39ad1",
                "sha256": "6a9bc6902d97e33aeba6839ae499d02085824ce581fddb901ae391688fb8c35a"
            },
            "downloads": -1,
            "filename": "dt_console-0.1.11.tar.gz",
            "has_sig": false,
            "md5_digest": "61749d8b496061f353fb9b015ec39ad1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 22505,
            "upload_time": "2024-09-28T17:11:22",
            "upload_time_iso_8601": "2024-09-28T17:11:22.171429Z",
            "url": "https://files.pythonhosted.org/packages/19/35/9ed0a8b73e7a82a9c8e1c0a4c779d2d5e853d4d073c6f3b7ee27ba8ff56b/dt_console-0.1.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-28 17:11:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "JavaWiz1",
    "github_project": "dt-console",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "dt-console"
}
        
Elapsed time: 2.21541s