output.go (sift-0.8.0) | : | output.go (sift-0.9.0) | ||
---|---|---|---|---|
skipping to change at line 62 | skipping to change at line 62 | |||
} | } | |||
func printLineno(lineno int64, delim string) { | func printLineno(lineno int64, delim string) { | |||
if options.ShowLineNumbers { | if options.ShowLineNumbers { | |||
writeOutput(global.termHighlightLineno+"%d"+global.termHighlightR eset+delim, lineno) | writeOutput(global.termHighlightLineno+"%d"+global.termHighlightR eset+delim, lineno) | |||
} | } | |||
} | } | |||
func printColumnNo(m *Match) { | func printColumnNo(m *Match) { | |||
if options.ShowColumnNumbers { | if options.ShowColumnNumbers { | |||
writeOutput("%d:", m.start-m.lineStart+1) | writeOutput("%d"+options.FieldSeparator, m.start-m.lineStart+1) | |||
} | ||||
} | ||||
func printByteOffset(m *Match) { | ||||
if options.ShowByteOffset { | ||||
if options.OnlyMatching { | ||||
writeOutput("%d"+options.FieldSeparator, m.start) | ||||
} else { | ||||
writeOutput("%d"+options.FieldSeparator, m.lineStart) | ||||
} | ||||
} | } | |||
} | } | |||
// printMatch prints the context after the previous match, the context before th e match and the match itself | // printMatch prints the context after the previous match, the context before th e match and the match itself | |||
func printMatch(match Match, lastMatch Match, target string, lastPrintedLine *in t64) { | func printMatch(match Match, lastMatch Match, target string, lastPrintedLine *in t64) { | |||
var matchOutput = match.line | var matchOutput = match.line | |||
if !options.InvertMatch { | if !options.InvertMatch { | |||
if options.Replace != "" { | if options.Replace != "" { | |||
matchOutput = match.match | matchOutput = match.match | |||
skipping to change at line 181 | skipping to change at line 191 | |||
// print current match | // print current match | |||
if options.Multiline { | if options.Multiline { | |||
lines := strings.Split(match.line, "\n") | lines := strings.Split(match.line, "\n") | |||
if len(lines) > 1 && options.Replace == "" { | if len(lines) > 1 && options.Replace == "" { | |||
firstLine := lines[0] | firstLine := lines[0] | |||
lastLine := lines[len(lines)-1] | lastLine := lines[len(lines)-1] | |||
firstLineOffset := match.start - match.lineStart | firstLineOffset := match.start - match.lineStart | |||
lastLineOffset := int64(len(lastLine)) - (match.lineEnd - match.end) | lastLineOffset := int64(len(lastLine)) - (match.lineEnd - match.end) | |||
// first line of multiline match with partial highlightin g | // first line of multiline match with partial highlightin g | |||
printFilename(target, ":") | printFilename(target, options.FieldSeparator) | |||
printLineno(match.lineno, ":") | printLineno(match.lineno, options.FieldSeparator) | |||
printColumnNo(&match) | printColumnNo(&match) | |||
printByteOffset(&match) | ||||
writeOutput("%s%s%s%s\n", firstLine[0:firstLineOffset], g lobal.termHighlightMatch, | writeOutput("%s%s%s%s\n", firstLine[0:firstLineOffset], g lobal.termHighlightMatch, | |||
firstLine[firstLineOffset:len(firstLine)], global .termHighlightReset) | firstLine[firstLineOffset:len(firstLine)], global .termHighlightReset) | |||
// lines 2 upto n-1 of multiline match with full highligh ting | // lines 2 upto n-1 of multiline match with full highligh ting | |||
for i := 1; i < len(lines)-1; i++ { | for i := 1; i < len(lines)-1; i++ { | |||
line := lines[i] | line := lines[i] | |||
printFilename(target, ":") | printFilename(target, options.FieldSeparator) | |||
printLineno(match.lineno+int64(i), ":") | printLineno(match.lineno+int64(i), options.FieldS | |||
eparator) | ||||
writeOutput("%s%s%s\n", global.termHighlightMatch , line, global.termHighlightReset) | writeOutput("%s%s%s\n", global.termHighlightMatch , line, global.termHighlightReset) | |||
} | } | |||
// last line of multiline match with partial highlighting | // last line of multiline match with partial highlighting | |||
printFilename(target, ":") | printFilename(target, options.FieldSeparator) | |||
printLineno(match.lineno+int64(len(lines))-1, ":") | printLineno(match.lineno+int64(len(lines))-1, options.Fie | |||
ldSeparator) | ||||
writeOutput("%s%s%s%s%s", global.termHighlightMatch, last Line[0:lastLineOffset], | writeOutput("%s%s%s%s%s", global.termHighlightMatch, last Line[0:lastLineOffset], | |||
global.termHighlightReset, lastLine[lastLineOffse t:len(lastLine)], options.OutputSeparator) | global.termHighlightReset, lastLine[lastLineOffse t:len(lastLine)], options.OutputSeparator) | |||
*lastPrintedLine = match.lineno + int64(len(lines)-1) | *lastPrintedLine = match.lineno + int64(len(lines)-1) | |||
} else { | } else { | |||
// single line output in multiline mode or replace option used | // single line output in multiline mode or replace option used | |||
printFilename(target, ":") | printFilename(target, options.FieldSeparator) | |||
printLineno(match.lineno, ":") | printLineno(match.lineno, options.FieldSeparator) | |||
printColumnNo(&match) | printColumnNo(&match) | |||
printByteOffset(&match) | ||||
writeOutput("%s%s", matchOutput, options.OutputSeparator) | writeOutput("%s%s", matchOutput, options.OutputSeparator) | |||
*lastPrintedLine = match.lineno + int64(len(lines)-1) | *lastPrintedLine = match.lineno + int64(len(lines)-1) | |||
} | } | |||
} else { | } else { | |||
// single line output | // single line output | |||
printFilename(target, ":") | printFilename(target, options.FieldSeparator) | |||
printLineno(match.lineno, ":") | printLineno(match.lineno, options.FieldSeparator) | |||
printColumnNo(&match) | printColumnNo(&match) | |||
printByteOffset(&match) | ||||
writeOutput("%s%s", matchOutput, options.OutputSeparator) | writeOutput("%s%s", matchOutput, options.OutputSeparator) | |||
*lastPrintedLine = match.lineno | *lastPrintedLine = match.lineno | |||
} | } | |||
} | } | |||
// printResult prints results using printMatch and handles various output option s. | // printResult prints results using printMatch and handles various output option s. | |||
func printResult(result *Result) { | func printResult(result *Result) { | |||
var matchCount int64 | var matchCount int64 | |||
target := result.target | target := result.target | |||
matches := result.matches | matches := result.matches | |||
skipping to change at line 256 | skipping to change at line 269 | |||
for matches := range result.matchChan { | for matches := range result.matchChan { | |||
matchCount += int64(len(matches)) | matchCount += int64(len(matches)) | |||
if options.Limit != 0 && matchCount >= options.Li mit { | if options.Limit != 0 && matchCount >= options.Li mit { | |||
matchCount = options.Limit | matchCount = options.Limit | |||
break countingMatchesLoop | break countingMatchesLoop | |||
} | } | |||
} | } | |||
} | } | |||
if options.FilesWithMatches { | if options.FilesWithMatches { | |||
if matchCount > 0 { | if matchCount > 0 { | |||
writeOutput("%s:%d\n", target, matchCount) | writeOutput("%s"+options.FieldSeparator+"%d\n", t arget, matchCount) | |||
} | } | |||
} else { | } else { | |||
if options.ShowFilename == "on" { | if options.ShowFilename == "on" { | |||
writeOutput("%s:", target) | writeOutput("%s"+options.FieldSeparator, target) | |||
} | } | |||
writeOutput("%d\n", matchCount) | writeOutput("%d\n", matchCount) | |||
} | } | |||
global.totalMatchCount += matchCount | global.totalMatchCount += matchCount | |||
if matchCount > 0 { | if matchCount > 0 { | |||
global.totalResultCount++ | global.totalResultCount++ | |||
} | } | |||
return | return | |||
} | } | |||
End of changes. 11 change blocks. | ||||
13 lines changed or deleted | 28 lines changed or added |