Some console tools for inputs and outputs
Project description
PyConsoleIOTools
Installation
pip install consoleiotools # install
pip install --upgrade consoleiotools # update
python -m consoleiotools # show README
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.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.dim('Hello World')
| Hello World # gray
>>> cit.print(var) # print variable
...
>>> cit.markdown("# Header") # print Markdown
+--------------+
| Header |
+--------------+
>>> cit.end()
`
>>> cit.br()
# blank line
>>> cit.br(2)
# blank line
# blank line
Get User Input
>>> cit.get_input()
> Hello World
'Hello World'
>>> 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')
'File contents'
>>> cit.read_file('/path/to/file', with_encoding=True)
('File contents', 'utf-8')
>>> cit.write_file('/path/to/file', 'Contents') # Append content to file.
8 # writed bytes
>>> cit.write_file('/path/to/file', 'Contents', overwrite=True) # Overwrite if file exists.
8 # writed bytes
Controls
>>> cit.pause()
| Press [Enter] to Continue...
>>> cit.bye()
# exit
>>> cit.bye(0)
# exit with code 0
>>> cit.bye('Seeya')
Seeya
# exit
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() |
+-----------------------+
`
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
consoleiotools-3.3.1.tar.gz
(5.8 kB
view hashes)
Built Distribution
Close
Hashes for consoleiotools-3.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e466bc3caeee60a026274d5217b93b0f273c46f98721bff700e796a44ca2bdef |
|
MD5 | 3d60c0e169fbd279906a627257e1aab6 |
|
BLAKE2b-256 | 1f3681ffbd8b19cef75e7fa9c974e7a44ee1e336b64a88876b14c8d9269cd84b |