2021-04-18 18:07:10 +10:00
|
|
|
package mergeconflicts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
|
2021-07-27 15:00:37 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
2021-04-18 18:07:10 +10:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
|
|
|
)
|
|
|
|
|
2024-01-14 00:18:05 +11:00
|
|
|
func ColoredConflictFile(state *State) string {
|
2022-01-26 01:20:19 +11:00
|
|
|
content := state.GetContent()
|
2021-04-18 18:07:10 +10:00
|
|
|
if len(state.conflicts) == 0 {
|
|
|
|
return content
|
|
|
|
}
|
|
|
|
conflict, remainingConflicts := shiftConflict(state.conflicts)
|
|
|
|
var outputBuffer bytes.Buffer
|
|
|
|
for i, line := range utils.SplitLines(content) {
|
2021-07-31 12:54:28 +10:00
|
|
|
textStyle := theme.DefaultTextColor
|
2021-08-25 20:43:57 +10:00
|
|
|
if conflict.isMarkerLine(i) {
|
2021-07-31 12:54:28 +10:00
|
|
|
textStyle = style.FgRed
|
2021-04-18 18:07:10 +10:00
|
|
|
}
|
2021-07-27 15:00:37 +02:00
|
|
|
|
2021-04-18 18:07:10 +10:00
|
|
|
if i == conflict.end && len(remainingConflicts) > 0 {
|
|
|
|
conflict, remainingConflicts = shiftConflict(remainingConflicts)
|
|
|
|
}
|
2021-07-31 12:54:28 +10:00
|
|
|
outputBuffer.WriteString(textStyle.Sprint(line) + "\n")
|
2021-04-18 18:07:10 +10:00
|
|
|
}
|
|
|
|
return outputBuffer.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func shiftConflict(conflicts []*mergeConflict) (*mergeConflict, []*mergeConflict) {
|
|
|
|
return conflicts[0], conflicts[1:]
|
|
|
|
}
|