Skip to content

Commit

Permalink
feat(conflicter): improve diff output
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Oct 27, 2023
1 parent cb49c0f commit aedf3a6
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions workspaces/conflicter/src/conflicter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,26 +142,30 @@ export class Conflicter {
return [colored];
};

const prepareChange = (changes: string, prefix: string) =>
changes
.split('\n')
.map((line, index, array) => (array.length - 1 === index ? line : `${prefix}${line}`))
.join('\n');

const messages: ColoredMessage[][] = file.conflicterChanges
?.map((change: Change): ColoredMessage => {
if (change.added) {
return { color: 'added', message: change.value };
return { color: 'added', message: prepareChange(change.value, '+') };
}

if (change.removed) {
return { color: 'removed', message: change.value };
return { color: 'removed', message: prepareChange(change.value, '-') };
}

return { message: change.value };
return { message: prepareChange(change.value, ' ') };
})
.map((colored: ColoredMessage): ColoredMessage[] => colorLines(colored));

if (file.fileModeChanges) {
destAdapter.log.colored([
{ message: '\npermission change ' },
{ message: `${file.fileModeChanges[0]}`, color: 'removed' },
{ message: '' },
{ message: `${file.fileModeChanges[1]}`, color: 'added' },
{ message: `\nold mode ${file.fileModeChanges[0]}`, color: 'removed' },
{ message: `\nnew mode ${file.fileModeChanges[1]}`, color: 'added' },
{ message: '\n' },
]);
}
Expand Down

0 comments on commit aedf3a6

Please sign in to comment.