File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -101,14 +101,18 @@ def _fragment(tpl: str, msg: Message) -> str:
101
101
"""
102
102
PLACEHOLDER = "..."
103
103
MAX_LENGTH = 79
104
- width = MAX_LENGTH - len (tpl .format (msg = "" ))
105
- content = msg .content
106
- res = shorten (content , width = width , placeholder = PLACEHOLDER )
107
- if res == PLACEHOLDER :
108
- # This isn't a very useful representation.
109
- # Go over slightly, even if the result is a bit more awkward.
110
- res = content [:width ] + "..."
111
- return tpl .format (msg = repr (res ))
104
+ MIN_LENGTH = 5
105
+ # length of the template once the fragment is stripped out
106
+ head_length = len (tpl .replace ("{msg}" , "" ))
107
+ # 2 extra chars because repr() will add surrounding quotes
108
+ avail = max (MIN_LENGTH , MAX_LENGTH - head_length - 2 )
109
+
110
+ short = shorten (msg .content , avail , placeholder = PLACEHOLDER )
111
+
112
+ if short == PLACEHOLDER :
113
+ short = msg .content [:avail ] + PLACEHOLDER
114
+
115
+ return tpl .format (msg = repr (short ))
112
116
113
117
@staticmethod
114
118
def _user_range_to_python_range (
You can’t perform that action at this time.
0 commit comments