1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
|
#[cfg(test)]
use std::ffi::OsString;
use std::path::PathBuf;
use structopt::clap::AppSettings::{ColorAlways, ColoredHelp, DeriveDisplayOrder};
use structopt::{clap, StructOpt};
use crate::git_config::GitConfig;
use crate::rewrite_options;
use crate::set_options;
#[derive(StructOpt, Clone, Debug, PartialEq)]
#[structopt(
name = "delta",
about = "A syntax-highlighter for git and diff output",
setting(ColorAlways),
setting(ColoredHelp),
setting(DeriveDisplayOrder),
after_help = "\
GIT CONFIG
----------
By default, delta takes settings from a section named \"delta\" in git config files, if one is
present. The git config file to use for delta options will usually be ~/.gitconfig, but delta
follows the rules given in https://git-scm.com/docs/git-config#FILES. Most delta options can be
given in a git config file, using the usual option names but without the initial '--'. An example
is
[delta]
number = true
zero-style = dim syntax
FEATURES
-------
A feature is a named collection of delta options in ~/.gitconfig. An example is:
[delta \"my-delta-feature\"]
syntax-theme = Dracula
plus-style = bold syntax \"#002800\"
...
To activate those options, you would use:
delta --features my-delta-feature
or in ~/.gitconfig
[delta]
features = my-delta-feature
A single feature name may not contain whitespace. You can activate multiple features:
[delta]
features = my-highlight-styles-colors-feature my-line-number-styles-feature
If more than one feature sets the same option, the last one wins.
There are two built-in features:
--features diff-highlight (https://github.com/git/git/tree/master/contrib/diff-highlight)
--features diff-so-fancy (https://github.com/so-fancy/diff-so-fancy)
STYLES
------
All options that have a name like --*-style work the same way. It is very similar to how
colors/styles are specified in a gitconfig file:
https://git-scm.com/docs/git-config#Documentation/git-config.txt-color
Here is an example:
--minus-style 'red bold ul #ffeeee'
That means: For removed lines, set the foreground (text) color to 'red', make it bold and
underlined, and set the background color to '#ffeeee'.
See the COLORS section below for how to specify a color. In addition to real colors, there are 4
special color names: 'auto', 'normal', 'raw', and 'syntax'.
Here is an example of using special color names together with a single attribute:
--minus-style 'syntax bold auto'
That means: For removed lines, syntax-highlight the text, and make it bold, and do whatever delta
normally does for the background.
The available attributes are: 'blink', 'bold', 'dim', 'hidden', 'italic', 'reverse', 'strike',
and 'ul' (or 'underline').
A complete description of the style string syntax follows:
- If the input that delta is receiving already has colors, and you want delta to output those
colors unchanged, then use the special style string 'raw'. Otherwise, delta will strip any colors
from its input.
- A style string consists of 0, 1, or 2 colors, together with an arbitrary number of style
attributes, all separated by spaces.
- The first color is the foreground (text) color. The second color is the background color.
Attributes can go in any position.
- This means that in order to specify a background color you must also specify a foreground (text)
color.
- If you want delta to choose one of the colors automatically, then use the special color 'auto'.
This can be used for both foreground and background.
- If you want the foreground/background color to be your terminal's foreground/background color,
then use the special color 'normal'.
- If you want the foreground text to be syntax-highlighted according to its language, then use the
special foreground color 'syntax'. This can only be used for the foreground (text).
- The minimal style specification is the empty string ''. This means: do not apply any colors or
styling to the element in question.
COLORS
------
There are three ways to specify a color (this section applies to foreground and background colors
within a style string):
1. RGB hex code
An example of using an RGB hex code is:
--file-style=\"#0e7c0e\"
2. ANSI color name
There are 8 ANSI color names:
black, red, green, yellow, blue, magenta, cyan, white.
In addition, all of them have a bright form:
brightblack, brightred, brightgreen, brightyellow, brightblue, brightmagenta, brightcyan, brightwhite.
An example of using an ANSI color name is:
--file-style=\"green\"
Unlike RGB hex codes, ANSI color names are just names: you can choose the exact color that each
name corresponds to in the settings of your terminal application (the application you use to
enter commands at a shell prompt). This means that if you use ANSI color names, and you change
the color theme used by your terminal, then delta's colors will respond automatically, without
needing to change the delta command line.
\"purple\" is accepted as a synonym for \"magenta\". Color names and codes are case-insensitive.
3. ANSI color number
An example of using an ANSI color number is:
--file-style=28
There are 256 ANSI color numbers: 0-255. The first 16 are the same as the colors described in
the \"ANSI color name\" section above. See https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit.
Specifying colors like this is useful if your terminal only supports 256 colors (i.e. doesn\'t
support 24-bit color).
LINE NUMBERS
------------
Options --number-minus-format and --number-plus-format allow you to specify a custom string to
display for the line number columns. The string should specify the location of the line number
using the placeholder %ln.
For example, to display the line numbers like
8 ⋮ 9 │ Here is an output line
you would use
--number-minus-format '%ln ⋮'
--number-plus-format '%ln │'
If something isn't working correctly, or you have a feature request, please open an issue at
https://github.com/dandavison/delta/issues.
"
)]
pub struct Opt {
#[structopt(long = "features", env = "DELTA_FEATURES", default_value = "")]
/// Name of delta features to use (space-separated). A feature is a named collection of delta
/// options in ~/.gitconfig. The feature names can also be set using an environment variable
/// named DELTA_FEATURES. Two built-in features are available: 'diff-highlight' and
/// 'diff-so-fancy'. See FEATURES section.
pub features: String,
#[structopt(long = "syntax-theme", env = "BAT_THEME")]
/// The code syntax-highlighting theme to use. Use --list-syntax-themes to demo available
/// themes. If the syntax-highlighting theme is not set using this option, it will be taken
/// from the BAT_THEME environment variable, if that contains a valid theme name.
/// --syntax-theme=none disables all syntax highlighting.
pub syntax_theme: Option<String>,
/// Use default colors appropriate for a light terminal background. For more control, see the
/// style options.
#[structopt(long = "light")]
pub light: bool,
/// Use default colors appropriate for a dark terminal background. For more control, see the
/// style options.
#[structopt(long = "dark")]
pub dark: bool,
#[structopt(long = "diff-highlight")]
/// Emulate diff-highlight (https://github.com/git/git/tree/master/contrib/diff-highlight)
pub diff_highlight: bool,
#[structopt(long = "diff-so-fancy")]
/// Emulate diff-so-fancy (https://github.com/so-fancy/diff-so-fancy)
pub diff_so_fancy: bool,
#[structopt(long = "minus-style", default_value = "normal auto")]
/// Style (foreground, background, attributes) for removed lines. See STYLES section.
pub minus_style: String,
#[structopt(long = "zero-style", default_value = "syntax normal")]
/// Style (foreground, background, attributes) for unchanged lines. See STYLES section.
pub zero_style: String,
#[structopt(long = "plus-style", default_value = "syntax auto")]
/// Style (foreground, background, attributes) for added lines. See STYLES section.
pub plus_style: String,
#[structopt(long = "minus-emph-style", default_value = "normal auto")]
/// Style (foreground, background, attributes) for emphasized sections of removed lines. See
/// STYLES section.
pub minus_emph_style: String,
#[structopt(long = "minus-non-emph-style", default_value = "auto auto")]
/// Style (foreground, background, attributes) for non-emphasized sections of removed lines
/// that have an emphasized section. Defaults to --minus-style. See STYLES section.
pub minus_non_emph_style: String,
#[structopt(long = "plus-emph-style", default_value = "syntax auto")]
/// Style (foreground, background, attributes) for emphasized sections of added lines. See
/// STYLES section.
pub plus_emph_style: String,
#[structopt(long = "plus-non-emph-style", default_value = "auto auto")]
/// Style (foreground, background, attributes) for non-emphasized sections of added lines that
/// have an emphasized section. Defaults to --plus-style. See STYLES section.
pub plus_non_emph_style: String,
#[structopt(long = "commit-style", default_value = "raw")]
/// Style (foreground, background, attributes) for the commit hash line. See STYLES section.
pub commit_style: String,
#[structopt(long = "commit-decoration-style", default_value = "")]
/// Style (foreground, background, attributes) for the commit hash decoration. See STYLES
/// section. One of the special attributes 'box', 'ul', 'overline', or 'underoverline' must be
/// given.
pub commit_decoration_style: String,
#[structopt(long = "file-style", default_value = "blue")]
/// Style (foreground, background, attributes) for the file section. See STYLES section.
pub file_style: String,
#[structopt(long = "file-decoration-style", default_value = "blue ul")]
/// Style (foreground, background, attributes) for the file decoration. See STYLES section. One
/// of the special attributes 'box', 'ul', 'overline', or 'underoverline' must be given.
pub file_decoration_style: String,
#[structopt(long = "navigate")]
/// Activate diff navigation: use n to jump forwards and N to jump backwards. To change the
/// file labels used see --file-modified-label, --file-removed-label, --file-added-label,
/// --file-renamed-label.
pub navigate: bool,
#[structopt(long = "file-modified-label", default_value = "")]
/// Text to display in front of a modified file path.
pub file_modified_label: String,
#[structopt(long = "file-removed-label", default_value = "removed:")]
/// Text to display in front of a removed file path.
pub file_removed_label: String,
#[structopt(long = "file-added-label", default_value = "added:")]
/// Text to display in front of a added file path.
pub file_added_label: String,
#[structopt(long = "file-renamed-label", default_value = "renamed:")]
/// Text to display in front of a renamed file path.
pub file_renamed_label: String,
#[structopt(long = "hunk-header-style", default_value = "syntax")]
/// Style (foreground, background, attributes) for the hunk-header. See STYLES section.
pub hunk_header_style: String,
#[structopt(long = "hunk-header-decoration-style", default_value = "blue box")]
/// Style (foreground, background, attributes) for the hunk-header decoration. See STYLES
/// section. One of the special attributes 'box', 'ul', 'overline', or 'underoverline' must be
/// given.
pub hunk_header_decoration_style: String,
/// Display line numbers next to the diff. The first column contains line
/// numbers in the previous version of the file, and the second column contains
/// line number in the new version of the file. A blank cell in the first or
/// second column indicates that the line does not exist in that file (it was
/// added or removed, respectively).
#[structopt(short = "n", long = "number")]
pub show_line_numbers: bool,
/// Style (foreground, background, attributes) for the left (minus) column of line numbers
/// (--number), if --number is set. See STYLES section. Defaults to
/// --hunk-header-decoration-style.
#[structopt(long = "number-minus-style", default_value = "auto")]
pub number_minus_style: String,
/// Style (foreground, background, attributes) for the right (plus) column of line numbers
/// (--number), if --number is set. See STYLES section. Defaults to
/// --hunk-header-decoration-style.
#[structopt(long = "number-plus-style", default_value = "auto")]
pub number_plus_style: String,
/// Format string for the left (minus) column of line numbers (--number), if --number is set.
/// Should include the placeholder %ln to indicate the position of the line number.
/// See the LINE NUMBERS section.
#[structopt(long = "number-minus-format", default_value = "%ln⋮")]
pub number_minus_format: String,
/// Format string for the right (plus) column of line numbers (--number), if --number is set.
/// Should include the placeholder %ln to indicate the position of the line number.
/// See the LINE NUMBERS section.
#[structopt(long = "number-plus-format", default_value = "%ln│ ")]
pub number_plus_format: String,
/// Style (foreground, background, attributes) for the left (minus) line number format string
/// (--number), if --number is set. See STYLES section. Defaults to
/// --h
|