Skip to content

Commit 6537ca0

Browse files
committed
Added theme color name overrides for diff colors.
Not all themes may define the colors 'green', 'red', and 'yellow'.
1 parent 05f6af8 commit 6537ca0

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# File Diff
2+
---
23

34
Two-way file comparison for Textadept.
45

@@ -73,6 +74,27 @@ The marker for line deletions.
7374

7475
The marker for line modifications.
7576

77+
<a id="file_diff.addition_color_name"></a>
78+
### `file_diff.addition_color_name`
79+
80+
The name of the theme color used to mark additions.
81+
The default value is 'green'. If your theme does not define that color, set this field to
82+
your theme's equivalent.
83+
84+
<a id="file_diff.deletion_color_name"></a>
85+
### `file_diff.deletion_color_name`
86+
87+
The name of the theme color used to mark deletions.
88+
The default value is 'red'. If your theme does not define that color, set this field to your
89+
theme's equivalent.
90+
91+
<a id="file_diff.modification_color_name"></a>
92+
### `file_diff.modification_color_name`
93+
94+
The name of the theme color used to mark modifications.
95+
The default value is 'yellow'. If your theme does not define that color, set this field to
96+
your theme's equivalent.
97+
7698

7799
## Functions defined by `file_diff`
78100

init.lua

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ local MARK_DELETION = M.MARK_DELETION
6363
local MARK_MODIFICATION = M.MARK_MODIFICATION
6464
local INDIC_ADDITION = M.INDIC_ADDITION
6565
local INDIC_DELETION = M.INDIC_DELETION
66+
--- The name of the theme color used to mark additions.
67+
-- The default value is 'green'. If your theme does not define that color, set this field to
68+
-- your theme's equivalent.
69+
M.addition_color_name = 'green'
70+
--- The name of the theme color used to mark deletions.
71+
-- The default value is 'red'. If your theme does not define that color, set this field to your
72+
-- theme's equivalent.
73+
M.deletion_color_name = 'red'
74+
--- The name of the theme color used to mark modifications.
75+
-- The default value is 'yellow'. If your theme does not define that color, set this field to
76+
-- your theme's equivalent.
77+
M.modification_color_name = 'yellow'
6678

6779
-- Localizations.
6880
local _L = _L
@@ -490,19 +502,22 @@ end)
490502

491503
events.connect(events.VIEW_NEW, function()
492504
local markers = {
493-
[MARK_ADDITION] = 'green', [MARK_DELETION] = 'red', [MARK_MODIFICATION] = 'yellow'
505+
[MARK_ADDITION] = M.addition_color_name, [MARK_DELETION] = M.deletion_color_name,
506+
[MARK_MODIFICATION] = M.modification_color_name
494507
}
495508
for mark, color in pairs(markers) do
496509
view:marker_define(mark, not CURSES and view.MARK_BACKGROUND or view.MARK_FULLRECT)
497-
view.marker_back[mark] = view.colors[color]
510+
if view.colors[color] then view.marker_back[mark] = view.colors[color] end
498511
if not CURSES then
499512
view.marker_layer[mark], view.marker_alpha[mark] = view.LAYER_UNDER_TEXT, 0x60
500513
end
501514
end
502-
local indicators = {[INDIC_ADDITION] = 'green', [INDIC_DELETION] = 'red'}
515+
local indicators = {
516+
[INDIC_ADDITION] = M.addition_color_name, [INDIC_DELETION] = M.deletion_color_name
517+
}
503518
for indic, color in pairs(indicators) do
504519
view.indic_style[indic] = not CURSES and view.INDIC_FULLBOX or view.INDIC_STRAIGHTBOX
505-
view.indic_fore[indic] = view.colors[color]
520+
if view.colors[color] then view.indic_fore[indic] = view.colors[color] end
506521
if not CURSES then view.indic_alpha[indic], view.indic_under[indic] = 0x60, true end
507522
end
508523
end)

0 commit comments

Comments
 (0)