We don't care the ref content as long as it is unique, so using threaded
RNG should be fine.
This change means refs/jj/keep will now contain refs of the following
forms:
- new create_no_gc_ref(): 0f8d6cd9721823906cfb55dac99d7bf5
- old create_no_gc_ref(): 0f6d93fe-0507-4db8-ad0a-6317f02e27b9
- prevent_gc(commit_id): 0f9c15100b6f1373f38186357e274a829fb6c4e2
There are several reasons for this:
* We can more easily skip styling a trailing blank line, which other
internal code then can correctly detect as having a trailing
newline. This fixes the TODO in tests/test_commit_template.rs.
* Some tools (like `less -R`) add an extra newline if the final
character is not a newline (e.g. if there's a color reset after
it), which led to an annoying blank line after the diff summary in
e.g. `jj status`.
* Since each line is styled independently, you get all the necessary
escapes even when grepping through the output.
* Some terminals extend background color to the end of the terminal
(i.e. past the newline character), which is probably not what the
user wanted.
* Some tools (like `less -R`) get confused and lose coloring of lines
after a newline.
We often end up writing escape codes for one style and then
immediately after, we write escape codes for another style. That seems
harmless, but it's a little ugly. More importantly, it prepares for
not emitting any escapes for turning off attributes at the end of
formatted contents across multiple lines (see next commit).
So far, configured color rules only support specifying foreground
color, and a better-matching rule completely overrides a worse
match. I'm about to add support for specifying other style attributes,
and I want a rule setting a background color not to be overridden by a
rule setting a foreground color. For that to work, it's not enough to
just find the best match, so this commit rewrites the algorithm for
finding the desired style so it finds all matching rules instead. It
then starts with the worst match and applies the other matches on top
of it in order or priority. I've implemented that priority to be in
order of the depth of matching labels, starting with deeper (more
specific) labels. The new algorithm doesn't care about how many labels
match.
We want to be able combine styles by replacing only some of the
attributes (foreground color, underlining, etc.) in the config. We
could implement that having keeping the current style and then update
it based on what we find in the config for a label we just
added. However, it's simpler if we can parse a configured style
without knowing the current style and just return a `Style` with some
fields blank. This commit prepares for that by making the foreground
color field optional.
I'd like to add support for at least bold font, background color, and
underlining. This commit adds a `struct Style` to store that
information. For now, it just contains the foreground color.
Let's use `crossterm` to make `ColorFormatter` a little more readable,
and maybe also more portable.
This uses the `SetForegroundColor()` function, which uses the escapes
for 256-color support (code 38) instead of the 8-color escapes (codes
30-37) combined with bold/bright (code 1) we were using before. IIUC,
most terminals support the 16 base colors when using the 256-color
escape even if they don't support all the 256 colors. It seems like an
improvement to use actual color codes for the bright colors too,
instead of assuming that terminals render bold as bright (even though
most terminals do).
Before this commit, we relied on ANSI escape 1 - which is specified to
make the font bold - to make the color brighter. That's why we call
the colors "bright blue" etc. When we switch from using code 30-37 to
using 38 to let our color config just control the color (not using
escape1), we therefore lose the bold font on many terminals (at least
in iTerm2 and in the terminal application on my Debian work
computer). As a workaround, I made us still use escape 1 when the
bright colors are used. I'll make boldness a separately configurable
attribute soon. Then we'll be able to remove this hack.
With the switch to `crossterm`, we also reset just the foreground
color (code 39) instead of resetting all attributes (code 0). That
also seems like an improvement, probably making it easier for us to
later support different background colors, underlining, etc.
The implementations of `add_label()` and `remove_label()` had a lot of
duplicated code, and we would soon have more duplication if we didn't
extract it to shared function.
Otherwise nix 2.8 and newer will give this error message:
```
>> nix --version; nix run github:martinvonz/jj
nix (Nix) 2.11.1
error: attribute 'defaultApp.x86_64-linux' should have type 'derivation'
```
Running `cargo fmt` while you're working in an editor means that you
may lose changes because of a race:
1. Your editor reads version X of file
2. `cargo fmt` reads version X
3. You save version Y from your editor
4. `cargo fmt` saves version Z, replacing Y
It's common to write a formatted error/warning message, but we can't use
writeln!() with the current ui.write_*() API, and sometimes we forget to
add "\n" to the message. With this wrapper, ui.write_error("message\n")
will be writeln!(ui.error(), "message"), and trivial formatter.with_label()
call can be replaced with write!(formatter.labeled(...), ...).
This can be disabled with the new `--quiet` option.
Printing every commit would give the user all the information of how to undo
this or where to `jj restore` from if they realize they need to after the
abandon.