-
Notifications
You must be signed in to change notification settings - Fork 804
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #813 from jcb91/limit_output
[limit_output] updates including allowing per-cell override of limit
- Loading branch information
Showing
2 changed files
with
83 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 19 additions & 10 deletions
29
src/jupyter_contrib_nbextensions/nbextensions/limit_output/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,39 @@ | ||
Limit Output | ||
============ | ||
|
||
|
||
Description | ||
----------- | ||
This extension limits the number of characters a codecell will output as text or HTML. | ||
This also allows to interrupt endless loops of print commands. | ||
|
||
This extension limits the number of characters a codecell will output as text | ||
or HTML. | ||
This also allows the interruption of endless loops of print commands. | ||
|
||
[![Demo Video](http://img.youtube.com/vi/U26ujuPXf00/0.jpg)](https://youtu.be/U26ujuPXf00) | ||
|
||
You can set the number of characters using the ConfigManager: | ||
|
||
```Python | ||
```python | ||
from notebook.services.config import ConfigManager | ||
cm = ConfigManager().update('notebook', {'limit_output': 1000}) | ||
``` | ||
|
||
or by using the [jupyter_nbextensions_configurator](https://github.com/Jupyter-contrib/jupyter_nbextensions_configurator) | ||
|
||
The limit can also be set for an individual cell, using the cell's | ||
`cell.metadata.limit_output`. | ||
|
||
|
||
Internals | ||
--------- | ||
|
||
Three types of messages are intercepted: `stream`, `execute_result`, `display_data` | ||
|
||
For `stream`- type messages, the text string length is limited to `limit_output` number of characters | ||
For other message types, `text/plain` and `text/html` content length is counted` and if either | ||
exceeds `limit_output` charaters, will be truncated. | ||
Three types of messages are intercepted: `stream`, `execute_result`, and | ||
`display_data`. For `stream`-type messages, the text string length is limited | ||
to `limit_output` number of characters. | ||
For other message types, `text/plain` and `text/html` content length is | ||
counted, and if either exceeds `limit_output` characters will be truncated to | ||
`limit_output` number of characters. | ||
|
||
The `limit_output_message` can be formatted to display the `limit_output` length and the current `output_length`, | ||
respectively using the replacement fields `{limit_output_length}` and `{output_length}`. | ||
The `limit_output_message` parameter can be formatted to display the | ||
`limit_output` length and the current `output_length`, using the respective | ||
replacement fields `{limit_output_length}` and `{output_length}`. |