Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gblame timestamp coloring and support for 256 color terminals #1654

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

bhaak
Copy link

@bhaak bhaak commented Jan 8, 2021

I've been using your "blame_color" branch for a long time and found it tremendously useful for finding recently changed lines. The visual cue due grayscale based on age helps a lot there.

While updating it to the current HEAD, I also added support for coloring hashes and timestamps in a 256 color terminal.

I've been using this patched version for several months now and haven't encountered any issues.

tpope and others added 4 commits January 7, 2021 11:12
This code is taken from tpope's "Timestamp WIP" branch and updated to
the current HEAD.
Using only colors from the 6x6x6 cube without system colors and the
grayscale ramp at the end of the 256 color mode.

Those colors also have the nice property of not being too dark or too
bright and therefore not making the hash unreadable on a dark or light
background.
@bhaak bhaak changed the title Gblame timstamp coloring and support for 256 color terminals Gblame timestamp coloring and support for 256 color terminals Jan 8, 2021
@tpope
Copy link
Owner

tpope commented Mar 23, 2021

I never merged this because I was extremely unsatisfied with the color distribution. Six of the 16 colors will only be used if you have code that is older than software itself. You can multiply by a factor to use more of the scale, but go to far and even year old code starts to look washed out. I don't think a logarithm is the solution to this problem.

In the intervening years since I first prototyped this feature, Git has gained the blame.coloring=highlightRecent option, which adds one color for code less than a month old, and one color for code less than a year old. That seems way more useful than what we're doing. Maybe we should switch to a system like this? We could do more than 2 colors, but less than 16.

As for your 256 color terminal additions, that is what the calls to CSApprox are for. That plugin abstracts away a lot of differences between how various terminals implement color support, but I think most of those differences are moot now, so we can probably replace CSApprox entirely with changes like yours. But a couple of notes:

  • For dates, you're going from dark gray to white rather than black to white, which is completely arbitrary because those colors are flipped around based on the 'background' option. (And keep in mind with the current scaling, half the colors are basically never used.) CSApprox computed [16, 233, 235, 236, 238, 240, 241, 243, 102, 246, 248, 250, 252, 253, 255, 231] which seems like as good of choice as any.
  • For commits, you're doing a dance to avoid black. Instead of % 215, you should scale these with * 215 / 255 (or whatever the appropriate scale is) so the colors merely shift a bit rather than jump all over the place when switching between terminal and GUI.

@tpope
Copy link
Owner

tpope commented Mar 23, 2021

Ignore that final bullet point for now, I was forgetting some of the details involved.

@bhaak
Copy link
Author

bhaak commented Mar 28, 2021

Six of the 16 colors will only be used if you have code that is older than software itself. You can multiply by a factor to use more of the scale, but go to far and even year old code starts to look washed out. I don't think a logarithm is the solution to this problem.

In the intervening years since I first prototyped this feature, Git has gained the blame.coloring=highlightRecent option, which adds one color for code less than a month old, and one color for code less than a year old. That seems way more useful than what we're doing. Maybe we should switch to a system like this? We could do more than 2 colors, but less than 16.

I've been using the Gitblame feature regularly on two repositories, of which one is 10 years old and another that is almost 40 years old but both getting almost daily updates. I've been mainly interested in seeing recent commits stand out well when using Gitblame as that's also where most of the bugs will appear. For older commits I don't think the timestamp coloring is that important (hash coloring gets more valuable in such a case).

The defaults of blame.coloring=highlightRecent are not fine grained enough for my taste. If I would have configure it (but I don't, because I have this patch :) , I would probably set it to 1 day, 2 days, 3 days, 1 week, 2 weeks, 1 month, 3 month, 6 month, 1 years.

As for your 256 color terminal additions, that is what the calls to CSApprox are for.

The problem with CSApprox is that it isn't installed by default and quite obscure. It's also not mentioned in the vim-fugitive documentation. I only learned about it from reading the source. When I first looked for it, I only found the version at vim.org/scripts which I didn't get to work. I only recently learned about the "godlygeek/csapprox" repository that allows to bundle it like any other plugin.

But in any case, nowadays almost every terminal supports 256 color mode out of the box, supporting it directly will just work for most people (88 color mode can be ignored and those that still have only 8/16 colors are out of luck anyway).

For dates, you're going from dark gray to white rather than black to white, which is completely arbitrary because those colors are flipped around based on the 'background' option. (And keep in mind with the current scaling, half the colors are basically never used.) CSApprox computed [16, 233, 235, 236, 238, 240, 241, 243, 102, 246, 248, 250, 252, 253, 255, 231] which seems like as good of choice as any.

I tried to make the grayscale values in shade256 evenly distributed so it can easily used for both background=dark and background=light. But for background=dark, I guess it's more likely that the actual background color is black than the background color is white for background=light. That's why I was avoiding the color black there. But I'm not a light background user, I might be wrong with this reasoning.

Ideally I would want to have a dynamic calculated list of colors that go from foreground color to alnist background color. But that goes beyond my current abilities in vimscript and I don't even know if this information is exported in a suitable way.

@Andrej-Marsic
Copy link

Andrej-Marsic commented Jun 26, 2024

This is one of the two places that mention the coloring of git blame.
Does fugitive now provide the option to color based on recency?

@shadowwa
Copy link

shadowwa commented Sep 6, 2024

I've played a little bit with the colouring algorithm on my branch: https://github.com/shadowwa/vim-fugitive/tree/commit-date-playground

simple log without adapting for oldest commit date (same as blame_color branch)

complete day to ln

index nb of days date
0 2.71828182845905 2024-09-03T20:06:35 #ffffff
1 7.38905609893065 2024-08-29T20:06:35 #eeeeee
2 20.0855369231877 2024-08-16T20:06:35 #dddddd
3 54.5981500331442 2024-07-13T20:06:35 #cccccc
4 148.413159102577 2024-04-10T20:06:35 #bbbbbb
5 403.428793492735 2023-07-30T20:06:35 #aaaaaa
6 1096.63315842846 2021-09-05T20:06:35 #999999
7 2980.95798704173 2016-07-09T20:06:35 #888888
8 8103.08392757538 2002-06-30T20:06:35 #777777
9 22026.4657948067 1964-05-17T20:06:35 #666666
10 59874.1417151978 1860-10-01T20:06:35 #555555
11 162754.791419004 1579-01-28T20:06:35 #444444
12 442413.39200892 0813-05-24T20:06:35 #333333
13 1202604.28416478 -1268-01-25T20:06:35 #222222
14 3269017.37247211 -6926-06-02T20:06:35 #111111
15 8886110.52050787 -22305-05-04T20:06:35 #000000

Going back to -22305 is overkill, I'm quite sure mesolithic guys weren't using git, but I'm not an historian and could be wrong.

complete minutes to ln

index nb of minutes date
0 2.71828182845905 2024-09-06T20:03:51 #ffffff
1 7.38905609893065 2024-09-06T19:59:11 #eeeeee
2 20.0855369231877 2024-09-06T19:46:29 #dddddd
3 54.5981500331442 2024-09-06T19:11:59 #cccccc
4 148.413159102577 2024-09-06T17:38:10 #bbbbbb
5 403.428793492735 2024-09-06T13:23:09 #aaaaaa
6 1096.63315842846 2024-09-06T01:49:57 #999999
7 2980.95798704173 2024-09-04T18:25:38 #888888
8 8103.08392757538 2024-09-01T05:03:30 #777777
9 22026.4657948067 2024-08-22T13:00:08 #666666
10 59874.1417151978 2024-07-27T06:12:27 #555555
11 162754.791419004 2024-05-16T19:31:48 #444444
12 442413.39200892 2023-11-04T14:33:12 #333333
13 1202604.28416478 2022-05-25T16:42:18 #222222
14 3269017.37247211 2018-06-20T16:29:13 #111111
15 8886110.52050787 2007-10-15T22:16:04 #000000

Using minutes as step for log calculation is better for the range but still getting 6 or 7 different colours in the blame window.

with factors to get step at 1 day, 2 days, 3 days, 1 week, 2 weeks, 1 month, 3 month, 6 month, 1 year

index nb of seconds date
0 65423.68 2024-09-06T01:56:11 #ffffff
1 142719.943426829 2024-09-05T04:27:56 #eeeeee
2 311339.598319101 2024-09-03T05:37:36 #dddddd
3 679178.698884468 2024-08-29T23:26:57 #cccccc
4 1481609.49493362 2024-08-20T16:33:06 #bbbbbb
5 3232090.02149649 2024-07-31T10:18:25 #aaaaaa
6 7050714.74148808 2024-06-17T05:34:41 #999999
7 15380938.6604956 2024-03-12T19:37:37 #888888
8 33553091.1052001 2023-08-15T11:48:24 #777777
9 73195137.6677285 2022-05-13T16:07:38 #666666
10 159673162.791472 2019-08-16T18:27:13 #555555
11 348322576.173976 2013-08-24T07:50:21 #444444
12 759856039.370413 2000-08-09T04:59:21 #333333
13 1657604875.65787 1972-02-27T14:19:07 #222222
14 3616019063.40223 1910-02-05T18:22:39 #111111
15 7888245298.32475 1774-09-18T16:52:04 #000000

trying to calculate factor to match the steps @bhaak gave in this thread show almost the same number of colours.

log adapting for oldest commit date

I've then decide to adjust the factors to take into consideration the newest and latest commit appearing on the file blame and adjust the logarithm to match theses. In theses table the steps get for a file blame with commit from now to ten years ago.

index nb of seconds since last commit date
0 1 2024-09-06T20:06:34 #ffffff
1 3.787272238452 2024-09-06T20:06:31 #eeeeee
2 14.3434310081492 2024-09-06T20:06:20 #dddddd
3 54.322478061315 2024-09-06T20:05:40 #cccccc
4 205.734013085536 2024-09-06T20:03:09 #bbbbbb
5 779.17071626417 2024-09-06T19:53:35 #aaaaaa
6 2950.93162272205 2024-09-06T19:17:24 #999999
7 11175.9814123053 2024-09-06T17:00:19 #888888
8 42326.4841402794 2024-09-06T08:21:08 #777777
9 160301.918335759 2024-09-04T23:34:54 #666666
10 607107.00508362 2024-08-30T19:28:08 #555555
11 2299279.50612293 2024-08-11T05:25:16 #444444
12 8707997.44198098 2024-05-29T01:13:18 #333333
13 32979556.9645256 2023-08-22T03:07:19 #222222
14 124902560.528194 2020-09-22T04:57:15 #111111
15 473039999.999999 2009-09-10T20:06:39 #000000

Here the scale is OK for the oldest commit but I don't really care to have a difference between commit happened 1, 3 or 14 seconds ago. To my biggest disappoint, I only got 1 or 2 colours more than the previous tests. and the same happen if I try to match with hours or days.

index nb of hours since last commit date
0 1 2024-09-06T19:06:35 #ffffff
1 2.19401549806661 2024-09-06T17:54:56 #eeeeee
2 4.81370400575649 2024-09-06T15:17:45 #dddddd
3 10.5613411917351 2024-09-06T09:32:54 #cccccc
4 23.1717462550361 2024-09-05T20:56:17 #bbbbbb
5 50.8391704008161 2024-09-04T17:16:14 #aaaaaa
6 111.54192776824 2024-09-02T04:34:05 #999999
7 244.724718207745 2024-08-27T15:23:07 #888888
8 536.929824507777 2024-08-15T11:10:48 #777777
9 1178.03235634425 2024-07-19T18:04:39 #666666
10 2584.62124704321 2024-05-22T03:29:19 #555555
11 5670.69907264507 2024-01-14T13:24:39 #444444
12 12441.6016502552 2023-04-07T10:30:30 #333333
13 27297.0668414312 2021-07-27T11:02:35 #222222
14 59890.1877018603 2017-11-07T09:55:20 #111111
15 131400 2009-09-10T20:06:36 #000000
index nb of days since last commit date
0 1 2024-09-05T20:06:35 #ffffff
1 1.77511138010263 2024-09-04T20:06:35 #eeeeee
2 3.15102041176985 2024-09-02T20:06:35 #dddddd
3 5.59341219186833 2024-08-31T20:06:35 #cccccc
4 9.92892963539025 2024-08-27T20:06:35 #bbbbbb
5 17.6249559880195 2024-08-19T20:06:35 #aaaaaa
6 31.2862599481413 2024-08-05T20:06:35 #999999
7 55.5365960747946 2024-07-12T20:06:35 #888888
8 98.5836437045308 2024-05-30T20:06:35 #777777
9 174.996947831895 2024-03-15T20:06:35 #666666
10 310.639073579623 2023-10-31T20:06:35 #555555
11 551.418954615726 2023-03-04T20:06:35 #444444
12 978.830061542669 2022-01-01T20:06:35 #333333
13 1737.53238143095 2019-12-04T20:06:35 #222222
14 3084.31350357489 2016-03-27T20:06:35 #111111
15 5475 2009-09-10T20:06:35 #000000

Linear adapting for oldest commit date

I also tried a linear approach and if using all 16 colours palette, I lose the focus on the most recent commit, but I find it quite useable.

index nb of seconds since last commit date
0 0 2024-09-06T20:06:35 #ffffff
1 31536000 2023-09-07T20:06:35 #eeeeee
2 63072000 2022-09-07T20:06:35 #dddddd
3 94608000 2021-09-07T20:06:35 #cccccc
4 126144000 2020-09-07T20:06:35 #bbbbbb
5 157680000 2019-09-08T20:06:35 #aaaaaa
6 189216000 2018-09-08T20:06:35 #999999
7 220752000 2017-09-08T20:06:35 #888888
8 252288000 2016-09-08T20:06:36 #777777
9 283824000 2015-09-09T20:06:36 #666666
10 315360000 2014-09-09T20:06:37 #555555
11 346896000 2013-09-09T20:06:37 #444444
12 378432000 2012-09-09T20:06:37 #333333
13 409968000 2011-09-10T20:06:38 #222222
14 441504000 2010-09-10T20:06:38 #111111
15 473040000 2009-09-10T20:06:38 #000000

Quadratic adapting for oldest commit date

Trying to get a little more focus on the more recent commit, I switch to a quadratic curve and it's the one that gave me the more satisfaction on my projects.

index nb of seconds since last commit date
0 0 2024-09-06T20:06:35 #ffffff
1 2102400 2024-08-13T12:06:35 #eeeeee
2 8409600 2024-06-01T12:06:35 #dddddd
3 18921600 2024-01-31T20:06:35 #cccccc
4 33638400 2023-08-14T12:06:35 #bbbbbb
5 52560000 2023-01-07T12:06:36 #aaaaaa
6 75686400 2022-04-14T20:06:35 #999999
7 103017600 2021-06-02T12:06:36 #888888
8 134553600 2020-06-02T12:06:35 #777777
9 170294400 2019-04-15T20:06:35 #666666
10 210240000 2018-01-08T12:06:36 #555555
11 254390400 2016-08-15T12:06:36 #444444
12 302745600 2015-02-02T20:06:37 #333333
13 355305600 2013-06-04T12:06:37 #222222
14 412070400 2011-08-17T12:06:39 #111111
15 473040000 2009-09-10T20:06:38 #000000

Adjusting to match newest and oldest commit allowed to be able to uses almost all the colours.
The drawback is that you can't use the colour alone to guess the age of a commit, even less when you look a another file: a file with its oldest commit 10 year ago could use the same colours for a commit from 1 year ago than a 1 week ago commit of a file having its oldest commit from 10 weeks ago.

You can try the different scale from my branch by (un)commenting lines in https://github.com/shadowwa/vim-fugitive/blob/2c7234761ffc7d734698cec90e153f725bf17f08/autoload/fugitive.vim#L7387-L7395
It maybe could serve to find a good implementation of timestamp colouring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants