consoleiotools


Nameconsoleiotools JSON
Version 4.5.0 PyPI version JSON
download
home_page
SummaryConsole tools for inputs and outputs in Python
upload_time2023-11-19 10:15:02
maintainer
docs_urlNone
author
requires_python>=3.6
licenseThe MIT License (MIT) Copyright (c) 2016 Kyan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords python console input output tool
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyConsoleIOTools
![PyPI - Downloads](https://img.shields.io/pypi/dm/consoleiotools.svg)
![GitHub release](https://img.shields.io/github/release/kyan001/PyConsoleIOTools.svg)
[![GitHub license](https://img.shields.io/github/license/kyan001/PyConsoleIOTools.svg)](https://github.com/kyan001/PyConsoleIOTools/blob/master/LICENSE)

## Installation

```sh
pip install consoleiotools  # install
pip install --upgrade consoleiotools  # update
python -m consoleiotools  # examples
```

## Get Started

```python
import consoleiotools as cit
print(cit.__version__)
```

## Prints on Screen

```python
>>> cit.start()
# blank line

>>> cit.title("Session Name")
+--------------+
| SESSION NAME |
+--------------+

>>> cit.echo("Hello World")
| Hello World

>>> cit.echo("Hello World", pre="say", bar="!")
! (Say) Hello World

>>> cit.ask("Hello World")
| (?) Hello World

>>> cit.info("Hello World")
| (Info) Hello World

>>> cit.warn("Hello World")
| (Warning) Hello World

>>> cit.err("Hello World")
| (Error) Hello World

>>> cit.mute("Hello World")
| Hello World  # muted by dim

>>> cit.print("[yellow]Hello World[/]")  # print with styles
Hello World

>>> cit.print(cit.escape("[yellow]Hello World[/]"))  # escape `[` -> `\[` if not escaped. escape `\` -> `\\` if not used as escape char.
[\]

>>> cit.markdown("# Header")  # print markdown
+--------------+
|    Header    |
+--------------+

>>> cit.rule()  # print horizontal rule
----------------------------------------

>>> cit.rule("Title", style="blue", align="center")  # print horizontal rule with Title. align = center|left|right
---------------- Title ----------------


>>> cit.panel("Panel", title="Panel Title", subtitle="Panel Subtitle")  # print text in a panel
+---------- Panel Title ----------+
| Panel                           |  # full width
+-------- Panel Subtitle ---------+

>>> cit.panel("Panel", title="Panel Title", subtitle="Panel Subtitle", expand=False, style="blue")  # fit panel to text
+- Panel Title -+  # blue
| Panel         |
+- Panel Subtit-+

>>> cit.end()
`

>>> cit.br()
# blank line

>>> cit.br(2)
# blank line
# blank line

>>> for var in cit.track(iterables, "Progress"): pass
| : Progress ---------------------===================  52% 0:00:52 - 52/100

>>> cit.__ascii__ = True  # use ascii chars only.
```

## Get User Input

```python
>>> cit.get_input()  # Get user input from stdin
> Hello World
'Hello World'

>>> cit.get_input("Question?")  # With a question
| (?) Question?
> Yes
'Yes'

>>> cit.get_input(prompt="Answer:")  # With a customized prompt.
Answer: Apple
'Apple'

>>> cit.get_input("Continue?", default="yes")  # With a default answer.
| (?) Continue?
> (yes)  # Entered nothing
'yes'

>>> cit.get_input(strip=False)  # Do not remove leading and trailing whitespaces from user input.
>       # Whitespaces
'    '

>>> cit.get_choice(["Apple", "Google"])  # Enter number to select.
|  1) Apple
|  2) Google
> 2
'Google'

>>> cit.get_choice(["Apple", "Google"])  # Enter string is ok too.
|  1) Apple
|  2) Google
> Google
'Google'

>>> cit.get_choice(["Apple", "Google"], exitable=True)  # Add a choice of exit in menu.
|  1) Apple
|  2) Google
|  0) ** EXIT **
> 0
None

>>> cit.get_choices(["Apple", "Google"])  # Multiple Selection
|  1) [ ] Apple
|  2) [ ] Google
> 1  # Enter number to check or uncheck selections
|  1) [+] Apple
|  2) [ ] Google
|  0) ** DONE **
> Google  # Enter string is ok too.
|  1) [+] Apple
|  2) [+] Google
|  0) ** DONE **
> 0  # Enter 0 when done.
['Apple', 'Google']  # return [] is no selections.

>>> cit.get_choices(["Apple", "Google"], allable=True)  # Add a choice of select all in menu.
|  a) ** ALL **
|  1) [ ] Apple
|  2) [ ] Google
> a  # Enter `a` to check all. If `a` is in choices, enter `all`.
|  a) ** ALL **
|  1) [+] Apple
|  2) [+] Google
|  0) ** DONE **
> 0
['Apple', 'Google']

>>> cit.get_choices(["Apple", "Google"], exitable=True)  # Add a choice of exit in menu.
|  1) [ ] Apple
|  2) [ ] Google
|  0) ** EXIT **
> 0
[]  # Empty list returned.
```

## File IO

```python
>>> cit.read_file("/path/to/file")
'Hello World'

>>> cit.read_file("/path/to/file", with_encoding=True)
('Hello World', 'utf-8')

>>> cit.write_file("/path/to/file", "Hello World")  # Append content to file.
11  # writed bytes

>>> cit.write_file("/path/to/file", "Hello World", overwrite=True)  # Overwrite if file exists.
11  # writed bytes
```

## Controls

```python
>>> cit.pause()
| Press [Enter] to Continue...

>>> cit.bye()
# exit

>>> cit.bye(0)
# exit with code 0

>>> cit.bye("Seeya")
Seeya
# exit
```

## Decorators

```python
@cit.as_session("Hello")  # String as the Title of the session.
def my_func():
    cit.echo("World")

>>> my_func()
+---------+
| HELLO() |
+---------+
| World
`

@cit.as_session  # Use function name as the Title of the session.
def underscore_orCamel():
    pass

>>> underscore_orCamel()
+-----------------------+
| UNDERSCORE OR CAMEL() |
+-----------------------+
`

@cit.deprecated_by(new_func):  # A function object as argument.
def old_func(...):
    pass  # code here won't be actually executed.

>>> old_func(...)
Function `old_func` is deprecated, now calling `new_func` instead.  # Warning printed to stderr.
# new_func(...) is called
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "consoleiotools",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "python,console,input,output,tool",
    "author": "",
    "author_email": "Kyan <kai@kyan001.com>",
    "download_url": "https://files.pythonhosted.org/packages/72/16/59df3a55b3a87991dfa35400563f14bcdbdd82579211b2689481fa6849c1/consoleiotools-4.5.0.tar.gz",
    "platform": null,
    "description": "# PyConsoleIOTools\n![PyPI - Downloads](https://img.shields.io/pypi/dm/consoleiotools.svg)\n![GitHub release](https://img.shields.io/github/release/kyan001/PyConsoleIOTools.svg)\n[![GitHub license](https://img.shields.io/github/license/kyan001/PyConsoleIOTools.svg)](https://github.com/kyan001/PyConsoleIOTools/blob/master/LICENSE)\n\n## Installation\n\n```sh\npip install consoleiotools  # install\npip install --upgrade consoleiotools  # update\npython -m consoleiotools  # examples\n```\n\n## Get Started\n\n```python\nimport consoleiotools as cit\nprint(cit.__version__)\n```\n\n## Prints on Screen\n\n```python\n>>> cit.start()\n# blank line\n\n>>> cit.title(\"Session Name\")\n+--------------+\n| SESSION NAME |\n+--------------+\n\n>>> cit.echo(\"Hello World\")\n| Hello World\n\n>>> cit.echo(\"Hello World\", pre=\"say\", bar=\"!\")\n! (Say) Hello World\n\n>>> cit.ask(\"Hello World\")\n| (?) Hello World\n\n>>> cit.info(\"Hello World\")\n| (Info) Hello World\n\n>>> cit.warn(\"Hello World\")\n| (Warning) Hello World\n\n>>> cit.err(\"Hello World\")\n| (Error) Hello World\n\n>>> cit.mute(\"Hello World\")\n| Hello World  # muted by dim\n\n>>> cit.print(\"[yellow]Hello World[/]\")  # print with styles\nHello World\n\n>>> cit.print(cit.escape(\"[yellow]Hello World[/]\"))  # escape `[` -> `\\[` if not escaped. escape `\\` -> `\\\\` if not used as escape char.\n[\\]\n\n>>> cit.markdown(\"# Header\")  # print markdown\n+--------------+\n|    Header    |\n+--------------+\n\n>>> cit.rule()  # print horizontal rule\n----------------------------------------\n\n>>> cit.rule(\"Title\", style=\"blue\", align=\"center\")  # print horizontal rule with Title. align = center|left|right\n---------------- Title ----------------\n\n\n>>> cit.panel(\"Panel\", title=\"Panel Title\", subtitle=\"Panel Subtitle\")  # print text in a panel\n+---------- Panel Title ----------+\n| Panel                           |  # full width\n+-------- Panel Subtitle ---------+\n\n>>> cit.panel(\"Panel\", title=\"Panel Title\", subtitle=\"Panel Subtitle\", expand=False, style=\"blue\")  # fit panel to text\n+- Panel Title -+  # blue\n| Panel         |\n+- Panel Subtit-+\n\n>>> cit.end()\n`\n\n>>> cit.br()\n# blank line\n\n>>> cit.br(2)\n# blank line\n# blank line\n\n>>> for var in cit.track(iterables, \"Progress\"): pass\n| : Progress ---------------------===================  52% 0:00:52 - 52/100\n\n>>> cit.__ascii__ = True  # use ascii chars only.\n```\n\n## Get User Input\n\n```python\n>>> cit.get_input()  # Get user input from stdin\n> Hello World\n'Hello World'\n\n>>> cit.get_input(\"Question?\")  # With a question\n| (?) Question?\n> Yes\n'Yes'\n\n>>> cit.get_input(prompt=\"Answer:\")  # With a customized prompt.\nAnswer: Apple\n'Apple'\n\n>>> cit.get_input(\"Continue?\", default=\"yes\")  # With a default answer.\n| (?) Continue?\n> (yes)  # Entered nothing\n'yes'\n\n>>> cit.get_input(strip=False)  # Do not remove leading and trailing whitespaces from user input.\n>       # Whitespaces\n'    '\n\n>>> cit.get_choice([\"Apple\", \"Google\"])  # Enter number to select.\n|  1) Apple\n|  2) Google\n> 2\n'Google'\n\n>>> cit.get_choice([\"Apple\", \"Google\"])  # Enter string is ok too.\n|  1) Apple\n|  2) Google\n> Google\n'Google'\n\n>>> cit.get_choice([\"Apple\", \"Google\"], exitable=True)  # Add a choice of exit in menu.\n|  1) Apple\n|  2) Google\n|  0) ** EXIT **\n> 0\nNone\n\n>>> cit.get_choices([\"Apple\", \"Google\"])  # Multiple Selection\n|  1) [ ] Apple\n|  2) [ ] Google\n> 1  # Enter number to check or uncheck selections\n|  1) [+] Apple\n|  2) [ ] Google\n|  0) ** DONE **\n> Google  # Enter string is ok too.\n|  1) [+] Apple\n|  2) [+] Google\n|  0) ** DONE **\n> 0  # Enter 0 when done.\n['Apple', 'Google']  # return [] is no selections.\n\n>>> cit.get_choices([\"Apple\", \"Google\"], allable=True)  # Add a choice of select all in menu.\n|  a) ** ALL **\n|  1) [ ] Apple\n|  2) [ ] Google\n> a  # Enter `a` to check all. If `a` is in choices, enter `all`.\n|  a) ** ALL **\n|  1) [+] Apple\n|  2) [+] Google\n|  0) ** DONE **\n> 0\n['Apple', 'Google']\n\n>>> cit.get_choices([\"Apple\", \"Google\"], exitable=True)  # Add a choice of exit in menu.\n|  1) [ ] Apple\n|  2) [ ] Google\n|  0) ** EXIT **\n> 0\n[]  # Empty list returned.\n```\n\n## File IO\n\n```python\n>>> cit.read_file(\"/path/to/file\")\n'Hello World'\n\n>>> cit.read_file(\"/path/to/file\", with_encoding=True)\n('Hello World', 'utf-8')\n\n>>> cit.write_file(\"/path/to/file\", \"Hello World\")  # Append content to file.\n11  # writed bytes\n\n>>> cit.write_file(\"/path/to/file\", \"Hello World\", overwrite=True)  # Overwrite if file exists.\n11  # writed bytes\n```\n\n## Controls\n\n```python\n>>> cit.pause()\n| Press [Enter] to Continue...\n\n>>> cit.bye()\n# exit\n\n>>> cit.bye(0)\n# exit with code 0\n\n>>> cit.bye(\"Seeya\")\nSeeya\n# exit\n```\n\n## Decorators\n\n```python\n@cit.as_session(\"Hello\")  # String as the Title of the session.\ndef my_func():\n    cit.echo(\"World\")\n\n>>> my_func()\n+---------+\n| HELLO() |\n+---------+\n| World\n`\n\n@cit.as_session  # Use function name as the Title of the session.\ndef underscore_orCamel():\n    pass\n\n>>> underscore_orCamel()\n+-----------------------+\n| UNDERSCORE OR CAMEL() |\n+-----------------------+\n`\n\n@cit.deprecated_by(new_func):  # A function object as argument.\ndef old_func(...):\n    pass  # code here won't be actually executed.\n\n>>> old_func(...)\nFunction `old_func` is deprecated, now calling `new_func` instead.  # Warning printed to stderr.\n# new_func(...) is called\n```\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT)  Copyright (c) 2016 Kyan  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Console tools for inputs and outputs in Python",
    "version": "4.5.0",
    "project_urls": {
        "Homepage": "https://github.com/kyan001/PyConsoleIOTools",
        "Issue Tracker": "https://github.com/kyan001/PyConsoleIOTools/issues",
        "Source Code": "https://github.com/kyan001/PyConsoleIOTools"
    },
    "split_keywords": [
        "python",
        "console",
        "input",
        "output",
        "tool"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "27828136293c4f74e7ac481681a10271ee73898729277c8db710868caefe6f8c",
                "md5": "5de9ffbfb4dcd5a5047fd67a655910e3",
                "sha256": "e451fd6ff081b05b42be7d61bb7b15145cea727d9812aac379c16cf726966804"
            },
            "downloads": -1,
            "filename": "consoleiotools-4.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5de9ffbfb4dcd5a5047fd67a655910e3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 9162,
            "upload_time": "2023-11-19T10:15:00",
            "upload_time_iso_8601": "2023-11-19T10:15:00.552858Z",
            "url": "https://files.pythonhosted.org/packages/27/82/8136293c4f74e7ac481681a10271ee73898729277c8db710868caefe6f8c/consoleiotools-4.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "721659df3a55b3a87991dfa35400563f14bcdbdd82579211b2689481fa6849c1",
                "md5": "f33423028117a9965219791561d5b7ef",
                "sha256": "fbd081c60a91571a1a8b5fa58f8ef3c259ac38c655c6ed448711f4eeafd29d91"
            },
            "downloads": -1,
            "filename": "consoleiotools-4.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "f33423028117a9965219791561d5b7ef",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 10879,
            "upload_time": "2023-11-19T10:15:02",
            "upload_time_iso_8601": "2023-11-19T10:15:02.835461Z",
            "url": "https://files.pythonhosted.org/packages/72/16/59df3a55b3a87991dfa35400563f14bcdbdd82579211b2689481fa6849c1/consoleiotools-4.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-19 10:15:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kyan001",
    "github_project": "PyConsoleIOTools",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "consoleiotools"
}
        
Elapsed time: 0.14668s