Commit Graph

157 Commits

Author SHA1 Message Date
Thomas Otto
c5f7428edd OutputType: PagerCfg and oneshot_write
Use new, smaller PagerCfg instead of the full Config, as for
pager output only 3 variables are relevant.

oneshot_write() can be used to write paginated output, usually
before exiting.
2024-08-01 21:40:55 -04:00
Tau Gärtli
841d559a84 Disable light mode detection in tests (#1765) 2024-07-21 20:41:23 -04:00
Thomas Otto
d7a22a7cf9 tests: set terminal width to 43 (#1741)
Make tests more deterministic by not allowing them
to "see" the current terminal width.
2024-07-07 04:33:15 -04:00
Thomas Otto
096941f77f tests: add insta for snapshot testing (#1739)
Insta makes writing new tests or performing changes which update the
expected value(s) easier. The new reference data can be reviewed
and inserted/updated automatically by `cargo insta review` (after
`cargo install cargo-insta`, but that tool is optional).

The snapshots are stored inline using the `@""` syntax and not in
separate files because the delta test output is small and designed to
be human readable.

See https://insta.rs/#hello-snapshot-testing
and https://docs.rs/insta/1.39.0/insta/
2024-07-06 10:35:06 -04:00
Thomas Otto
f5b37173fe Don't read git files when --no-gitconfig is given + unused variables (#1728)
* Fix unused variables

* Don't read git files when --no-gitconfig is given

Despite starting delta with `--no-gitconfig`, strace still shows
that `.git/config` etc. files are accessed. By no longer doing
that it is very clear that no config options are read from there.
2024-06-24 13:26:28 -04:00
Tau
2f76c56d91 Detect Dark/Light Mode from Terminal (#1615) 2024-03-12 11:05:44 -04:00
Dan Davison
084a6d19b2 Accept clippy suggestions (#1632) 2024-02-19 12:56:22 -05:00
Dan Davison
83ca127e9e Introduce grep-output-type option: ripgrep or classic 2023-06-02 14:36:30 -07:00
nickelc
6a37445efb Add methods for getting GitConfig as reference (#1336) 2023-03-09 05:15:04 -05:00
nickelc
5e4faabfd3 Return the GitRemoteRepo type directly (#1328)
The type is unnecessarily wrapped and it's the only use for
`GitConfigEntry::GitRemote` enum variant.
2023-03-05 17:24:24 -05:00
nickelc
a8446c53bb Update dependencies & switch back to the dirs crate (#1325)
* Update direct dependencies

* Update transient dependencies

* Switch back to `dirs` crate

The `dirs`/`dirs-sys` repositories are unarchived and the crates are
maintained again, while `dirs-next` crates aren't.
2023-03-05 15:07:25 -05:00
nickelc
a30aa5f88f Encapsulate git2 types (#1326)
* Move theme iteration logic to `GitConfig`

The `git2::Config` type is now encapsulated and the regex is given to
`libgit2` to filter the config entries.

* Move remote url getter to `GitConfig`
2023-03-05 14:59:30 -05:00
Josh Soref
590d5fa2eb Spelling (#1257)
Corrects misspellings identified by https://github.com/marketplace/actions/check-spelling

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-03-03 05:31:28 -05:00
nickelc
28bf556897 Fix clippy warnings (#1298)
* Fix clippy warnings

- `clippy::uninlined_format_args`

* Fix clippy warnings

- `clippy::clone_on_copy`
- `clippy::explicit_auto_deref`
- `clippy::iter_cloned_collect`
- `clippy::map_clone`
- `clippy::needless_borrow`
- `clippy::needless_lifetimes`
- `clippy::needless_return`
- `clippy::redundant_clone`
- `clippy::redundant_field_names`
- `clippy::seek_to_start_instead_of_rewind`
- `clippy::unnecessary_cast`
- `clippy::unused_unit`
2023-02-28 06:37:20 -05:00
Sheldon Nico
54e1ee79c7 try fix bad alignment in unicode (#1144) (#1145)
* try fix bad alignment in unicode (#1144)

* use width instead of count in wrap_line

* fix fmt

* 3 tests do not need fail

* fix tests

Co-authored-by: Thomas Otto <th1000s@posteo.net>
2022-12-03 06:59:06 -08:00
clnoll
6b2d0b7fc8 Fix clippy warnings (#1236) 2022-11-13 18:54:39 -05:00
Thomas Otto
65044c0e0d Fix clippy warnings after rust 1.64 upgrade 2022-10-11 16:19:25 -04:00
mliszcz
b99e6c5d9c Fix clippy warnings after rust 1.63 upgrade
Following fixes are included:

* derive_partial_eq_without_eq:
  Eq trait was added by running `cargo clippy --fix --no-deps`.
* get_first:
  Function was replaced by running `cargo clippy --fix --no-deps`.
* unnecessary_to_owned:
  This check was disabled for ANSIString as to_string call is required
  to enforce formatting. Otherwise the underlying string was returned
  directly (probably due to Deref implementation).
* type_complexity:
  Closure type was simplified and Box<> usage was removed.
2022-08-16 18:17:10 -04:00
Dan Davison
3f527e0d9c Fix commit hyperlink formatting (#1110) 2022-06-20 16:01:58 -04:00
Yudai Takada
e7dbdd4846 Tweak some words improved representation (#1078)
* Use "overridden" instead of "overriden"

* Use "line_numbers" instead of "linennumbers"

* Use "context" instead of "contexct"

* Use "summary" instead of "sumary"
2022-05-23 10:56:28 +01:00
William Escande
85a07cd109 Add custom env struct to store env at init (#1025)
This allow to no longer ignore some tests (marked previously as FIXME)
by storing the env at the start of the program (Or creating a custom env
for test purpose)
This centralize almost alls calls to std::env inside one wrapper

Add a test profile to increase speed for testing (5min -> 20sec on my
machine)

clean a few code style like this:
```
if Some(value) = ...
    if value
```
to
```
if Some(true) = ...
```

Co-authored-by: William Escande <wescande@google.com>
2022-03-30 20:35:10 -04:00
Johan Wärlander
9572adb744 Enable commit links for GitLab (#972)
* Enable commit links for GitLab
2022-02-21 12:46:37 -05:00
Dan Davison
3d5b6852a0 Fix hyperlink absolute paths (#939)
Fix file paths and hyperlinks

With this commit the target of a hyperlink should always be an absolute path. This should be true for all file hyperlinks, e.g.

- File hyperlink
- Hunk header hyperlink
- Line number hyperlink

Fixes #890
2022-02-14 12:30:30 -05:00
Thomas Otto
b66d1d3717 Fix unused imports and functions warnings on windows
Otherwise these warnings clutter the github diff display.
2022-02-07 19:35:27 -05:00
Thomas Otto
64258ccef2 Placeholder may contain a type field
Similar to Pythons `{n:2.1f}` where f indicates a floating point type.
The type may be separated by an underscore: `{n:<15.14_type}`.

Add a FormatStringPlaceholderDataAnyPlaceholder template which works
without a borrowed Placeholder.
2022-01-21 03:15:35 -05:00
Thomas Otto
3aed51cdc1 Center Align numbers right-ish (#883)
There is no such thing as "Center Align" with discrete terminal cells. In
some cases a decision has to be made whether to use the left or the right
cell, e.g. when centering one char in 4 cells: "_X__" or "__X_".

The format!() center/^ default is left, but when padding numbers these
are now aligned to the right if required. Strings remain left-aligned.
2022-01-18 19:33:09 -05:00
Dan Davison
7d8533c984 Cwd fixups (#918)
Do cwd computations once only; rename cwd variable
2022-01-18 09:02:21 -05:00
Dan Davison
e9e9fb7c69 Construct hyperlink file path relative to cwd
Fixes #890
2022-01-17 18:30:32 -05:00
Dan Davison
fb38eddd9a Add failing test of file hyperlink in git repo 2022-01-17 18:30:32 -05:00
Thomas Otto
48fec2e6fd Make Config cloneable for DeltaTest, store as Cow<Config> there
Only cloneable when testing, the types git2::Config and
git2::Repository in GitConfig contain C pointers and can't
really be cloned.
2022-01-04 19:51:23 -05:00
Wayne Davison
1d6f18a663 DeltaTest improvements (#876)
* DeltaTest improvements

- Added .expect_contains(), .expect_raw_contains(), and
  .expect_contains_once() member functions to DeltaTestOutput.
  These functions also output some helpful debug info when the
  assert fails.
- Separated .with_config_and_input() into .with_config() and (the
  tweaked) .with_input().
- Made .with_config() create a DeltaTest object (like .with() does).
- Renamed .with() as .with_args().
- Moved .explain_ansi() from DeltaTestOutput to DeltaTest, which must
  now be called prior to .with_input() since the latter stashes off both
  the raw_output & the processed output in the object.
- Changed .expect() and .expect_skip() to return Self so that they can
  continue a chain of multiple expect calls (e.g. a series of partial
  matches with different skip values).
- The processed output text can be accessed via `test_obj.output` (see
  also `test_obj.raw_output`).
- Renamed .expect_skip() to .expect_after_skip().
- Changed .expect() to start at the first line.
- Added .expect_after_header() that works like the old .expect().
- Renamed lines_match() to assert_lines_match() and made it match all
  lines (no skip number).
- Added assert_lines_match_after_skip() to work like the old
  lines_match() function, but with the .expect_after_skip() arg order.
- Converted some old-style tests into DeltaTest style tests.
- Renamed set_cfg as set_config
2022-01-04 03:39:03 -05:00
Dan Davison
b5d7c23e07 Line state refactor (#851)
* Refactor: compute raw line and new line state
2021-12-14 22:21:07 -05:00
Dan Davison
cec8542e5f Revert "Ignore test maing ANSI assertions"
This reverts commit 424fe8b59a.
2021-12-14 01:39:39 -05:00
Dan Davison
fbf88e4686 DELTA_FEATURES appends iff prefixed with +
Thanks @bew for the suggestion.

Fixes #848
2021-12-12 17:36:56 -05:00
Rashil Gandhi
87156fb871 Store history file in data_local_dir for Windows (#847)
* Store history file in data_local_dir

* Be specific
2021-12-11 14:19:43 -05:00
Dan Davison
da083bba2a Store raw_line in HunkZero, as HunkMinus and HunkPlus
ref #829
2021-12-09 20:46:28 -05:00
Dan Davison
424fe8b59a Ignore test maing ANSI assertions
This fails currently in some environments.

Fixes #842
2021-12-08 20:19:11 -05:00
Thomas Otto
91b8c3066c Fix more side-by-side line number miscounts 2021-12-07 19:18:23 -05:00
Thomas Otto
d7ef078acb Add DeltaTest to speed up adding and fixing tests
Using a syntax similar to the builder pattern:
  `DeltaTest::with([config options]).with_input(DIFF).expect(lines)`
plus `.explain_ansi()` to pretty-print ansi codes and `.inspect()` to
print the to-be-tested output.

Rewrite a few tests using it and add ansi tests for 
  --line-fill-method=<spaces|ansi>
2021-12-07 19:18:23 -05:00
Dan Davison
6745f42dda Display merge conflicts 2021-12-05 11:25:05 -05:00
Dan Davison
422954164f Handle combined diff format
With this commit combined diff
format (https://git-scm.com/docs/git-diff#_combined_diff_format) is
handled appropriately. However, there is no special handling of merge
conflict markers.

Fixes #189, #736
2021-12-05 11:25:05 -05:00
Thomas Otto
c8aa15d351 Fix side-by-side line number miscount 2021-12-02 20:33:35 -05:00
Dan Davison
85367a6ab2 Do not fill entirely new/removed lines with non-emph style 2021-11-28 18:28:22 -05:00
Dan Davison
af07e54c7b Refactor: hunk style sections handling
- Factor out a new function update_diff_style_sections
- Use MinusPlus construct more
2021-11-28 18:28:22 -05:00
Dan Davison
52ce4c3443 Refactor: further isolate side-by-side implementation (#801) 2021-11-27 09:00:24 -05:00
Dan Davison
a122013f07 Refactor: rename: LineSegments -> LineSections 2021-11-26 11:25:02 -05:00
Wayne Davison
0c0043b428 Navigate regexp (#782)
* Allow navigate-regexp value to be overridden.

* Don't add an empty label to the navigate_regexp.

* Make --hunk-label=str not require --navigate.

* Change navigate regexp to navigate regex.

* Turn navigate-regex into an Option<String>.
2021-11-22 20:19:23 -05:00
Dan Davison
57cabdcb65 Support precision specifier in run-time format strings 2021-11-15 21:01:32 -05:00
Thomas Otto
93d37649ae Remove +/- line prefix instead of substituting a space
Simplifies line handling and printing by removing a "magical"
1-offset previously required in various locations.

Now explicitly prepend "" in `tokenize()`.
2021-11-10 20:08:28 -05:00
Thomas Otto
59e8908f82 Fix side-by-side mode without line numbers
Even though this feature enables line numbers, these can be disabled via
the git config `delta.line-numbers=false`. So always enable line numbers,
even if they do not print numbers.

Construct more structs with ..Self::default()
2021-10-26 18:05:30 -04:00