Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disableColoring and enableColoring methods added to IceCreamDebugger closes#155 #157

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: CI

on:
push:
branches:
- master
# branches:
# - master
pull_request:
branches:
- master
Expand All @@ -14,8 +14,6 @@ jobs:
strategy:
matrix:
include:
- python-version: 2.7
toxenv: py27
- python-version: 3.5
toxenv: py35
- python-version: 3.6
Expand All @@ -26,8 +24,6 @@ jobs:
toxenv: py38
- python-version: 3.9
toxenv: py39
- python-version: pypy-2.7
toxenv: pypy
- python-version: pypy-3.7
toxenv: pypy3

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ build/
*.pyo
*.egg
*.egg-info
.vscode
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ ic| 3: 3
`ic()` continues to return its arguments when disabled, of course; no existing
code with `ic()` breaks.

Finally, by default `ic()` will produce an output with coloring. Colored output can be disabled and enabled.

```
ic.disableColoring()

ic.enableColoring()

```


### Import Tricks

Expand Down
14 changes: 14 additions & 0 deletions icecream/icecream.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,20 @@ def configureOutput(self, prefix=_absent, outputFunction=_absent,

if contextAbsPath is not _absent:
self.contextAbsPath = contextAbsPath

def disableColoring(self):
"""Disable color output by rerouting outputFunction to sys.stderr"""

self.color_outputFunction = self.outputFunction
self.outputFunction = stderrPrint

def enableColoring(self):
"""Renable color output by restoring original output function"""

# Check if color_outputFunction has been set already.
# If not then coloring hasn't been disabled so do nothing
if hasattr(self, "color_outputFunction"):
self.outputFunction = self.color_outputFunction


ic = IceCreamDebugger()
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27, py35, py36, py37, py38, py39, pypy, pypy3
envlist = py35, py36, py37, py38, py39, pypy, pypy3

[testenv]
deps =
Expand Down