Skip to content

Commit 281023e

Browse files
committed
Merge pull request #135 from facebook/handleLongPaths
Awesomeeee long file truncation Resolves #118
2 parents 3b43ab2 + 99220d7 commit 281023e

4 files changed

Lines changed: 92 additions & 2 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
./hadoop-mapreduce-project/|...|eNamereallylongfileName.txt
2+
___________________________________________________________
3+
|===>./hadoop-mapreduce-pro|...|t/some/deeper/dir/source.py
4+
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
5+
6+
7+
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
____________________________________________________________
38+
39+
[f|A] selection, [down|j|up|k|space|b] navigation, [enter] o
40+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
./hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-client/hadoop-mapreduce-project/hadoop-mapreduce-client/LongFileNamereallylongfileName.txt
2+
./hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-client/hadoop-mapreduce-project/hadoop-mapreduce-client/some/deeper/dir/source.py

src/__tests__/testScreen.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@
103103
'maxY': 40
104104
},
105105
'pastScreens': [0, 1, 2, 3, 4]
106+
}, {
107+
'name': 'longFileTruncation',
108+
'input': 'superLongFileNames.txt',
109+
'withAttributes': True,
110+
'inputs': ['DOWN', 'f'],
111+
'screenConfig': {
112+
'maxX': 60,
113+
'maxY': 20
114+
},
106115
}]
107116

108117

src/format.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ def isSimple(self):
4343
class 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,20 @@ 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+
midPoint = int(spaceAllowed / 2)
178+
beginMatch = plainText[0:midPoint]
179+
endMatch = plainText[-midPoint:len(plainText)]
180+
plainText = beginMatch + self.TRUNCATE_DECORATOR + endMatch
181+
167182
self.decoratedMatch = FormattedText(
168183
FormattedText.getSequenceForAttributes(*attributes) +
169-
decoratorText + self.getMatch())
184+
plainText)
170185

171186
def getDecorator(self):
172187
if self.selected:
@@ -191,6 +206,30 @@ def output(self, printer):
191206
if (y < miny or y >= maxy):
192207
# wont be displayed!
193208
return
209+
210+
# we dont care about the after text, but we should be able to see
211+
# all of the decorated match (which means we need to see up to
212+
# the end of the decoratedMatch, aka include beforeText)
213+
importantTextLength = len(str(self.beforeText)) + \
214+
len(str(self.decoratedMatch))
215+
spaceForPrinting = maxx - minx
216+
if importantTextLength > spaceForPrinting:
217+
# hrm, we need to update our decorated match to show
218+
# a truncated version since right now we will print off
219+
# the screen. lets also dump the beforeText for more
220+
# space
221+
self.updateDecoratedMatch(maxLen=spaceForPrinting)
222+
self.isTruncated = True
223+
else:
224+
# first check what our expanded size would be:
225+
expandedSize = len(str(self.beforeText)) + \
226+
len(self.getMatch())
227+
if expandedSize < spaceForPrinting and self.isTruncated:
228+
# if the screen gets resized, we might be truncated
229+
# from a previous render but **now** we have room.
230+
# in that case lets expand back out
231+
self.updateDecoratedMatch()
232+
self.isTruncated = False
194233

195234
maxLen = maxx - minx
196235
soFar = (minx, maxLen)

0 commit comments

Comments
 (0)