consoleiotools


Nameconsoleiotools JSON
Version 4.6.15 PyPI version JSON
download
home_pageNone
SummaryConsole tools for inputs and outputs in Python
upload_time2024-10-08 02:22:50
maintainerNone
docs_urlNone
authorNone
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 rich
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.echo("Hello World", indent=1)  # indent level, default is 0.
| |-- Hello World

>>> cit.echo("Hello World", indent=-1)  # level < 0 means the last line of this indent.
| `-- Hello World

>>> cit.echo("Hello World", indent=3)  # 3 level of indent.
| |   |   |-- 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  # yellow

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

>>> 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": null,
    "name": "consoleiotools",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "python, console, input, output, tool",
    "author": null,
    "author_email": "Kyan <kai@kyan001.com>",
    "download_url": "https://files.pythonhosted.org/packages/7a/d1/dc8dc48321147eb2ec83bd751a3952f9a431de20e29795174ca9a274b049/consoleiotools-4.6.15.tar.gz",
    "platform": null,
    "description": "# PyConsoleIOTools\r\n![PyPI - Downloads](https://img.shields.io/pypi/dm/consoleiotools.svg)\r\n![GitHub release](https://img.shields.io/github/release/kyan001/PyConsoleIOTools.svg)\r\n[![GitHub license](https://img.shields.io/github/license/kyan001/PyConsoleIOTools.svg)](https://github.com/kyan001/PyConsoleIOTools/blob/master/LICENSE)\r\n\r\n## Installation\r\n\r\n```sh\r\npip install consoleiotools  # install\r\npip install --upgrade consoleiotools  # update\r\npython -m consoleiotools  # examples\r\n```\r\n\r\n## Get Started\r\n\r\n```python\r\nimport consoleiotools as cit\r\nprint(cit.__version__)\r\n```\r\n\r\n## Prints on Screen\r\n\r\n```python\r\n>>> cit.start()\r\n# blank line\r\n\r\n>>> cit.title(\"Session Name\")\r\n+--------------+\r\n| SESSION NAME |\r\n+--------------+\r\n\r\n>>> cit.echo(\"Hello World\")\r\n| Hello World\r\n\r\n>>> cit.echo(\"Hello World\", pre=\"say\", bar=\"!\")\r\n! (Say) Hello World\r\n\r\n>>> cit.echo(\"Hello World\", indent=1)  # indent level, default is 0.\r\n| |-- Hello World\r\n\r\n>>> cit.echo(\"Hello World\", indent=-1)  # level < 0 means the last line of this indent.\r\n| `-- Hello World\r\n\r\n>>> cit.echo(\"Hello World\", indent=3)  # 3 level of indent.\r\n| |   |   |-- Hello World\r\n\r\n>>> cit.ask(\"Hello World\")\r\n| (?) Hello World\r\n\r\n>>> cit.info(\"Hello World\")\r\n| (Info) Hello World\r\n\r\n>>> cit.warn(\"Hello World\")\r\n| (Warning) Hello World\r\n\r\n>>> cit.err(\"Hello World\")\r\n| (Error) Hello World\r\n\r\n>>> cit.mute(\"Hello World\")\r\n| Hello World  # muted by dim\r\n\r\n>>> cit.print(\"[yellow]Hello World[/]\")  # print with styles\r\nHello World  # yellow\r\n\r\n>>> cit.print(cit.escape(\"[yellow]Hello World[/]\"))  # escape `[` -> `\\[` if not escaped. escape `\\` -> `\\\\` if not used as escape char.\r\n[yellow]Hello World[/]\r\n\r\n>>> cit.markdown(\"# Header\")  # print markdown\r\n+--------------+\r\n|    Header    |\r\n+--------------+\r\n\r\n>>> cit.rule()  # print horizontal rule\r\n----------------------------------------\r\n\r\n>>> cit.rule(\"Title\", style=\"blue\", align=\"center\")  # print horizontal rule with Title. align = center|left|right\r\n---------------- Title ----------------\r\n\r\n\r\n>>> cit.panel(\"Panel\", title=\"Panel Title\", subtitle=\"Panel Subtitle\")  # print text in a panel\r\n+---------- Panel Title ----------+\r\n| Panel                           |  # full width\r\n+-------- Panel Subtitle ---------+\r\n\r\n>>> cit.panel(\"Panel\", title=\"Panel Title\", subtitle=\"Panel Subtitle\", expand=False, style=\"blue\")  # fit panel to text\r\n+- Panel Title -+  # blue\r\n| Panel         |\r\n+- Panel Subtit-+\r\n\r\n>>> cit.end()\r\n`\r\n\r\n>>> cit.br()\r\n# blank line\r\n\r\n>>> cit.br(2)\r\n# blank line\r\n# blank line\r\n\r\n>>> for var in cit.track(iterables, \"Progress\"): pass\r\n| : Progress ---------------------===================  52% 0:00:52 - 52/100\r\n\r\n>>> cit.__ascii__ = True  # use ascii chars only.\r\n```\r\n\r\n## Get User Input\r\n\r\n```python\r\n>>> cit.get_input()  # Get user input from stdin\r\n> Hello World\r\n'Hello World'\r\n\r\n>>> cit.get_input(\"Question?\")  # With a question\r\n| (?) Question?\r\n> Yes\r\n'Yes'\r\n\r\n>>> cit.get_input(prompt=\"Answer:\")  # With a customized prompt.\r\nAnswer: Apple\r\n'Apple'\r\n\r\n>>> cit.get_input(\"Continue?\", default=\"yes\")  # With a default answer.\r\n| (?) Continue?\r\n> (yes)  # Entered nothing\r\n'yes'\r\n\r\n>>> cit.get_input(strip=False)  # Do not remove leading and trailing whitespaces from user input.\r\n>       # Whitespaces\r\n'    '\r\n\r\n>>> cit.get_choice([\"Apple\", \"Google\"])  # Enter number to select.\r\n|  1) Apple\r\n|  2) Google\r\n> 2\r\n'Google'\r\n\r\n>>> cit.get_choice([\"Apple\", \"Google\"])  # Enter string is ok too.\r\n|  1) Apple\r\n|  2) Google\r\n> Google\r\n'Google'\r\n\r\n>>> cit.get_choice([\"Apple\", \"Google\"], exitable=True)  # Add a choice of exit in menu.\r\n|  1) Apple\r\n|  2) Google\r\n|  0) ** EXIT **\r\n> 0\r\nNone\r\n\r\n>>> cit.get_choices([\"Apple\", \"Google\"])  # Multiple Selection\r\n|  1) [ ] Apple\r\n|  2) [ ] Google\r\n> 1  # Enter number to check or uncheck selections\r\n|  1) [+] Apple\r\n|  2) [ ] Google\r\n|  0) ** DONE **\r\n> Google  # Enter string is ok too.\r\n|  1) [+] Apple\r\n|  2) [+] Google\r\n|  0) ** DONE **\r\n> 0  # Enter 0 when done.\r\n['Apple', 'Google']  # return [] is no selections.\r\n\r\n>>> cit.get_choices([\"Apple\", \"Google\"], allable=True)  # Add a choice of select all in menu.\r\n|  a) ** ALL **\r\n|  1) [ ] Apple\r\n|  2) [ ] Google\r\n> a  # Enter `a` to check all. If `a` is in choices, enter `all`.\r\n|  a) ** ALL **\r\n|  1) [+] Apple\r\n|  2) [+] Google\r\n|  0) ** DONE **\r\n> 0\r\n['Apple', 'Google']\r\n\r\n>>> cit.get_choices([\"Apple\", \"Google\"], exitable=True)  # Add a choice of exit in menu.\r\n|  1) [ ] Apple\r\n|  2) [ ] Google\r\n|  0) ** EXIT **\r\n> 0\r\n[]  # Empty list returned.\r\n```\r\n\r\n## File IO\r\n\r\n```python\r\n>>> cit.read_file(\"/path/to/file\")\r\n'Hello World'\r\n\r\n>>> cit.read_file(\"/path/to/file\", with_encoding=True)\r\n('Hello World', 'utf-8')\r\n\r\n>>> cit.write_file(\"/path/to/file\", \"Hello World\")  # Append content to file.\r\n11  # writed bytes\r\n\r\n>>> cit.write_file(\"/path/to/file\", \"Hello World\", overwrite=True)  # Overwrite if file exists.\r\n11  # writed bytes\r\n```\r\n\r\n## Controls\r\n\r\n```python\r\n>>> cit.pause()\r\n| Press [Enter] to Continue...\r\n\r\n>>> cit.bye()\r\n# exit\r\n\r\n>>> cit.bye(0)\r\n# exit with code 0\r\n\r\n>>> cit.bye(\"Seeya\")\r\nSeeya\r\n# exit\r\n```\r\n\r\n## Decorators\r\n\r\n```python\r\n@cit.as_session(\"Hello\")  # String as the Title of the session.\r\ndef my_func():\r\n    cit.echo(\"World\")\r\n\r\n>>> my_func()\r\n+---------+\r\n| HELLO() |\r\n+---------+\r\n| World\r\n`\r\n\r\n@cit.as_session  # Use function name as the Title of the session.\r\ndef underscore_orCamel():\r\n    pass\r\n\r\n>>> underscore_orCamel()\r\n+-----------------------+\r\n| UNDERSCORE OR CAMEL() |\r\n+-----------------------+\r\n`\r\n\r\n@cit.deprecated_by(new_func):  # A function object as argument.\r\ndef old_func(...):\r\n    pass  # code here won't be actually executed.\r\n\r\n>>> old_func(...)\r\nFunction `old_func` is deprecated, now calling `new_func` instead.  # Warning printed to stderr.\r\n# new_func(...) is called\r\n```\r\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.6.15",
    "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": "0138add58b26757e939e15c4b698a68b2b4eb99bdcfe41ad7d61af9c81063374",
                "md5": "00d2b83ae2f83c44281aa3c59db8fe1a",
                "sha256": "8d37a5ff93493d9bfd4f2144e51c0ed561c3ba1da04ca7ef6e5139c679e7d1b6"
            },
            "downloads": -1,
            "filename": "consoleiotools-4.6.15-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "00d2b83ae2f83c44281aa3c59db8fe1a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 9484,
            "upload_time": "2024-10-08T02:22:48",
            "upload_time_iso_8601": "2024-10-08T02:22:48.773937Z",
            "url": "https://files.pythonhosted.org/packages/01/38/add58b26757e939e15c4b698a68b2b4eb99bdcfe41ad7d61af9c81063374/consoleiotools-4.6.15-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7ad1dc8dc48321147eb2ec83bd751a3952f9a431de20e29795174ca9a274b049",
                "md5": "6f1f0ba95d04898c9dcab06734d03a4c",
                "sha256": "05743d51e40611a4cb639676b708438bd8297982fc22c29defb90511078001c2"
            },
            "downloads": -1,
            "filename": "consoleiotools-4.6.15.tar.gz",
            "has_sig": false,
            "md5_digest": "6f1f0ba95d04898c9dcab06734d03a4c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 11370,
            "upload_time": "2024-10-08T02:22:50",
            "upload_time_iso_8601": "2024-10-08T02:22:50.549910Z",
            "url": "https://files.pythonhosted.org/packages/7a/d1/dc8dc48321147eb2ec83bd751a3952f9a431de20e29795174ca9a274b049/consoleiotools-4.6.15.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-08 02:22:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kyan001",
    "github_project": "PyConsoleIOTools",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "rich",
            "specs": []
        }
    ],
    "lcname": "consoleiotools"
}
        
Elapsed time: 0.35071s