Skip to content

Commit

Permalink
fix: truncate output text (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
benlubas committed Nov 30, 2023
1 parent 523d0ec commit 3141b93
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ variable, their values, and a brief description.
| `g:molten_output_win_style` | (`false`) \| `"minimal"` | Value passed to the `style` option in `:h nvim_open_win()` |
| `g:molten_save_path` | (`stdpath("data").."/molten"`) \| any path to a folder | Where to save/load data with `:MoltenSave` and `:MoltenLoad` |
| `g:molten_use_border_highlights` | `true` \| (`false`) | When true, uses different highlights for output border depending on the state of the cell (running, done, error). see [highlights](#highlights) |
| `g:molten_limit_output_chars` | (`1000000`) \| int | Limit on the number of chars in an output. If you're lagging your editor with too much output text, decrease it |
| `g:molten_virt_lines_off_by_1` | `true` \| (`false`) | Allows the output window to cover exactly one line of the regular buffer when `output_virt_lines` is true, also effects `virt_text_output`. (useful for running code in a markdown file where that covered line will just be \`\`\`) |
| `g:molten_virt_text_output` | `true` \| (`false`) | When true, show output as virtual text below the cell. When true, output window doesn't open automatically on run. Effected by `virt_lines_off_by_1` |
| `g:molten_virt_text_max_lines` | (`12`) \| int | Max height of the virtual text |
Expand Down
2 changes: 2 additions & 0 deletions rplugin/python3/molten/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class MoltenOptions:
copy_output: bool
enter_output_behavior: str
image_provider: str
limit_output_chars: int
output_crop_border: bool
output_show_more: bool
output_virt_lines: bool
Expand Down Expand Up @@ -68,6 +69,7 @@ def __init__(self, nvim: Nvim):
("molten_output_virt_lines", False),
("molten_output_win_border", [ "", "━", "", "" ]),
("molten_output_win_cover_gutter", True),
("molten_limit_output_chars", 1000000),
("molten_output_win_hide_on_leave", True),
("molten_output_win_max_height", 999999),
("molten_output_win_max_width", 999999),
Expand Down
5 changes: 5 additions & 0 deletions rplugin/python3/molten/outputbuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ def build_output_text(self, shape, buf: int, virtual: bool) -> Tuple[List[str],
lineno += chunktext.count("\n")
virtual_lines += virt_lines

limit = self.options.limit_output_chars
if limit and len(lines_str) > limit:
lines_str = lines_str[:limit]
lines_str += f"\n...truncated to {limit} chars\n"

lines = handle_progress_bars(lines_str)
lineno = len(lines) + virtual_lines
else:
Expand Down

0 comments on commit 3141b93

Please sign in to comment.