ok/jj
1
0
Fork 0
forked from mirrors/jj
Commit graph

45 commits

Author SHA1 Message Date
Martin von Zweigbergk
138798ce0a formatter: build style by overwriting matches in priority order
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.
2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
db5dbf3540 formatter: make Style::fg_color an Option
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.
2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
2080913d15 formatter: accept foreground color config as {fg = "blue"} 2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
19e23c321b formatter: parse color config eagerly
It's simpler to parse the color config eagerly. It might also be
faster.
2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
c7b7b5c04b formatter: make room for other styles than foreground color
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.
2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
5cf2b6615a formatter: use crossterm for colors
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.
2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
fbab5e1bd9 formatter: extract repeated code for writing new color code
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.
2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
4b80c259cf formatter: avoid updating unchanged self.current_color 2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
8db8da5990 formatter: make color_for_name() a free function
The function doesn't use its `&self` argument anyway.
2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
91fe6024b6 formatter: add unit tests
This includes a test for the non-deterministic case reported by
@ilyagr at
https://github.com/martinvonz/jj/pull/941#issuecomment-1363561554.
2023-01-13 21:47:50 -08:00
Yuya Nishihara
32e3a87135 cli: add formatter.labeled() for short 2023-01-12 17:32:18 +09:00
Yuya Nishihara
99b84778ed cli: introduce wrapper to writeln!() a message with label
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(...), ...).
2023-01-12 17:32:18 +09:00
Yuya Nishihara
dfe861a5e7 cli: remove unused Formatter::write_from_reader()
It's unused, and we can use std::io::copy() instead.
2023-01-12 17:32:18 +09:00
Martin von Zweigbergk
9257cc34e5 formatter: don't allow rules to match labels out of order
I don't see a good reason to let e.g. "added diff" to match added text
inside a diff when we already allow "diff added" for that. Allowing
both means that we have to decide which should take precedence. With
the recent change to add labels for methods, we no longer depend on it
for the "timestamp author" case ("author timestamp" now
matches). Thanks to @yuja for noticing that dependency.
2023-01-08 23:01:53 -08:00
Yuya Nishihara
d0d92a0e06 cli: initialize Ui without using UserSettings, use config::Config
UserSettings will be instantiated after both user and repo configs are
loaded. We might want to add a wrapper for CLI settings, but I have no idea
how that should be structured. Let's use bare config::Config until then.
2023-01-07 11:33:12 +09:00
Yuya Nishihara
1b45c5fe8e cli: use ui.reset() to process --config-toml arguments
This should also fix handling of --config-toml 'colors...'. Before, the color
table wouldn't be updated without mode change.
2023-01-02 14:14:50 +09:00
Martin von Zweigbergk
5cb3807b26 colors: move defaults from source to file 2022-12-24 07:07:37 -08:00
Martin von Zweigbergk
d8feed9be4 copyright: change from "Google LLC" to "The Jujutsu Authors"
Let's acknowledge everyone's contributions by replacing "Google LLC"
in the copyright header by "The Jujutsu Authors". If I understand
correctly, it won't have any legal effect, but maybe it still helps
reduce concerns from contributors (though I haven't heard any
concerns).

Google employees can read about Google's policy at
go/releasing/contributions#copyright.
2022-11-28 06:05:45 -10:00
Martin von Zweigbergk
91ee32b183 templater: drop support for open template keyword 2022-11-05 06:14:37 -07:00
Martin von Zweigbergk
a061ac022e formatter: add a with_label() helper
There's a risk of forgetting to call `remove_label()` and I've wanted
to reduce that risk for a long time. I considered creating RAII
adapters that implement `Drop`, but I didn't like that that would
ignore errors (such as `BrokenPipe`) that can happen while emitting an
escape sequence in `remove_label()`. I would ideally have liked
Python's context managers here, but Rust doesn't have that. Instead,
we get to use closures. That works pretty well, except that we can't
return other errors than `io::Error` inside the closures. Even with
that limitation, we can use the new `with_label()` method in all but a
few cases.

We can't define the `with_label()` method directly in the trait
because `&mut self` is not a trait object, so we can't pass it on to
the closure (which expects a trait object). The solution is to use
`impl dyn Formatter` (thanks to @kupiakos for figuring that
out!). That unfortunately means that we can *only* call the function
on trait objects, so if `f` is a concrete formatter type
(e.g. `PlainTextFormatter`), then `f.with_label()` won't
compile. Since we only ever access the formatters as trait objects,
that's not really a problem, however.
2022-10-13 19:27:18 -07:00
Yuya Nishihara
3392e83486 cli: do not abstract away underlying output stream at formatter layer
Since the concrete Formatter type is hidden behind the Ui, there wouldn't
be many reasons to use dyn Write at the formatter layer. This allows us
to create a formatter against MutexGuard<Box<dyn Write>> without one more
Box<dyn Write> wrapper.
2022-10-09 09:08:46 +09:00
Yuya Nishihara
885f1d04d1 cli: introduce FormatterFactory to cache color table
This should help to create a temporary ColorFormatter instantly.

A cached_colors table could also be shared across formatters, but doing that
would require some locking mechanism. Since commands like cmd_log/diff()
use a single formatter instance, I don't think shared mutable cache would be
needed for the moment.
2022-10-09 09:08:46 +09:00
Yuya Nishihara
56191610c7 cli: pass formatter label by reference
All callers do String::from(), .to_string(), or .clone(), but owned label
isn't needed unless formatter is a ColorFormatter.
2022-10-08 00:52:33 +09:00
Martin von Zweigbergk
c36b720dd4 cli: rename checkout to working_copy in template 2022-09-18 16:19:58 -07:00
Waleed Khan
7a551e584f cli: jj branch can accept any number of branches 2022-05-02 21:33:58 -07:00
Waleed Khan
4e026c6c93 diff_edit: add hint when using default editor 2022-05-02 08:19:23 -07:00
Martin von Zweigbergk
bcece02084 cli: indicate each workspace's checkout in log (#13)
It seems helpful to show in the log output which commit is checked out
in which workspace, so let's try that. I made it only show the
information if there are multiple checkouts for now.
2022-02-02 21:36:14 -08:00
Martin von Zweigbergk
006cb37183 docs: replace jj concepts by markdown docs
I wanted to have all the documentation available on the command line,
but that makes it harder to maintain and link to. Let's move it to
markdown instead. We may later be able to add some way of presenting
the markdown in the terminal (or maybe by first converting it to
reStructuredText).
2021-12-17 15:18:41 -08:00
Martin von Zweigbergk
626fbee0dd cli: show Git HEAD in log output
It's useful to know which commit is checked out in the underlying Git
repo (if there is one), so let's show that. This patch indicates that
commit with `HEAD@git` in the log output. It's probably not very
useful when the Git repo is "internal" (i.e. stored inside `.jj/`),
because then it's unlikely to change often. I therefore considered not
showing it when the Git repo is internal. However, it turned out that
`HEAD` points to a non-existent branch in the repo I use, so it won't
get imported anyway (by the function added in the previous patch). We
can always review this decision later.

This is part of #44.
2021-12-01 11:08:53 -08:00
Martin von Zweigbergk
ced252f766 cleanup: replace some as_slice() by & 2021-11-10 10:55:58 -08:00
Martin von Zweigbergk
9375106a05 cli: use same color for timestamps in operation log as in commit log 2021-11-07 21:41:22 -08:00
Martin von Zweigbergk
853b40cf18 cleanup: run rustfmt on formatter (missed in recent commit) 2021-10-27 21:26:22 -07:00
Martin von Zweigbergk
3981cd90f8 cli: use bright colors for head of operation log 2021-10-27 16:35:48 -07:00
Martin von Zweigbergk
922fea0c18 cli: use bright color for the current checkout's description too 2021-10-27 16:31:04 -07:00
Martin von Zweigbergk
3587d4ec7e cli: use bright colors for the current checkout
As @arxanas noted, it's hard to tell which commit is currently checked
out. Hopefully bright colors will help. Maybe setting a background
color would be even clearer, but that's harder to do because the
formatter doesn't support background colors yet.
2021-10-27 14:16:13 -07:00
Martin von Zweigbergk
b3ad965a3b formatter: delete default colors for obsolete, evolution-related labels 2021-10-27 14:13:01 -07:00
Martin von Zweigbergk
452fecb7c4 cli: colorize diff summary and sort by path
The order used to be like Mercurial's and the (lack of) coloring used
to be like Git's. Let's try the opposite :)
2021-10-27 14:13:01 -07:00
Martin von Zweigbergk
7917bad5b2 cli: rename "left"/"right" formatter labels to "removed"/"added" 2021-10-27 13:39:59 -07:00
Martin von Zweigbergk
7add35999f cli: add support for Git's unified diff format
As #33 says, the default diff we have can be hard to read and it
cannot be used for use with other tools. This patch adds a `jj diff
--git` mode for showing Git's flavor of unified diffs.

We should add a config option to get these diffs by default. For
interchange with other tools, we also need a way of turnning off color
codes in output (it's currently always on, even when when not printing
to a TTY).
2021-10-10 00:10:19 -07:00
Martin von Zweigbergk
ae7f00e7b1 cli: rename jj prune to jj abandon
The command's help text says "Abandon a revision", which I think is a
good indication that the command's name should be `abandon`. This
patch renames the command and other user-facing occurrences of the
word. The remaining occurrences should be removed when I remove
support for evolution.
2021-09-19 22:51:12 -07:00
Martin von Zweigbergk
fa73b17c66 cli: add jj concepts subcommand for concept help, starting with "branches"
With this commit, you can run `jj concepts branches` to get help about
the "branches" concept. We don't have much help for other commands and
their arguments yet, but I'm starting with concept guides so we can
point to them as we add help for commands and their arguments.

I initially tried to make the command to get help be `jj help
--concept branches`. That would require replacing clap's
implementation of the help command with our own. clap-rs/clap#1350
prevented me from doing that. But I'm pretty happy with having it
under `jj concepts` anyway. It's probably more discoverable that way.

I tried to mimic clap's styling with yellow headings.
2021-09-02 23:06:46 -07:00
Martin von Zweigbergk
4878c94052 cli: color branch name and conflict marker in jj branches output 2021-08-11 09:15:08 -07:00
Martin von Zweigbergk
15132a1166 cli: replace git refs by branches and tags in log output
Now that our own branches and tags are updated when git refs are
updated and the user can use them to specify revisions, we can start
displaying them instead of the git refs. This commit adds new
`branches` and `tags` template keywords and updates the default
templates to use them instead of `git_refs`.
2021-08-04 11:53:37 -07:00
Martin von Zweigbergk
4c416dd864 cleanup: let Clippy fix a bunch of warnings 2021-06-14 00:27:31 -07:00
Martin von Zweigbergk
b50ef1410d styler: rename Styler to more standard Formatter 2021-06-05 08:38:28 -07:00
Renamed from src/styler.rs (Browse further)