Skip to content

Commit f7d6f57

Browse files
committed
fix --fit for Windows
1 parent 830aedf commit f7d6f57

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

tools/nimgrep.nim

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ type
155155
checkNoMatch: Pat
156156
SinglePattern[PAT] = tuple # compile single pattern for replacef
157157
pattern: PAT
158+
Column = tuple # current column info for the cropping (--limit) feature
159+
terminal: int
160+
file: int
161+
overflowMatches: int
158162

159163
var
160164
paths: seq[string] = @[]
@@ -328,17 +332,13 @@ proc blockHeader(filename: string, line: int|string, replMode=false) =
328332
printBlockLineN($line.`$`.align(alignment) & ":")
329333
stdout.write("\n")
330334

331-
type Column = tuple # current column info for the cropping (--limit) feature
332-
terminal: int
333-
file: int
334-
overflowMatches: int
335-
336335
proc newLn(curCol: var Column) =
337336
stdout.write("\n")
338337
curCol.file = 0
339338
curcol.terminal = 0
340339

341-
proc lineHeader(filename: string, line: int|string, isMatch: bool, curCol: var Column) =
340+
proc lineHeader(filename: string, line: int|string, isMatch: bool,
341+
curCol: var Column) =
342342
let lineSym =
343343
if isMatch: $line & ":"
344344
else: $line & " "
@@ -457,7 +457,8 @@ proc getSubLinesBefore(buf: string, curMi: MatchInfo): string =
457457
result = substr(buf, first, curMi.first-1)
458458

459459
proc printSubLinesBefore(filename: string, beforeMatch: string, lineBeg: int,
460-
curCol: var Column, reserveChars: int, replMode=false) =
460+
curCol: var Column, reserveChars: int,
461+
replMode=false) =
461462
# start block: print 'linesBefore' lines before current match `curMi`
462463
let sLines = splitLines(beforeMatch)
463464
let startLine = lineBeg - sLines.len + 1
@@ -1168,6 +1169,8 @@ for kind, key, val in getopt():
11681169
of "fit":
11691170
incl(options, optFit)
11701171
limitChar = terminalWidth()
1172+
when defined(windows): # Windows cmd&powershell add an empty line when
1173+
limitChar -= 1 # printing '\n' right after the last column
11711174
of "onlyascii", "only-ascii", "o": optOnlyAscii = true
11721175
of "verbose": incl(options, optVerbose)
11731176
of "filenames": incl(options, optFilenames)

0 commit comments

Comments
 (0)