PyConsoleIOTools
Installation
pip install consoleiotools
pip install --upgrade consoleiotools
python -m consoleiotools
Get Started
import consoleiotools as cit
print(cit.__version__)
Prints on Screen
>>> cit.start()
>>> 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)
| |-- Hello World
>>> cit.echo("Hello World", indent=-1)
| `-- Hello World
>>> cit.echo("Hello World", indent=3)
| | | |-- 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
>>> cit.print("[yellow]Hello World[/]")
Hello World
>>> cit.print(cit.escape("[yellow]Hello World[/]"))
[yellow]Hello World[/]
>>> cit.markdown("# Header")
+--------------+
| Header |
+--------------+
>>> cit.rule()
----------------------------------------
>>> cit.rule("Title", style="blue", align="center")
---------------- Title ----------------
>>> cit.panel("Panel", title="Panel Title", subtitle="Panel Subtitle")
+---------- Panel Title ----------+
| Panel |
+-------- Panel Subtitle ---------+
>>> cit.panel("Panel", title="Panel Title", subtitle="Panel Subtitle", expand=False, style="blue")
+- Panel Title -+
| Panel |
+- Panel Subtit-+
>>> cit.end()
`
>>> cit.br()
>>> cit.br(2)
>>> for var in cit.track(iterables, "Progress"): pass
| : Progress ---------------------=================== 52% 0:00:52 - 52/100
>>> cit.__ascii__ = True
Get User Input
>>> cit.get_input()
> Hello World
'Hello World'
>>> cit.get_input("Question?")
| (?) Question?
> Yes
'Yes'
>>> cit.get_input(prompt="Answer:")
Answer: Apple
'Apple'
>>> cit.get_input("Continue?", default="yes")
| (?) Continue?
> (yes)
'yes'
>>> cit.get_input(strip=False)
>
' '
>>> cit.get_choice(["Apple", "Google"])
| 1) Apple
| 2) Google
> 2
'Google'
>>> cit.get_choice(["Apple", "Google"])
| 1) Apple
| 2) Google
> Google
'Google'
>>> cit.get_choice(["Apple", "Google"], exitable=True)
| 1) Apple
| 2) Google
| 0) ** EXIT **
> 0
None
>>> cit.get_choices(["Apple", "Google"])
| 1) [ ] Apple
| 2) [ ] Google
> 1
| 1) [+] Apple
| 2) [ ] Google
| 0) ** DONE **
> Google
| 1) [+] Apple
| 2) [+] Google
| 0) ** DONE **
> 0
['Apple', 'Google']
>>> cit.get_choices(["Apple", "Google"], allable=True)
| a) ** ALL **
| 1) [ ] Apple
| 2) [ ] Google
> a
| a) ** ALL **
| 1) [+] Apple
| 2) [+] Google
| 0) ** DONE **
> 0
['Apple', 'Google']
>>> cit.get_choices(["Apple", "Google"], exitable=True)
| 1) [ ] Apple
| 2) [ ] Google
| 0) ** EXIT **
> 0
[]
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")
11
>>> cit.write_file("/path/to/file", "Hello World", overwrite=True)
11
Controls
>>> cit.pause()
| Press [Enter] to Continue...
>>> cit.bye()
>>> cit.bye(0)
>>> cit.bye("Seeya")
Seeya
Decorators
@cit.as_session("Hello")
def my_func():
cit.echo("World")
>>> my_func()
+---------+
| HELLO() |
+---------+
| World
`
@cit.as_session
def underscore_orCamel():
pass
>>> underscore_orCamel()
+-----------------------+
| UNDERSCORE OR CAMEL() |
+-----------------------+
`
@cit.deprecated_by(new_func):
def old_func(...):
pass
>>> old_func(...)
Function `old_func` is deprecated, now calling `new_func` instead.