12345678910111213141516171819202122232425262728293031323334353637 |
- import contextlib
- import sys
- import os
- import platform
- def term():
- """Get the Terminal reference to make output pretty
- Returns:
- (blessings.Terminal): Returns
- a `blessings <https://blessings.readthedocs.io/en/latest>`_ terminal
- instance. If running in windows and not cygwin it will return an
- `intercessions <https://pypi.org/project/intercessions>`_ terminal
- instance instead
- """
- if not hasattr(term, '_handle'):
- if sys.platform != "cygwin" and platform.system() == 'Windows':
- from intercessions import Terminal
- else:
- from blessings import Terminal
- term._handle = Terminal()
- return term._handle
- @contextlib.contextmanager
- def pushd(newDir):
- previousDir = os.getcwd()
- os.chdir(newDir)
- try:
- yield
- finally:
- os.chdir(previousDir)
|