Change when a newline is printed; so that we don't print extraneous newlinesraneous newlines
This commit is contained in:
16
cmd/main.go
16
cmd/main.go
@@ -204,10 +204,12 @@ func main() {
|
|||||||
color.New(color.FgRed).Fprintf(out, "%c", c)
|
color.New(color.FgRed).Fprintf(out, "%c", c)
|
||||||
// Newline after every match - only if -o is enabled and -v is disabled.
|
// Newline after every match - only if -o is enabled and -v is disabled.
|
||||||
if *onlyFlag && !(*invertFlag) {
|
if *onlyFlag && !(*invertFlag) {
|
||||||
for _, idx := range matchIndices {
|
for matchIdxNum, idx := range matchIndices {
|
||||||
if i+1 == idx[0].EndIdx { // End index is one more than last index of match
|
if matchIdxNum < len(matchIndices)-1 { // Only print a newline afte printing a match, if there are multiple matches on the line, and we aren't on the last one. This is because the newline that gets added at the end will take care of that.
|
||||||
fmt.Fprintf(out, "\n")
|
if i+1 == idx[0].EndIdx { // End index is one more than last index of match
|
||||||
break
|
fmt.Fprintf(out, "\n")
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -222,6 +224,10 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
fmt.Println()
|
// If the last character in the string wasn't a newline, AND we either have don't -o set or we do (and we've matched something), then print a newline
|
||||||
|
if (len(test_str_runes) > 0 && test_str_runes[len(test_str_runes)-1] != '\n') &&
|
||||||
|
(!*onlyFlag || indicesToPrint.len() > 0) {
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user