@@ -43,6 +43,9 @@ def isSimple(self):
4343class LineMatch (object ):
4444
4545 ARROW_DECORATOR = '|===>'
46+ # this is inserted between long files, so it looks like
47+ # ./src/foo/bar/something|...|baz/foo.py
48+ TRUNCATE_DECORATOR = '|...|'
4649
4750 def __init__ (self , formattedLine , result , index , validateFileExists = False ):
4851 self .controller = None
@@ -79,6 +82,7 @@ def __init__(self, formattedLine, result, index, validateFileExists=False):
7982
8083 self .selected = False
8184 self .hovered = False
85+ self .isTruncated = False
8286
8387 # precalculate the pre, post, and match strings
8488 (self .beforeText , unused ) = self .formattedLine .breakat (self .start )
@@ -145,7 +149,7 @@ def __str__(self):
145149 + '||' + self .getAfter () + '||' +
146150 str (self .num ))
147151
148- def updateDecoratedMatch (self ):
152+ def updateDecoratedMatch (self , maxLen = None ):
149153 '''Update the cached decorated match formatted string, and
150154 dirty the line, if needed'''
151155 if self .hovered and self .selected :
@@ -164,9 +168,19 @@ def updateDecoratedMatch(self):
164168 if self .controller :
165169 self .controller .dirtyLine (self .index )
166170
171+ plainText = decoratorText + self .getMatch ()
172+ if maxLen and len (plainText ) > maxLen :
173+ # alright, we need to chop the ends off of our
174+ # decorated match and glue them together with our
175+ # truncation decorator
176+ spaceAllowed = maxLen - len (self .TRUNCATE_DECORATOR )
177+ beginMatch = plainText [0 :(spaceAllowed / 2 )]
178+ endMatch = plainText [- (spaceAllowed / 2 ):]
179+ plainText = beginMatch + self .TRUNCATE_DECORATOR + endMatch
180+
167181 self .decoratedMatch = FormattedText (
168182 FormattedText .getSequenceForAttributes (* attributes ) +
169- decoratorText + self . getMatch () )
183+ plainText )
170184
171185 def getDecorator (self ):
172186 if self .selected :
@@ -191,6 +205,30 @@ def output(self, printer):
191205 if (y < miny or y >= maxy ):
192206 # wont be displayed!
193207 return
208+
209+ # we dont care about the after text, but we should be able to see
210+ # all of the decorated match (which means we need to see up to
211+ # the end of the decoratedMatch, aka include beforeText)
212+ importantTextLength = len (str (self .beforeText )) + \
213+ len (str (self .decoratedMatch ))
214+ spaceForPrinting = maxx - minx
215+ if importantTextLength > spaceForPrinting :
216+ # hrm, we need to update our decorated match to show
217+ # a truncated version since right now we will print off
218+ # the screen. lets also dump the beforeText for more
219+ # space
220+ self .updateDecoratedMatch (maxLen = spaceForPrinting )
221+ self .isTruncated = True
222+ else :
223+ # first check what our expanded size would be:
224+ expandedSize = len (str (self .beforeText )) + \
225+ len (self .getMatch ())
226+ if expandedSize < spaceForPrinting and self .isTruncated :
227+ # if the screen gets resized, we might be truncated
228+ # from a previous render but **now** we have room.
229+ # in that case lets expand back out
230+ self .updateDecoratedMatch ()
231+ self .isTruncated = False
194232
195233 maxLen = maxx - minx
196234 soFar = (minx , maxLen )
0 commit comments