denisidoro / navi

An interactive cheatsheet tool for the command-line
Apache License 2.0
14.62k stars 491 forks source link

navi cannot search cheats with truncated tags or comments #459

Open kai2nenobu opened 3 years ago

kai2nenobu commented 3 years ago

Describe the bug

When tags or comments are truncated in a narrow window, navi cannot search cheats with truncated tags or comments.

To Reproduce

  1. Set a terminal window width to around 100 columns.
  2. navi repo add denisidoro/cheats
  3. Input query unixporn or penguin
  4. No candidates are shown

Expected behavior

navi shows this cheat in candidates.

Screenshots

The target cheat is shown with no query.

image

Query with penguin in a narrow window (around 100 columns)

image

Query unixporn in a narrow window (around 100 columns)

image

Query penguin in a wide window (around 180 columns)

image

Query unixporn in a wide winodw (around 180 columns)

image

Versions:

welcome[bot] commented 3 years ago

Thanks for opening your first issue here! In case you're facing a bug, please update navi to the latest version first. Maybe the bug is already solved! :)

kai2nenobu commented 3 years ago

This bug also happens with --best-match option. In a wide window, navi automatically selects the target cheat.

image

However, doesn't in a narrow window

image

denisidoro commented 3 years ago

Duplicate of https://github.com/denisidoro/navi/issues/249#issuecomment-598633887

denisidoro commented 3 years ago

I'm afraid there's no way to fix it with the existing TUI (which uses fzf)

However, --best-match should have a different behavior. When navi is unable to get a terminal window width (which is the case of a subshell/--best-match), then navi assumes it's like 99999.

I'll take a look if this part of the code is buggy.

kai2nenobu commented 3 years ago

Oh, I'm sorry to duplicate the issue.

Just a thought, but how about adding a new option that doesn't truncate tags and comments, but simply combines tags, comments, and commands? It won't look good because the columns are not aligned, but it will allow fzf to search on all words.

denisidoro commented 3 years ago

There's this workaround: NAVI_TAG_WIDTH=60 NAVI_COMMENT_WIDTH=120 navi

It's ugly, but it will make sure columns are wide enough.

denisidoro commented 3 years ago

Another workaround is to have lines like this:

<trimmed_tag> <trimmed_comment> <command>   <A LOT OF SPACES>    <tag> <comment>

The downside is that all lines will contain ... at the end of the terminal window + if a search matches <comment> but not <trimmed_comment>, the results will be quite confusing.

WDYT?

kai2nenobu commented 3 years ago

I think your workaround is good and downsides are trivial to me 👍. But how can I achieve the workaround?

denisidoro commented 3 years ago

Right now, you can't. The next release will probably include this workaround and you'll be able to enable it using a config flag.