Skip to content

hard wrap long interdiff lines - #20

Open
bc1cindy wants to merge 1 commit into
mainfrom
wrap-diffs
Open

bc1cindy wants to merge 1 commit into
mainfrom
wrap-diffs

Conversation

@bc1cindy

@bc1cindy bc1cindy commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

closes #17. interdiff lines over wrap-width (120 by default, at least 4) are split after the last space that fits. each piece repeats the line's diff markers and indentation, so -+ stays -+ and a commit message continuation keeps its indent.

before:

--Each peer forwards a message to a few random neighbours, which in turn forward it to theirs, until every peer has seen it.
-+Each peer forwards a message to a few random neighbors, which in turn forward it to theirs, until every peer has seen it once.

after:

--Each peer forwards a message to a few random neighbours, which in turn forward it to theirs, until every peer has 
--seen it.
-+Each peer forwards a message to a few random neighbors, which in turn forward it to theirs, until every peer has seen 
-+it once.

@bc1cindy
bc1cindy requested a review from nothingmuch November 14, 2026 21:51
Comment thread render.py Resolved
Comment thread render.py Resolved
@github-actions

Copy link
Copy Markdown
range-diff for force push 40c04832ce → b6bb2d3903 November 14, 2026 23:13 UTC: 1 modified; 1 commit; same base b8681c9d0f

reproduce: git range-diff b8681c9..40c0483 b8681c9..b6bb2d3

1:  40c04832ce  +76 -5 5f ! 1:  b6bb2d3903 +101 -5 5f Hard wrap long interdiff lines
1: 40c04832ce ! 1: b6bb2d3903 Hard wrap long interdiff lines
@@ action.yml: inputs:
      description: "Interdiffs are truncated to keep the comment under this 
      size; GitHub's limit is 65536."
      default: "65000"
 +  wrap-width:
-+    description: "Interdiff lines longer than this are hard wrapped, 
-+    repeating their diff markers; empty never wraps."
++    description: "Interdiff lines longer than this are hard wrapped, 
++    repeating their diff markers; at least 4, or empty to never wrap."
 +    default: "80"
    hide-after-days:
      description: "On a force push, hide as outdated the earlier range-diff 
      comments that are at least this many days old; empty keeps them all."
@@ render.py: HEADER = re.compile(
      r"(?: (?P<subject>.*))?$"
  )
  BODY_INDENT = "    "
-+# Each body line starts with two diff markers: one for the change between the
-+# two versions of the commit, one for the patch itself.
-+MARKERS = 2
++# A body line starts with up to two diff markers (none on a range-diff hunk
++# header, one on a commit message line) and then its indentation.
++HANG = re.compile(r"[ +-]{0,2}[ \t]*")
++# Half of this width holds both diff markers, and the other half holds text.
++MIN_WRAP_WIDTH = 4
  SHORT_SHA = 10
  OP_LABEL = {"!": "modified", "=": "unchanged", "<": "dropped", ">": "added"}
  
@@ render.py: def main(argv: list[str]) -> int:
      )
 +    ap.add_argument(
 +        "--wrap-width",
-+        type=int,
-+        help="hard wrap interdiff lines longer than this; omit to never wrap",
++        type=wrap_width,
++        help=f"hard wrap interdiff lines longer than this, at least 
++        {MIN_WRAP_WIDTH}; omit to never wrap",
 +    )
      ap.add_argument(
          "--pushed-at", required=True, help="when the push happened, ISO 8601 
          UTC"
@@ render.py: def stat_column(pairs: list[Pair], stats: dict[str, Stat]) -> 
Callabl
 +def wrap(line: str, width: int | None) -> list[str]:
 +    """Split a body line, for reading, into pieces at most `width` long.
 +
-+    Each piece repeats the line's diff markers and ends after the last space
-+    that fits.  A word that does not fit is cut at the width.
++    Each piece repeats the line's diff markers and indentation, at most half
++    the width of it, and ends after the last space that fits.  A word that
++    does not fit is cut at the width.  `width` is at least `MIN_WRAP_WIDTH`.
 +    """
 +    if width is None or len(line) <= width:
 +        return [line]
-+    markers, text = line[:MARKERS], line[MARKERS:]
-+    room = max(width - len(markers), 1)
++    markers = hang(line, width)
++    text = line[len(markers) :]
++    room = width - len(markers)
 +    pieces = []
 +    while len(text) > room:
 +        space = text.rfind(" ", 0, room)
@@ render.py: def stat_column(pairs: list[Pair], stats: dict[str, Stat]) -> 
Callabl
 +        text = text[cut:]
 +    return pieces + [markers + text]
 +
++
++def wrap_width(arg: str) -> int:
++    width = int(arg)
++    if width < MIN_WRAP_WIDTH:
++        raise argparse.ArgumentTypeError(f"must be at least {MIN_WRAP_WIDTH}")
++    return width
++
++
++def hang(line: str, width: int) -> str:
++    return HANG.match(line)[0][: width // 2]
++
 +
  def describe_series(pairs: list[Pair]) -> str:
      old = sum(p.lnum != "-" for p in pairs)
@@ tests/test_action.py: esac
 
  ## tests/test_render.py ##
 @@
++import argparse
 +import itertools
  import pathlib
  import sys
@@ tests/test_render.py: class RenderTest(unittest.TestCase):
 +        self.assertEqual(render.wrap(" -abcd", 6), [" -abcd"])
 +        self.assertEqual(render.wrap("++ab cdef", 6), ["++ab ", "++cdef"])
 +        self.assertEqual(render.wrap("++ab cdefgh", 6), ["++ab ", "++cdef", 
 +        "++gh"])
-+        self.assertEqual(render.wrap("++  abcdef", 6), ["++  ab", "++cdef"])
++        self.assertEqual(render.wrap("++  abcdef", 8), ["++  abcd", "++  ef"])
++        self.assertEqual(render.wrap("-  ab cd", 6), ["-  ab ", "-  cd"])
++        self.assertEqual(render.wrap("@@ ab cd", 6), ["@@ ab ", "cd"])
 +        self.assertEqual(render.wrap("++abcdefgh", None), ["++abcdefgh"])
 +
++    def test_wrap_width_leaves_room_for_markers(self):
++        self.assertEqual(render.wrap_width("4"), 4)
++        for arg in ("3", "0", "-1"):
++            with self.assertRaises(argparse.ArgumentTypeError):
++                render.wrap_width(arg)
++
 +    def test_wrapping_keeps_every_character(self):
 +        # Every line up to 7 characters over a small alphabet, at every width:
-+        # the pieces fit, start with the markers, and rejoin to the line.
++        # the pieces fit, start with the markers and indentation, and rejoin
++        # to the line.
 +        # Every piece but the last ends at a space or is cut at the width.
 +        for n in range(8):
-+            for chars in itertools.product(" +-a", repeat=n):
++            for chars in itertools.product(" +-@a", repeat=n):
 +                line = "".join(chars)
-+                for width in range(3, 9):
++                for width in range(render.MIN_WRAP_WIDTH, 9):
 +                    pieces = render.wrap(line, width)
-+                    markers = line[: render.MARKERS]
++                    markers = render.hang(line, width)
 +                    self.assertTrue(all(len(p) <= width for p in pieces))
 +                    self.assertTrue(all(p.startswith(markers) for p in 
 +                    pieces))
 +                    rejoined = markers + "".join(p[len(markers) :] for p in 
 +                    pieces)

Comment thread render.py Resolved
@github-actions

Copy link
Copy Markdown
range-diff for force push b6bb2d3903 → 2ec8e3f0ba November 15, 2026 01:56 UTC: 1 modified; 1 commit; same base b8681c9d0f

reproduce: git range-diff b8681c9..b6bb2d3 b8681c9..2ec8e3f

1:  b6bb2d3903 +101 -5 5f ! 1:  2ec8e3f0ba +126 -1 5f Hard wrap long interdiff lines
1: b6bb2d3903 ! 1: 2ec8e3f0ba Hard wrap long interdiff lines
@@ render.py: def render(
      counts = {op: sum(1 for p in pairs if p.op == op) for op in OP_LABEL}
      tally = (
 @@ render.py: def render(
-             + (["", note] if truncated else [])
-             + ["", render_listing(pairs, repo_url, stats)]
-             + (
--                ["", render_interdiffs(pairs)]
-+                ["", render_interdiffs(pairs, wrap_width)]
-                 if any(p.op == "!" for p in pairs)
-                 else []
-             )
-@@ render.py: def stat_column(pairs: list[Pair], stats: dict[str, Stat]) -> 
-Callable[[str], st
-     return column
+         "",
+         f"<sup>reproduce: <code>git range-diff {html.escape(old_range)} 
+         {html.escape(new_range)}</code></sup>",
+     ]
++    pairs = [
++        replace(
++            p, body=tuple(part for line in p.body for part in wrap(line, 
++            wrap_width))
++        )
++        for p in pairs
++    ]
+     note = "<i>Some interdiffs were truncated to fit; the full range-diff is 
+     in the job summary.</i>"
  
- 
--def render_interdiffs(pairs: list[Pair]) -> str:
-+def render_interdiffs(pairs: list[Pair], wrap_width: int | None = None) -> 
-+str:
-     width = number_width(pairs)
-     blocks = []
-     for p in pairs:
-         if p.op != "!":
-             continue
-         head = f"{p.lnum.rjust(width)}:  {p.lsha[:SHORT_SHA]} ! 
-         {p.rnum.rjust(width)}:  {p.rsha[:SHORT_SHA]}"
--        fence = fence_for(p.body)
-+        body = tuple(part for line in p.body for part in wrap(line, 
-+        wrap_width))
-+        fence = fence_for(body)
-         blocks.append(
-             f"<details>\n<summary><code>{head}</code> 
-             {html.escape(p.subject)}</summary>\n\n"
--            f"{fence}diff\n" + "\n".join(p.body) + f"\n{fence}\n\n</details>"
-+            f"{fence}diff\n" + "\n".join(body) + f"\n{fence}\n\n</details>"
-         )
+     def assemble(pairs: list[Pair], truncated: bool) -> str:
+@@ render.py: def render_interdiffs(pairs: list[Pair]) -> str:
      return "\n\n".join(blocks)
  
  
@@ tests/test_render.py: class RenderTest(unittest.TestCase):
 +                    self.assertEqual(rejoined, line)
 +                    for p in pieces[:-1]:
 +                        self.assertTrue(p.endswith(" ") or len(p) == width)
++
++    def test_wrapped_lines_are_truncated_by_line(self):
++        # The line fits unwrapped, but its wrapped pieces do not.  Halving
++        # them keeps the fence closed, which a byte cut would not.
++        text = "1:  aaaaaaa ! 1:  bbbbbbb s\n    ++" + "x" * 63500 + "\n"
++        out = render.render(
++            render.parse(text),
++            repo_url=REPO,
++            before=BEFORE,
++            after=AFTER,
++            old_range="a..b",
++            new_range="a..c",
++            max_bytes=65000,
++            pushed_at="2026-09-17T00:10:17Z",
++            old_base="",
++            new_base="",
++            base_behind=0,
++            base_ahead=0,
++            stats={},
++            wrap_width=80,
++        )
++        self.assertLessEqual(len(out.encode()), 65000)
++        self.assertIn("Some interdiffs were truncated", out)
++        self.assertEqual(out.count("```"), 2)
 +
      def test_truncation_fits_and_is_noted(self):
          full = render_basic()

@oakagent

Copy link
Copy Markdown

ACK 2ec8e3f

oakagent · automated · 2ec8e3f · 1 commit · 0 findings

Comment thread action.yml Outdated
default: "65000"
wrap-width:
description: "Interdiff lines longer than this are hard wrapped, repeating their diff markers; at least 4, or empty to never wrap."
default: "80"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default: "80"
default: "120"

80 is very narrow

github's widest view supports a bit more than even 120, i suspect it's 130ish... not sure what it's like on 13" laptops, and mobile is not going to be great either way

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, default is 120 now

@github-actions

Copy link
Copy Markdown
range-diff for force push 2ec8e3f0ba → caa55ca8d0 November 16, 2026 12:27 UTC: 1 modified; 1 commit; same base b8681c9d0f

reproduce: git range-diff b8681c9..2ec8e3f b8681c9..caa55ca

1:  2ec8e3f0ba +126 -1 5f ! 1:  caa55ca8d0 +126 -1 5f Hard wrap long interdiff lines
1: 2ec8e3f0ba ! 1: caa55ca8d0 Hard wrap long interdiff lines
@@ Commit message
 
     Soft wrapped markdown puts a whole paragraph on one line, and GitHub
     scrolls code blocks sideways instead of wrapping them. Lines past
-    wrap-width (80 by default) are split for reading, after the last space
+    wrap-width (120 by default) are split for reading, after the last space
     that fits.
 
     Each piece repeats both diff markers of its line. Repeating only the
@@ action.yml: inputs:
      default: "65000"
 +  wrap-width:
 +    description: "Interdiff lines longer than this are hard wrapped, repeating their diff markers; at least 4, or 
 +    empty to never wrap."
-+    default: "80"
++    default: "120"
    hide-after-days:
      description: "On a force push, hide as outdated the earlier range-diff comments that are at least this many days 
      old; empty keeps them all."
      default: "3"

Comment thread render.py Resolved
@github-actions

Copy link
Copy Markdown
range-diff for force push caa55ca8d0 → 2db6eefa69 November 16, 2026 14:18 UTC: 1 modified; 1 commit; same base b8681c9d0f

reproduce: git range-diff b8681c9..caa55ca b8681c9..2db6eef

1:  caa55ca8d0 +126 -1 5f ! 1:  2db6eefa69 +131 -1 5f Hard wrap long interdiff lines
1: caa55ca8d0 ! 1: 2db6eefa69 Hard wrap long interdiff lines
@@ Commit message
     first would leave the piece's first character of text in the column of
     the patch's marker, where it reads as a marker.
 
+    Indentation past half the width is dropped, since deeper indentation
+    could fill a piece with spaces and show a blank line.
+
     Fixes #17
 
  ## action.yml ##
@@ render.py: def render_interdiffs(pairs: list[Pair]) -> str:
 +    """Split a body line, for reading, into pieces at most `width` long.
 +
 +    Each piece repeats the line's diff markers and indentation, at most half
-+    the width of it, and ends after the last space that fits.  A word that
-+    does not fit is cut at the width.  `width` is at least `MIN_WRAP_WIDTH`.
++    the width of it, and ends after the last space that fits.  Indentation
++    past half the width is dropped, so it cannot fill a piece with spaces.  A
++    word that does not fit is cut at the width.  `width` is at least
++    `MIN_WRAP_WIDTH`.
 +    """
 +    if width is None or len(line) <= width:
 +        return [line]
 +    markers = hang(line, width)
-+    text = line[len(markers) :]
++    text = line[HANG.match(line).end() :]
 +    room = width - len(markers)
 +    pieces = []
 +    while len(text) > room:
 +        space = text.rfind(" ", 0, room)
-+        # A space in the leading indentation is no place to cut: the piece
-+        # would be blank.
++        # A space at the start of the remaining text is no place to cut: the
++        # piece would be blank.
 +        cut = space + 1 if space > 0 and text[:space].strip() else room
 +        pieces.append(markers + text[:cut])
 +        text = text[cut:]
@@ tests/test_render.py: class RenderTest(unittest.TestCase):
 +        self.assertEqual(render.wrap("++  abcdef", 8), ["++  abcd", "++  ef"])
 +        self.assertEqual(render.wrap("-  ab cd", 6), ["-  ab ", "-  cd"])
 +        self.assertEqual(render.wrap("@@ ab cd", 6), ["@@ ab ", "cd"])
++        self.assertEqual(render.wrap("+    abcdef", 4), ["+ ab", "+ cd", "+ ef"])
 +        self.assertEqual(render.wrap("++abcdefgh", None), ["++abcdefgh"])
 +
 +    def test_wrap_width_leaves_room_for_markers(self):
@@ tests/test_render.py: class RenderTest(unittest.TestCase):
 +            with self.assertRaises(argparse.ArgumentTypeError):
 +                render.wrap_width(arg)
 +
-+    def test_wrapping_keeps_every_character(self):
++    def test_wrapping_keeps_the_text(self):
 +        # Every line up to 7 characters over a small alphabet, at every width:
 +        # the pieces fit, start with the markers and indentation, and rejoin
-+        # to the line.
++        # to the line, less the indentation past half the width.
 +        # Every piece but the last ends at a space or is cut at the width.
 +        for n in range(8):
 +            for chars in itertools.product(" +-@a", repeat=n):
@@ tests/test_render.py: class RenderTest(unittest.TestCase):
 +                    markers = render.hang(line, width)
 +                    self.assertTrue(all(len(p) <= width for p in pieces))
 +                    self.assertTrue(all(p.startswith(markers) for p in pieces))
-+                    rejoined = markers + "".join(p[len(markers) :] for p in pieces)
-+                    self.assertEqual(rejoined, line)
++                    if pieces == [line]:
++                        continue
++                    rest = line[render.HANG.match(line).end() :]
++                    self.assertEqual("".join(p[len(markers) :] for p in pieces), rest)
 +                    for p in pieces[:-1]:
 +                        self.assertTrue(p.endswith(" ") or len(p) == width)
 +

Comment thread render.py Resolved
Comment thread render.py Resolved
@github-actions

Copy link
Copy Markdown
range-diff for force push 2db6eefa69 → 764bc23503 November 16, 2026 15:38 UTC: 1 modified; 1 commit; same base b8681c9d0f

reproduce: git range-diff b8681c9..2db6eef b8681c9..764bc23

1:  2db6eefa69 +131 -1 5f ! 1:  764bc23503 +138 -4 5f Hard wrap long interdiff lines
1: 2db6eefa69 ! 1: 764bc23503 Hard wrap long interdiff lines
@@ action.yml: inputs:
      description: "Interdiffs are truncated to keep the comment under this size; GitHub's limit is 65536."
      default: "65000"
 +  wrap-width:
-+    description: "Interdiff lines longer than this are hard wrapped, repeating their diff markers; at least 4, or 
-+    empty to never wrap."
++    description: "Interdiff lines in the comment longer than this are hard wrapped, repeating their diff markers; at 
++    least 4, or empty to never wrap."
 +    default: "120"
    hide-after-days:
      description: "On a force push, hide as outdated the earlier range-diff comments that are at least this many days 
      old; empty keeps them all."
@@ post-range-diff-comment.sh: render() {
 +    ${WRAP_WIDTH:+--wrap-width "$WRAP_WIDTH"} <"$WORK/range-diff.txt"
  }
  render "${MAX_COMMENT_BYTES:-65000}" >"$WORK/comment.md"
- # Job summaries allow 1 MiB, so the summary usually holds the untruncated text.
+-# Job summaries allow 1 MiB, so the summary usually holds the untruncated text.
+-render 1000000 >>"$SUMMARY"
++# Job summaries allow 1 MiB, so the summary usually holds the full text.
++# Wrapping is left out there because it lengthens the text it would hold.
++WRAP_WIDTH= render 1000000 >>"$SUMMARY"
+ 
+ if [[ ${POST_COMMENT:-true} == false ]]; then
+   cat "$WORK/comment.md"
 
  ## render.py ##
 @@ render.py: HEADER = re.compile(
@@ tests/test_action.py: esac
              PATH=f"{stub}{os.pathsep}{os.environ['PATH']}",
          )
          command = (
+@@ tests/test_action.py: esac
+             self.assertIn("<b>range-diff</b>", result.stdout)
+             self.assertIn(self.before, result.stdout)
+             self.assertIn(self.after, result.stdout)
+-            self.assertTrue(result.stdout.endswith(summary.read_text()))
++            if not wrap_width:
++                self.assertTrue(result.stdout.endswith(summary.read_text()))
+         return result.stdout
+ 
+     def test_force_push_full_checkout(self):
 @@ tests/test_action.py: esac
          self.run_action(comments=[old], post_fails=True)
          self.assertFalse((self.root / "stub" / "hidden").exists())
@@ tests/test_action.py: esac
 +        self.after = self.commit("old\n" + "x" * 40 + "\n", "change", amend=True)
 +        out = self.run_action(wrap_width="20")
 +        self.assertIn("\n++" + "x" * 18 + "\n++" + "x" * 18 + "\n++xxxx\n", out)
++        summary = (self.root / "summary").read_text()
++        self.assertIn("\n++" + "x" * 40 + "\n", summary)
 +
      def test_force_push_shallow_checkout(self):
          self.run_action(shallow=True)

@github-actions

Copy link
Copy Markdown
range-diff for force push 764bc23503 → 23222d7082 November 16, 2026 15:43 UTC: 1 modified; 1 commit; same base b8681c9d0f

reproduce: git range-diff b8681c9..764bc23 b8681c9..23222d7

1:  764bc23503 +138 -4 5f ! 1:  23222d7082 +138 -4 5f Hard wrap long interdiff lines
1: 764bc23503 ! 1: 23222d7082 Hard wrap long interdiff lines
@@ post-range-diff-comment.sh: render() {
 -render 1000000 >>"$SUMMARY"
 +# Job summaries allow 1 MiB, so the summary usually holds the full text.
 +# Wrapping is left out there because it lengthens the text it would hold.
-+WRAP_WIDTH= render 1000000 >>"$SUMMARY"
++WRAP_WIDTH='' render 1000000 >>"$SUMMARY"
  
  if [[ ${POST_COMMENT:-true} == false ]]; then
    cat "$WORK/comment.md"

Comment thread render.py Resolved
Soft wrapped markdown puts a whole paragraph on one line, and GitHub
scrolls code blocks sideways instead of wrapping them. Lines past
wrap-width (120 by default) are split for reading, after the last space
that fits.

Each piece repeats both diff markers of its line. Repeating only the
first would leave the piece's first character of text in the column of
the patch's marker, where it reads as a marker.

Indentation past half the width is dropped, since deeper indentation
could fill a piece with spaces and show a blank line.

Fixes #17
@github-actions

Copy link
Copy Markdown
range-diff for force push 23222d7082 → 71a3e86c0e November 16, 2026 21:19 UTC: 1 modified; 1 commit; same base b8681c9d0f

reproduce: git range-diff b8681c9..23222d7 b8681c9..71a3e86

1:  23222d7082 +138 -4 5f ! 1:  71a3e86c0e +146 -4 5f Hard wrap long interdiff lines
1: 23222d7082 ! 1: 71a3e86c0e Hard wrap long interdiff lines
@@ render.py: def render_interdiffs(pairs: list[Pair]) -> str:
 +def wrap(line: str, width: int | None) -> list[str]:
 +    """Split a body line, for reading, into pieces at most `width` long.
 +
-+    Each piece repeats the line's diff markers and indentation, at most half
-+    the width of it, and ends after the last space that fits.  Indentation
-+    past half the width is dropped, so it cannot fill a piece with spaces.  A
-+    word that does not fit is cut at the width.  `width` is at least
++    Each piece starts with the line's diff markers and indentation, cut to half
++    of `width` so they cannot fill a piece with spaces.  A piece ends after the
++    last space that fits, and a word longer than the rest of the piece is cut at
++    the width.  `width` is None to keep the line whole, or at least
 +    `MIN_WRAP_WIDTH`.
 +    """
 +    if width is None or len(line) <= width:
@@ render.py: def render_interdiffs(pairs: list[Pair]) -> str:
 +    pieces = []
 +    while len(text) > room:
 +        space = text.rfind(" ", 0, room)
-+        # A space at the start of the remaining text is no place to cut: the
-+        # piece would be blank.
-+        cut = space + 1 if space > 0 and text[:space].strip() else room
++        cut = space + 1 if space >= 0 else room
 +        pieces.append(markers + text[:cut])
 +        text = text[cut:]
 +    return pieces + [markers + text]
@@ tests/test_render.py: class RenderTest(unittest.TestCase):
 +        self.assertEqual(render.wrap("-  ab cd", 6), ["-  ab ", "-  cd"])
 +        self.assertEqual(render.wrap("@@ ab cd", 6), ["@@ ab ", "cd"])
 +        self.assertEqual(render.wrap("+    abcdef", 4), ["+ ab", "+ cd", "+ ef"])
++        self.assertEqual(
++            render.wrap("++a" + " " * 10 + "abc", 6),
++            ["++a   ", "++    ", "++   ", "++abc"],
++        )
 +        self.assertEqual(render.wrap("++abcdefgh", None), ["++abcdefgh"])
 +
 +    def test_wrap_width_leaves_room_for_markers(self):
@@ tests/test_render.py: class RenderTest(unittest.TestCase):
 +        # Every line up to 7 characters over a small alphabet, at every width:
 +        # the pieces fit, start with the markers and indentation, and rejoin
 +        # to the line, less the indentation past half the width.
-+        # Every piece but the last ends at a space or is cut at the width.
++        # Every piece but the last ends at a space or is cut at the width, and
++        # a cut at the width splits only a word longer than a piece holds.
 +        for n in range(8):
 +            for chars in itertools.product(" +-@a", repeat=n):
 +                line = "".join(chars)
@@ tests/test_render.py: class RenderTest(unittest.TestCase):
 +                    self.assertEqual("".join(p[len(markers) :] for p in pieces), rest)
 +                    for p in pieces[:-1]:
 +                        self.assertTrue(p.endswith(" ") or len(p) == width)
++                    texts = [p[len(markers) :] for p in pieces]
++                    for a, b in itertools.pairwise(texts):
++                        if not a.endswith(" ") and not b.startswith(" "):
++                            word = a.rsplit(" ", 1)[-1] + b.split(" ", 1)[0]
++                            self.assertGreater(len(word), width - len(markers))
 +
 +    def test_wrapped_lines_are_truncated_by_line(self):
 +        # The line fits unwrapped, but its wrapped pieces do not.  Halving

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

improve soft wrapped text display

3 participants