Skip to main content

Convenient formatting, coloring, and utility for user-facing print statements.

Project description

display-session is an MIT licensed Python package that provides easy ANSI formatting and utility to Python’s built in print statement.

This project stemmed from wanting better looking, more informative, and more engaging command line interfaces.

There are three functions intended to be user-facing:

  1. header - print provided message with all other space as the provided justify_char. Serves as easy way to communicate seperate sections within logs.

  2. alert - simple print statement that maps numeric arg (-1, 0, 1) to bad, neutral, good. Serves as easy way to communicate sentiment of message.

  3. report - most complicated print statement. proceeds all messages with bylines, and if provided will run all provided functions at print time. intended to serve as a sort of heads-up-display for the command line. See example below.

Simple comparison and examples:

>>>print('This is how the builtin print function works')
This is how the builtin print function works

Simplest compelling usecase for display_session:

>>>from display_session import DisplaySession
>>>display = DisplaySession('This is a byline')
>>>display.report('The byline proceeds any text input here')

# hard to show with markdown, but byline is also separately ANSI colored.
This is a byline  : The byline proceeds any text input here

More complicated examples:

>>>import datetime as dt
>>>import psutil

>>>from display_session import DisplaySession
>>>user = 'John'

>>>display = DisplaySession(byline='P R O G R A M - {}'.format(user),
                            byline_action=[dt.datetime.now, psutil.cpu_percent]
                            )
>>>display.report('User successfully logged in')
 P R O G R A M - John  // 2018-09-19 21:55:29.115387 // 9.1: User successfully logged in.
>>>display.report('User successfully logged out')
 P R O G R A M - John  // 2018-09-19 21:56:14.560489 // 7.8: User successfully logged out.

Other capabilities:

>>># lets signify to our users that we are entering a new section
>>>display.header('BEGINNING LEVEL 2', align='right')
______________________________________________________________________ BEGINNING LEVEL 2

>>># lets communicate by leveraging ANSI colors - our second arg maps to them in the method.
>>>display.alert('This message is good, so it should have a green color', 1)
This message is good, so it should have a green color
>>>
>>>display.alert('This message is bad, so it should have a red color', -1)
This message is bad, so it should have a red color

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

display_session-2.0.1.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

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

display_session-2.0.1-py2.py3-none-any.whl (4.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file display_session-2.0.1.tar.gz.

File metadata

  • Download URL: display_session-2.0.1.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for display_session-2.0.1.tar.gz
Algorithm Hash digest
SHA256 568f63efcdc475eaa60ae571cffaf47335814695fdb7ca0eb21ae39510603ad6
MD5 a3e3db6ec28e3e11d599e67da5db7fbe
BLAKE2b-256 eba475a7d926a9cf6f7693e0fa00085962255d23798f84bbd63d1630580b2849

See more details on using hashes here.

File details

Details for the file display_session-2.0.1-py2.py3-none-any.whl.

File metadata

  • Download URL: display_session-2.0.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for display_session-2.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cff16b005d2354c469cab9672a0237e965a00a781df089bda80b4fb38e99fe12
MD5 ceb8d07321f6cbff2f5dc627af6f70c9
BLAKE2b-256 f10fed7527e7468d8f20e7be1007fb9dad31771c7eefcf0de51fa538157733e2

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