Skip to main content

Console tools for inputs and outputs in Python

Project description

PyConsoleIOTools

PyPI - Downloads GitHub release GitHub license

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.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(var)  # print variable
...

>>> 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

>>> 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_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

consoleiotools-4.1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

consoleiotools-4.1.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file consoleiotools-4.1.0.tar.gz.

File metadata

  • Download URL: consoleiotools-4.1.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for consoleiotools-4.1.0.tar.gz
Algorithm Hash digest
SHA256 36009a044d24757a8ac9653f402db12b1147c6b76362cf82d4ec0a1b2d75d119
MD5 c9d481698577faf2ccef427faa4424e9
BLAKE2b-256 ba4789158bca78ffaf502319c11a28c90918d28c2c3d7ae2df5d868c237daa5d

See more details on using hashes here.

File details

Details for the file consoleiotools-4.1.0-py3-none-any.whl.

File metadata

  • Download URL: consoleiotools-4.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for consoleiotools-4.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 333a74ebcd90caef1802a8d01b0192a51b015bfa0a9dc04ec508e39f21ff954b
MD5 f7fb084ed3f5faacebeb2a3be442a374
BLAKE2b-256 f6e73d01ea95ec6a821af359e31f1a2550df3582da9a73e561cee7c6e5acaa04

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page