Skip to content

[#954] parser.rs: enable multiline descriptions #962

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

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

Conversation

gabriel-vanzandycke
Copy link

@gabriel-vanzandycke gabriel-vanzandycke commented Mar 20, 2025

This PR adds the possibility to split description into multiple lines.
Resolves #954

The following cheat sheet:

% test
# Single line description
echo "hello world"
# Multilines
# description 1
```
echo -n hello
echo    world
```
# Multilines
# description 2
echo "hello world"
# Single line description
```
echo -n hello
echo    world
```

Yields the following result:
image

Copy link

welcome bot commented Mar 20, 2025

Thanks for opening this pull request!

@gabriel-vanzandycke
Copy link
Author

I'm working on the multi-line code-block and multi-line description. Here is how I would like it to render
image

I'm almost there. The tag, description and snippet column are correctly rendered, but I struggle with the next columns (in terminal.rs). Can someone help me understand the purpose of the DELIMITER and what is expected by fzf?

@kit494way
Copy link
Contributor

I'm not sure I understand your question correctly, but I will comment on what I understand about DELIMITER.
DELIMITER is a field separator that separates tags, descriptions, commands, and other fields.
DELIMITER is passed to fzf's --delimiter option.

navi/src/finder/mod.rs

Lines 113 to 114 in 6f1bbcf

"--delimiter",
deser::terminal::DELIMITER.to_string().as_str(),

In manual of fzf:

-d, --delimiter=STR
Field delimiter regex for --nth, --with-nth, and field index expressions (default: AWK-style)

DELIMITER is used when we change the order of columns by passing --with-nth option to fzf.
For example, without --with-nth:
スクリーンショット 2025-03-21 083608

With --with-nth:
スクリーンショット 2025-03-21 083711

Does this help?

…locks with multiple lines (only fzf supported)
@gabriel-vanzandycke
Copy link
Author

It did. Thanks!! I hadn't realized that the delimiter could be used for multiple columns within fzf. I'm updating this PR description to integrate latest changes.

@alexis-opolka
Copy link
Collaborator

It looks good @gabriel-vanzandycke , thanks!
I will let either @kit494way or @denisidoro review the code.

Could you link this PR to your issue ?
Using GitHub link words: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue

@gabriel-vanzandycke
Copy link
Author

gabriel-vanzandycke commented Mar 24, 2025

Caveats of this PR:
This implementation required to merge the 3 columns (tag, description and command). Therefore, it is no longer possible to change their order by just overriding fzf arguments (with --with-nth=3,2,1 for instance).

@alexis-opolka
Copy link
Collaborator

alexis-opolka commented Mar 25, 2025

Personally, I don't think it's going to be a big issue, it would be a breaking change for sure to people mainly using this feature but it might make sense if we're moving forward to allow converting other cheatsheet types into navi cheatsheets (see #891) and introducing a syntax parser for cheatsheets (see #948).

To me, we can take two roads from here regarding the columns, both are breaking changes with the current implementation:

  1. We still allow them to be "dynamic" and introduce in this PR another way to change their orders.
  2. We decide they are fixed from now on and their orders won't change for the foreseeable future.

The second option would be viable IF modifying the order of the columns is not something a lot of users do.
I can't say since I don't use them in navi but I can think that there is people who might use them.

@gabriel-vanzandycke
Copy link
Author

Implementing the first option doesn't necessarily need to be done in this PR as it implies a breaking change anyway...

Copy link
Contributor

@kit494way kit494way left a comment

Choose a reason for hiding this comment

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

I think the change in the parsing multiline descriptions is compatible, but the change in the display part is a breaking change.
I think it is better to avoid this breaking change.
How about adding an option to display descriptions and snippets on multiple lines.

To add a note about the --with-nth option, it can be used not only for reordering columns but also for selecting which columns to display.

@gabriel-vanzandycke
Copy link
Author

Thanks @kit494way for your review !

How about adding an option to display descriptions and snippets on multiple lines.

An option specific for multilines rendering is anyway mutually exclusive with column selection option --with-nth= of fzf, and I'm not sure handling both cases in the code is best approach.

I believe giving users the ability to select columns another way is the best option in term of code maintenance, but it's a breaking change.

@alexis-opolka
Copy link
Collaborator

Implementing the first option doesn't necessarily need to be done in this PR as it implies a breaking change anyway...

I agree but it would be best to decide how we're going to change this for users before breaking the current behavior.
I don't want us to introduce breaking changes without knowing where we're going with it and I'm not going to merge this PR until then.

@gabriel-vanzandycke
Copy link
Author

Can someone assist me for setting up tests ?

@alexis-opolka
Copy link
Collaborator

I won't be able to help you on that but maybe those references can help:

@kit494way
Copy link
Contributor

@gabriel-vanzandycke

Can someone assist me for setting up tests ?

Can't run cargo test?
Or are you trying to run ./tests/run?
I think that ./tests/run is intended to be executed in an isolated environment like GitHub Actions, because the test kills tmux sessions and reads user config.yaml if NAVI_CONFIG is not properly set.
If you want to run ./tests/run locally, you might want to consider using act, although I have never run the test with act, so I can't confirm if it works.

@alexis-opolka
Copy link
Collaborator

If needed, I can trigger the tests on GitHub, just let me know.

@@ -258,14 +258,15 @@ impl<'a> Parser<'a> {

// blank
if line.is_empty() {
if !item.snippet.is_empty() {
if !item.snippet.is_empty() && inside_snippet {
item.snippet.push_str(deser::LINE_SEPARATOR);
}
}
// tag
else if line.starts_with('%') {
should_break = self.write_cmd(&item).is_err();
item.snippet = String::from("");
Copy link
Author

@gabriel-vanzandycke gabriel-vanzandycke Mar 27, 2025

Choose a reason for hiding this comment

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

Can someone enlighten me on why the item is reset rather than creating a new item object when we move to the next item ? (It makes me wonder each time I'm in this file)

@gabriel-vanzandycke
Copy link
Author

Thanks. cargo test passes on my side. I failed setting-up act, I'll investigate depending on the next GitHub actions results (@alexis-opolka ).

@alexis-opolka
Copy link
Collaborator

Thanks. cargo test passes on my side. I failed setting-up act, I'll investigate depending on the next GitHub actions results (@alexis-opolka ).

If you successfully installed act, you just need to be in the directory of navi (where .github is present) and run:

act push

It should trigger both CI/Lints and CI/Tests.

@gabriel-vanzandycke
Copy link
Author

Thanks. I ran cargo fmt and pushed the changes, CI should now pass.

@alexis-opolka
Copy link
Collaborator

alexis-opolka commented Mar 28, 2025

Great @gabriel-vanzandycke !

I am waiting for the approval of @kit494way and @denisidoro on this PR and since it contains breaking changes I don't know if we wait to merge it in a later major release or we upgrade the next release from a minor to a major release.

I would like to at least merge it after #955 .

EDIT: When I say a major release I mean a release with breaking changes.

@kit494way
Copy link
Contributor

Please make displaying multiple lines optional.
I'd like to display the search table compactly.

@@ -119,7 +119,7 @@ impl FinderChoice {
]);

if !opts.show_all_columns {
command.args(["--with-nth", "1,2,3"]);
command.args(["--read0", "--print0", "--with-nth", "1"]);
Copy link
Contributor

Choose a reason for hiding this comment

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

It is better to rename show_all_columns or introduce another option for --read0 and --print0 because --read0 and --print0 do not control the number of columns to display.

@denisidoro
Copy link
Owner

I agree with @kit494way. Let's make this opt-in. Otherwise, people may import cheatsheets using this syntax and be surprised by the behavior.

I'll approve the PR once this is addressed.

@alexis-opolka alexis-opolka mentioned this pull request Apr 8, 2025
@alexis-opolka alexis-opolka added the wip Work in progress label Apr 24, 2025
@alexis-opolka
Copy link
Collaborator

Hi @gabriel-vanzandycke ,
Have you had time to look into the requested changes in this PR?

@gabriel-vanzandycke
Copy link
Author

Hello, no, I haven't had the time to look into this, sorry.

@alexis-opolka
Copy link
Collaborator

No worries. ^^

I just wanted to check on you, you can take the time you need to work on this PR.
Let us know if you need help, I might not be able to help much but I'm sure @kit494way or @denisidoro would help you if you need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request wip Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is it possible to have blocks of text in my cheat sheets
4 participants