Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@cjordan
Copy link
Contributor

@cjordan cjordan commented Aug 17, 2025

This commit changes the nom key parsing code such that key bindings in a user's config do not surround special keys (e.g. "ctrl") in angle brackets. Unfortunately this means many tests need to be changes.

Also, any errors encountered when parsing a user's binding config are immediately reported to the user.

@cjordan
Copy link
Contributor Author

cjordan commented Aug 17, 2025

I just realised I commented on the old, somewhat-related PR...

Feel free to let me know if I should change things up. Also, maybe it's just my set up, but hitting ctrl+j on a highlighted unstaged file opened my text editor, when I think it should be moving the cursor down one line. Probably worth giving this code a proper "shake".

@altsem
Copy link
Owner

altsem commented Aug 25, 2025

Started reviewing this now. Think it looks pretty good so far.
I guess there'll be a discrepancy between the -k flag and bindings in the config file.
Perhaps it would be nice if they were consistent, but at least it's documented in --help.

Copy link
Owner

@altsem altsem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thinking about the commit message (and generated changelog).
Perhaps it'd be nice to communicate a bit more:

  • feat(config): Removed support of sequences of keys abc
  • feat(config): Removed requirement of <> around special keys
  • fix(config): Print error an error message when a bound key is invalid

or something like that. What do you think?
It may be a pain to split the PR into these commits, adding empty commits is fine too imo.
As long as you prefix it with feat or fix then there'll be a changelog entry.

https://github.com/altsem/gitu/blob/master/docs/dev-tooling.md

In the meantime I'll ponder whether changelog generation is really worth it 🤡

@altsem
Copy link
Owner

altsem commented Aug 25, 2025

I'm just rolling with the latest version of clippy in CI, so it breaks sometimes whenever new linting rules are added. I pushed a fix for it in master, so if you rebase, it should fix it.

@cjordan
Copy link
Contributor Author

cjordan commented Aug 27, 2025

Thanks for the review! I'll try to do everything indicated soon.

Also I've just looked at ctrl+j again; when I hit that, gitu reports a KeyEvent of "Enter". I tried a different terminal and got the same thing. Maybe my shell is somehow mapping this? Will investigate more soon.

@cjordan
Copy link
Contributor Author

cjordan commented Aug 27, 2025

It appears that on linux terminals, ctrl+j is a line feed and ctrl+m is a carriage return. Will keep investigating.

@cjordan cjordan force-pushed the fix/dont-require-angle-brackets branch 2 times, most recently from cbd88e6 to a89b53b Compare September 6, 2025 01:30
@cjordan
Copy link
Contributor Author

cjordan commented Sep 6, 2025

Sorry for the delay, I hope these new commits follow what you want to see. I did look into breaking up the logic into separate commits, but if it's possible this is pretty difficult because the logic is quite coupled. So I've opted to make 1 or the 3 commits empty, and another with just clippy lints.

Regarding the ctrl+j / ctrl+m stuff, I'm guessing you're a mac user if this hasn't affected you. Pretty sure I didn't see an issue with these keys on my own mac last weekend, but I can confirm this again if you'd like. In any case, I don't believe this work causes these keys to behave differently to before, so I think we should press ahead. (Put another way, before this PR, gitu wasn't handling ctrl+j or ctrl+m on linux correctly, but I haven't made it any worse here.) I think this is an issue with termwiz but I haven't confirmed yet; will also look into crossterm as an alternative backend.

@altsem
Copy link
Owner

altsem commented Sep 7, 2025

@cjordan No problem! I think the commit situation is fine, it's just to produce a changelog which I'd do either way.

I think some terminals treat ctrl+j differently, so it might've been a mistake binding it by default actually. Not sure how the landscape looks like tbh.

I'll have another look :)

Copy link
Owner

@altsem altsem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good I think. This is a much needed fix, thanks! :)

@codecov
Copy link

codecov bot commented Sep 7, 2025

Codecov Report

❌ Patch coverage is 69.82456% with 86 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.22%. Comparing base (8bc7a3a) to head (639ae2b).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/error.rs 2.56% 38 Missing ⚠️
src/bindings.rs 62.50% 12 Missing ⚠️
src/config.rs 50.00% 12 Missing ⚠️
src/main.rs 0.00% 10 Missing ⚠️
src/key_parser.rs 95.07% 7 Missing ⚠️
src/gitu_diff.rs 0.00% 2 Missing ⚠️
src/ops/pull.rs 66.66% 2 Missing ⚠️
src/cmd_log.rs 50.00% 1 Missing ⚠️
src/lib.rs 0.00% 1 Missing ⚠️
src/ops/show.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #407      +/-   ##
==========================================
- Coverage   86.57%   86.22%   -0.36%     
==========================================
  Files          70       70              
  Lines        6883     7004     +121     
==========================================
+ Hits         5959     6039      +80     
- Misses        924      965      +41     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This commit changes the `nom` key parsing code such that key bindings in a
user's config do not surround special keys (e.g. "ctrl") in angle
brackets. Unfortunately this means many tests need to be changes.

Also, any errors encountered when parsing a user's binding config are
immediately reported to the user.
Also do a bunch of clippy lints.
@cjordan cjordan force-pushed the fix/dont-require-angle-brackets branch from a89b53b to 639ae2b Compare September 7, 2025 23:20
@cjordan
Copy link
Contributor Author

cjordan commented Sep 7, 2025

Looks good I think. This is a much needed fix, thanks! :)

Glad I could help! I'd like to use gitu long term; wanted to help out to add momentum :)

It's been a long time since I've used the GitHub UI for PRs, but it looks like I needed to rebase to appease it before merge. Now it looks like it's waiting for you... sorry about that :/

@altsem altsem enabled auto-merge (rebase) September 8, 2025 16:16
@altsem altsem disabled auto-merge September 8, 2025 16:32
@altsem altsem merged commit a4588fe into altsem:master Sep 8, 2025
4 of 5 checks passed
@alexrp
Copy link
Contributor

alexrp commented Nov 7, 2025

A bit late to the party here, but is it intentional that a binding of " " is reported as invalid after this PR?

@cjordan
Copy link
Contributor Author

cjordan commented Nov 7, 2025

Hi there. I think a space literal should be handled by a special key code (like backspace and arrow keys etc.), but I can't check right now. I'll have a look in a few days when I get some idle time.

@alexrp

This comment was marked as outdated.

@alexrp
Copy link
Contributor

alexrp commented Nov 8, 2025

Looks to me like the problem is the removal of support for angle-quoted keys combined with the key parser trimming the input, so the space just gets lost prior to parsing. I agree that recognizing space specially is the most sensible fix for this.

@alexrp
Copy link
Contributor

alexrp commented Nov 8, 2025

#449

altsem pushed a commit that referenced this pull request Nov 8, 2025
This addresses a minor regression in #407 which rendered the following invalid:

    [bindings.root]
    stage = [" "]

Rather than removing the trimming of the key code string, this commit fixes the
problem by recognizing "space" specially, similar to e.g. "tab". As a result,
the above config can be achieved with:

    [bindings.root]
    stage = ["space"]
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.

3 participants