From 3141b936ee69f15f3a926b122d110b0940e152e0 Mon Sep 17 00:00:00 2001 From: Ben Lubas <56943754+benlubas@users.noreply.github.com> Date: Wed, 29 Nov 2023 21:13:24 -0500 Subject: [PATCH] fix: truncate output text (#67) --- README.md | 1 + rplugin/python3/molten/options.py | 2 ++ rplugin/python3/molten/outputbuffer.py | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/README.md b/README.md index 88ec8c8..75f3267 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/rplugin/python3/molten/options.py b/rplugin/python3/molten/options.py index 52949a4..96648ad 100644 --- a/rplugin/python3/molten/options.py +++ b/rplugin/python3/molten/options.py @@ -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 @@ -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), diff --git a/rplugin/python3/molten/outputbuffer.py b/rplugin/python3/molten/outputbuffer.py index ba241e8..378dc47 100644 --- a/rplugin/python3/molten/outputbuffer.py +++ b/rplugin/python3/molten/outputbuffer.py @@ -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: