Skip to content

Commit

Permalink
Switch from diff-so-fancy to delta
Browse files Browse the repository at this point in the history
diff-so-fancy [1] provided a way better highlighting than
diff-highlight [2], the tool that is shipped with Git.
Anyway, next to the fact that it is written in Perl and required yet
another interpreter installation, there have also been long-time
problems regarding the `fatal: mismatched output` error when running as
`interactive.diffFilter`.
In so-fancy/diff-so-fancy#296 and
so-fancy/diff-so-fancy#35 are long discussions
and some proposed workarounds, but none really worked properly.

Therefore I switched to delta [3] a while ago and the configurations
have now been tested enough on a day-by-day basis to be persisted in
igloo.
delta not only provides the same features like diff-so-fancy and other
highlighters [4] but comes with many more advantages. The highlighting
can also be styled using the same themes like bat [5] that is also
already available as snowblock [6].

The colors have been adjusted to match the Nord [7] theme.
Note that the Nord color palettes must be provided through the
terminal [8] as the 16 ANSI base colors. Some diff specific colors
have been specified as HEX tripplets. The background colors for added,
removed and modified lines are adjusted in brightness and saturation
using the `scale()` function [9] of the `color` module [10] provided by
the official Sass reference implementation written in Dart [11].

```scss
@use "sass:color";

$nord10: #5e81ac;
$nord11: #bf616a;

$minus-color: color.scale($nord11, $lightness: -28%, $saturation: -20%);
$plus-color: color.scale($nord10, $lightness: -22%, $saturation: -16%);
```

[1]: https://github.com/so-fancy/diff-so-fancy
[2]: https://github.com/git/git/tree/master/contrib/diff-highlight
[3]: https://github.com/dandavison/delta
[4]: https://github.com/dandavison/delta#features
[5]: https://github.com/sharkdp/bat
[6]: https://github.com/arcticicestudio/igloo/tree/master/snowblocks/bat
[7]: https://www.nordtheme.com
[8]: https://www.nordtheme.com/ports
[9]: https://sass-lang.com/documentation/modules/color#scale
[10]: https://sass-lang.com/documentation/modules
[11]: https://github.com/sass/dart-sass

GH-281

Co-authored-by: Sven Greb <[email protected]>
  • Loading branch information
arcticicestudio and svengreb committed May 9, 2020
1 parent ca31290 commit d42b158
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 28 deletions.
Binary file added assets/sb-zsh-zle-iterm2-key_shortcuts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions snowblocks/git/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Colors

## _diff_ Syntax Highlighter

Instead of using the [diff-highlight][] tool that is bundled with _Git_ [diff-so-fancy][] was used for some time because it provided way better syntax highlighting features and styles.
Anyway, next to the fact that it is written in _Perl_ and required yet another interpreter installation, there have also been long-time problems regarding the `fatal: mismatched output` error when running as `interactive.diffFilter`. In https://github.com/so-fancy/diff-so-fancy/issues/296 and https://github.com/so-fancy/diff-so-fancy/issues/35 are long discussions and some proposed workarounds, but none really worked properly.

Anyway, next to the fact that it is written in _Perl_ and therefore requires yet another interpreter installation there have also been long-time problems regarding the `fatal: mismatched output` error when running as Git‘s `interactive.diffFilter`. There are long discussions and some workarounds in https://github.com/so-fancy/diff-so-fancy/issues/296 and https://github.com/so-fancy/diff-so-fancy/issues/35, but none really worked 100% even when additional new lines at the end have been removed from target files.

Therefore this configuration switched to [delta][] that not only provides the [same features like _diff-so-fancy_ and other highlighters][delta#features] but also comes with many more advantages.
The highlighting can also be styled using the same themes like [bat][], that is also already [available as _snowblock_][gh-tree-sb-bat], and so the colors have been adjusted to match the [Nord][] theme.
Note that the _Nord_ color palettes must be [provided through the terminal][nord-ports] as the 16 ANSI base colors. Some _diff_ specific colors are specified as HEX tripplets. The background colors for added, removed and modified lines have been adjusted in brightness and saturation using the [`scale()` function][sass-docs-mods-color#scale] of the [`color` module][sass-docs-mods] provided by the [official Sass reference implementation written in Dart][sass].

```scss
@use "sass:color";

$nord10: #5e81ac;
$nord11: #bf616a;

$minus-color: color.scale($nord11, $lightness: -28%, $saturation: -20%);
$plus-color: color.scale($nord10, $lightness: -22%, $saturation: -16%);
```

[bat]: https://github.com/sharkdp/bat
[delta]: https://github.com/dandavison/delta
[delta#features]: https://github.com/dandavison/delta#features
[diff-highlight]: https://github.com/git/git/tree/master/contrib/diff-highlight
[diff-so-fancy]: https://github.com/so-fancy/diff-so-fancy
[gh-tree-sb-bat]: https://github.com/arcticicestudio/igloo/tree/master/snowblocks/bat
[nord-ports]: https://www.nordtheme.com/ports
[nord]: https://www.nordtheme.com
[sass-docs-mods-color#scale]: https://sass-lang.com/documentation/modules/color#scale
[sass-docs-mods]: https://sass-lang.com/documentation/modules
[sass]: https://github.com/sass/dart-sass
28 changes: 4 additions & 24 deletions snowblocks/git/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 2. https://git-scm.com/book/tr/v2/Customizing-Git-Git-Configuration#_colors_in_git
# 3. https://git-scm.com/docs/git-config#_conditional_includes
# 4. https://git-scm.com/docs/git-config#Documentation/git-config.txt---show-origin
# 5. https://github.com/so-fancy/diff-so-fancy#options
# 5. https://github.com/dandavison/delta

[includeIf "gitdir:~/yggdrasil/"]
path = ./includes/user-arcticicestudio.conf
Expand Down Expand Up @@ -50,7 +50,7 @@
logallrefupdates = true
whitespace = tab-in-indent
editor = vim
pager = diff-so-fancy | less --tabs=2 -RFX
pager = delta --highlight-removed --file-style="box" --commit-color="#88c0d0" --file-color="#8fbcbb" --hunk-color="#81a1c1" --minus-color="#8b454b" --minus-emph-color="#bf616a" --plus-color="#4c6584" --plus-emph-color="#5e81ac" --tabs="2" --theme="Nord"
autocrlf = input

[commit]
Expand All @@ -68,27 +68,8 @@
prompt = true
cmd = idea diff $(cd $(dirname "$LOCAL") && pwd)/$(basename "$LOCAL") $(cd $(dirname "$REMOTE") && pwd)/$(basename "$REMOTE")

[diff-so-fancy]
markEmptyLines = true
changeHunkIndicators = true
stripLeadingSymbols = true
useUnicodeRuler = true

[interactive]
# Temporary replaced "diff-so-fancy" with bundled "diff-highlight".
#
# The reason are incompatibility problems of "diff-so-fancy" with the latest Git versions caused by changes in the
# diff logic.
# See "so-fancy/diff-so-fancy#35" and "so-fancy/diff-so-fancy#296" for details.
#
# Note that downgrading to a compatible Git version is not an option because versions <2.17.1 are effected by
# CVE-2018-11233 and and 11235.
# See https://github.com/git/git/blob/master/Documentation/RelNotes/2.17.1.txt#L7-L10 for details.
#
# To fix this problem for interactive patch mode the filter has been temporary changed to the official
# "diff-highlight" tool bundled with Git.
# See https://github.com/git/git/tree/master/contrib/diff-highlight for details.
diffFilter = diff-highlight
diffFilter = delta --color-only --highlight-removed --file-style="box" --commit-color="#88c0d0" --file-color="#8fbcbb" --hunk-color="#81a1c1" --minus-color="#8b454b" --minus-emph-color="#bf616a" --plus-color="#4c6584" --plus-emph-color="#5e81ac" --theme="Nord"

[merge]
tool = intellij
Expand Down Expand Up @@ -270,8 +251,7 @@
# +----------------------------+
# + Interaction - Format Patch +
# +----------------------------+
# Formats "diff-so-fancy" compatible patchs by removing printed ANSI color escape sequences and enables patch stats
# by default.
# Formats patches by removing printed ANSI color escape sequences and enables patch stats by default.
#
# Usage:
# git fp
Expand Down
7 changes: 3 additions & 4 deletions snowblocks/zsh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ In order to allow a clean and simple way to configure applications, this _snowbl
This _snowblock_ comes with a [custom prompt theme][gh-blob-lib-themes-igloo] for the [_ZSH_ `promptinit` module][zsh-docs-contrib#prompt_themes] named `igloo`. It has been designed for a minimal and uncluttered appearance without an unnecessary overhead of information and distractions.
The theme consists of **eight elements in total**, divided into **fix segments**, where **five of them can be rendered conditionally** or **hidden explicitly through configurations** via environment variables.

<p align="center">Appearance when <strong>all segments</strong> are rendered</p>
<p align="center"><img src="https://raw.githubusercontent.com/arcticicestudio/igloo/master/assets/sb-zsh-prompt-theme-segments-all.png" /></p>

The following sections provide a brief overview of their purpose, style and the ways to configure them.
For a extensive and detailed documentation see the theme help by running `prompt -h igloo`.

Expand Down Expand Up @@ -101,7 +104,6 @@ This is the metadata line that consists of segments like the name of the current
- **Time** — The in _YYYY-MM-DD_ format.
When the `IGLOO_ZSH_PROMPT_THEME_HIDE_TIME` environment variable is set to `true` the segment won‘t be rendered.
**Note** that this does not represent the actual time but the last time the prompt was rendered and printed which occurs when the last command finished.
<p align="center"><img src="https://raw.githubusercontent.com/arcticicestudio/igloo/master/assets/sb-zsh-prompt-theme-segments-default.png" /></p>

## Line B

Expand Down Expand Up @@ -152,9 +154,6 @@ See the official Git documentation about [Git in other environments][git-docs-ap
This is the main line to actually fire and run commands.
The ▶ “arrow“ character is always rendered and not bound by a condition.

<p align="center">Appearance when <strong>all segments</strong> are rendered</p>
<p align="center"><img src="https://raw.githubusercontent.com/arcticicestudio/igloo/master/assets/sb-zsh-prompt-theme-segments-all.png" /></p>

# Colors

This _snowblock_ is designed for the usage with [Nord][] through one of it‘s terminal [port projects][nord-ports].
Expand Down

0 comments on commit d42b158

Please sign in to comment.