PyConsoleIOTools
Installation
pip install consoleiotools # install
pip install --upgrade consoleiotools # update
python -m consoleiotools # examples
Get Started
import consoleiotools as cit
print(cit.__version__)
Prints on Screen
>>> 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.debug("Hello World")
| (Debug) Hello World # with blue background
>>> 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
>>> cit.start().title().br().end().pause()
.echo().ask().info().warn().err().mute()
.print().markdown().rule().panel() # chaining
...
>>> for var in cit.track(iterables, "Progress"): pass # track iterable progress
| : Progress ---------------------=================== 52% 0:00:52 - 52/100
>>> cit.__ascii__ = True # use ascii chars only.
Get User Input
>>> 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
>>> 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
>>> cit.pause()
| Press [Enter] to Continue...
>>> cit.bye()
# exit with code 0 (Success)
>>> cit.bye(error=True)
# exit with code 1 (Error)
>>> cit.bye("Seeya")
| (Info) Seeya
# exit with code 0 (Success)
>>> cit.bye("Seeya", error=True)
| (Error) Seeya
# exit with code 1 (Error)
Decorators
@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
Metadata
Release files for consoleiotools 6.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| consoleiotools-6.0.0.tar.gz | 11.5 kB | Without provenance | Details for consoleiotools-6.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| consoleiotools-6.0.0-py3-none-any.whl | Python 3 | none | any | Details for consoleiotools-6.0.0-py3-none-any.whl |
Total release size: 20.8 kB
Release files / consoleiotools-6.0.0.tar.gz
| Download URL | consoleiotools-6.0.0.tar.gz |
|---|---|
| Size | 11.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
01efe0e07f3186c404b791be23b566d38fbb778d80a8c738e3a078af4e660741
|
|
BLAKE2b-256 checksum How to use checksums |
3d8ffe983260c5443d0dd72c9c46e47bcb0cc5a80d28963eae60aac7155790d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / consoleiotools-6.0.0-py3-none-any.whl
| Download URL | consoleiotools-6.0.0-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a97ad0085b4c24b139d932955d28df1804c05eaa6c802957da88887cae28106e
|
|
BLAKE2b-256 checksum How to use checksums |
9fa831537aa4ed9aa00ab2ccb8b562211f93f593397921272b4a5805e55f7b04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for consoleiotools 6.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.