Skip to content
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

Better Search Results #1871

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

kadaan
Copy link
Contributor

@kadaan kadaan commented Mar 1, 2024

Summary

Output tabular search results which show the platforms available

❯ devbox search ruby
Found 6+ results for "ruby":

┌─────────────┬──────────────────────────────────┬─────────────────┐
│ PACKAGE     │             VERSIONS             │    PLATFORMS    │
├─────────────┼──────────────────────────────────┼─────────────────┤
│             │ 3.3.0                  3.3.0-rc1 │ aarch64-darwin  │
│             │ 3.3.0-preview3    3.3.0-preview2 │ aarch64-linux   │
│ ruby        │ 3.3.0-preview1             3.2.3 │ x86_64-darwin   │
│             │ 3.2.2                      3.2.1 │ x86_64-linux    │
│             │ 3.1.4                      3.1.3 │                 │
│             │                                  │                 │
├─────────────┼──────────────────────────────────┼─────────────────┤
│             │ 0.10.0                           │ aarch64-darwin  │
│ rubyfmt     │                                  │ aarch64-linux   │
│             │                                  │ x86_64-linux    │
│             ├──────────────────────────────────┼─────────────────┤
│             │ 0.8.1                            │ aarch64-darwin  │
│             │                                  │ aarch64-linux   │
│             │                                  │ x86_64-darwin   │
│             │                                  │ x86_64-linux    │
├─────────────┼──────────────────────────────────┤                 │
│             │ 0.14.0                    0.13.4 │                 │
│             │ 0.13.2                    0.13.0 │                 │
│ ruby-lsp    │ 0.11.1                     0.9.4 │                 │
│             │ 0.8.0                      0.7.4 │                 │
│             │                                  │                 │
├─────────────┼──────────────────────────────────┤                 │
│             │ 5.3.0                            │                 │
│ ruby-zoom   │                                  │                 │
│             │                                  │                 │
│             │                                  │                 │
├─────────────┼──────────────────────────────────┼─────────────────┤
│             │ 0.8.0rc3                         │ aarch64-linux   │
│ rubyripper  │ 0.6.2                            │ x86_64-linux    │
│             │                                  │                 │
├─────────────┼──────────────────────────────────┼─────────────────┤
│ rubyMinimal │ 2.6.6                            │ x86_64-linux    │
│             │                                  │                 │
└─────────────┴──────────────────────────────────┴─────────────────┘

Warning: Showing top 10 results and truncated versions. Use --show-all to show all.

Info: For more information go to: https://www.nixhub.io/search?q=ruby
❯ devbox search ruby --show-all
Found 6+ results for "ruby":

┌─────────────┬──────────────────────────────────┬─────────────────┐
│ PACKAGE     │             VERSIONS             │    PLATFORMS    │
├─────────────┼──────────────────────────────────┼─────────────────┤
│             │ 3.3.0                  3.3.0-rc1 │ aarch64-darwin  │
│             │ 3.3.0-preview3    3.3.0-preview2 │ aarch64-linux   │
│             │ 3.3.0-preview1             3.2.3 │ x86_64-darwin   │
│             │ 3.2.2                      3.2.1 │ x86_64-linux    │
│ ruby        │ 3.1.4                      3.1.3 │                 │
│             │ 3.1.2                      3.1.1 │                 │
│             │ 3.1.0                      3.0.6 │                 │
│             │ 3.0.5                      3.0.4 │                 │
│             │ 3.0.3                            │                 │
│             │                                  │                 │
│             ├──────────────────────────────────┼─────────────────┤
│             │ 3.0.2                            │ aarch64-darwin  │
│             │                                  │ x86_64-darwin   │
│             │                                  │ x86_64-linux    │
│             ├──────────────────────────────────┼─────────────────┤
│             │ 3.0.1                            │ x86_64-darwin   │
│             │                                  │ x86_64-linux    │
│             ├──────────────────────────────────┼─────────────────┤
│             │ 3.0.0                            │ x86_64-linux    │
│             │                                  │                 │
│             ├──────────────────────────────────┼─────────────────┤
│             │ 2.7.8                      2.7.7 │ aarch64-darwin  │
│             │ 2.7.6                      2.7.5 │ aarch64-linux   │
│             │                                  │ x86_64-darwin   │
│             │                                  │ x86_64-linux    │
│             ├──────────────────────────────────┼─────────────────┤
│             │ 2.7.4                            │ aarch64-darwin  │
│             │                                  │ x86_64-darwin   │
│             │                                  │ x86_64-linux    │
│             ├──────────────────────────────────┼─────────────────┤
│             │ 2.7.3                            │ x86_64-darwin   │
│             │                                  │ x86_64-linux    │
│             ├──────────────────────────────────┼─────────────────┤
│             │ 2.7.2                            │ x86_64-linux    │
│             │ 2.7.1                            │                 │
│             │                                  │                 │
│             ├──────────────────────────────────┼─────────────────┤
│             │ 2.6.8                            │ aarch64-darwin  │
│             │                                  │ x86_64-darwin   │
│             │                                  │ x86_64-linux    │
│             ├──────────────────────────────────┼─────────────────┤
│             │ 2.6.7                            │ x86_64-darwin   │
│             │                                  │ x86_64-linux    │
│             ├──────────────────────────────────┼─────────────────┤
│             │ 2.6.6                            │ x86_64-linux    │
│             │ 2.5.8                            │                 │
│             │                                  │                 │
├─────────────┼──────────────────────────────────┼─────────────────┤
│             │ 0.10.0                           │ aarch64-darwin  │
│ rubyfmt     │                                  │ aarch64-linux   │
│             │                                  │ x86_64-linux    │
│             ├──────────────────────────────────┼─────────────────┤
│             │ 0.8.1                            │ aarch64-darwin  │
│             │                                  │ aarch64-linux   │
│             │                                  │ x86_64-darwin   │
│             │                                  │ x86_64-linux    │
├─────────────┼──────────────────────────────────┤                 │
│             │ 0.14.0                    0.13.4 │                 │
│             │ 0.13.2                    0.13.0 │                 │
│ ruby-lsp    │ 0.11.1                     0.9.4 │                 │
│             │ 0.8.0                      0.7.4 │                 │
│             │                                  │                 │
├─────────────┼──────────────────────────────────┤                 │
│             │ 5.3.0                            │                 │
│ ruby-zoom   │                                  │                 │
│             │                                  │                 │
│             │                                  │                 │
├─────────────┼──────────────────────────────────┼─────────────────┤
│             │ 0.8.0rc3                         │ aarch64-linux   │
│ rubyripper  │ 0.6.2                            │ x86_64-linux    │
│             │                                  │                 │
├─────────────┼──────────────────────────────────┼─────────────────┤
│ rubyMinimal │ 2.6.6                            │ x86_64-linux    │
│             │                                  │                 │
└─────────────┴──────────────────────────────────┴─────────────────┘
Info: For more information go to: https://www.nixhub.io/search?q=ruby

How was it tested?

Ran search locally and looked at the output.

@kadaan kadaan force-pushed the kadaan/better_search_results branch from f51334a to 291b5a3 Compare March 1, 2024 18:51
@kadaan
Copy link
Contributor Author

kadaan commented Mar 5, 2024

@Lagoja Can someone look at this? I believe that this is a much better search experience for users. Any feedback would be appreciated.

@kadaan
Copy link
Contributor Author

kadaan commented Mar 5, 2024

@Lagoja Also, I don't recall the package at the moment, but the current code (and this PR) filter out packages with empty versions. I think that might be wrong, as I think empty version implies "latest" and by filtering them out they are unfindable.

@gcurtis
Copy link
Collaborator

gcurtis commented Mar 11, 2024

We appreciate the PR, but I think this change may require a bit more discussion because it has a large impact on the UI.

We also import a couple TUI-like helper libraries already (some indirectly like charmbracelet), so it would be nice to consolidate instead of adding another dependency.

@kadaan
Copy link
Contributor Author

kadaan commented Mar 11, 2024

@gcurtis It would be great if some of that discussion could occur here. I'm game to make changes to get a tweaked version of this PR in, as I believe it greatly enhances the usability to the search command.

Also, maybe I missed it, but looks like only lipgloss is currently used from charmbracelet.

@mikeland73
Copy link
Contributor

Yeah, we actually don't pull in any core charmbracelet libraries because they are very large. They would probably increase binary released size by 10MB+

@kadaan
Copy link
Contributor Author

kadaan commented Mar 11, 2024

That makes sense. For reference, adding the dependency used here only increased the binary size for Darwin arm64 by 164kb.

@Lagoja
Copy link
Contributor

Lagoja commented Mar 11, 2024

Looking at this, my thoughts are:

  1. I like the fact that this adds some grouping (I thought it was by major/minor versions, but I guess it's by platform). It’s an improvement in readability over our current UI
  2. The table output makes the content a lot longer — it’s a lot more scrolling for search terms with a lot of results, and it may not scan well on smaller terminal windows. I'm going to try it out a bit to see how it works in practice

As an example, if I run devbox search python --show-all, I have to scroll up a lot before I see actual python results. It's a little better if I paginate the output by piping to less

Is there a way to achieve the version grouping while maintaining the compactness of the current output?

@kadaan
Copy link
Contributor Author

kadaan commented Mar 11, 2024

@Lagoja Thanks for the feedback. The width is intentionally constrained at the moment. The platforms list could be two columns to reduce the height somewhat. The table dividers, or something like that, seem necessary to be able to unambiguously identify which versions and platforms apply together. Color would be an option, but then it might not work in different terminals or with color blindness.

Another improvement would be to detect the width of the terminal and lay the table out at the width. That would allow more columns for version and platform.

Also, once a package stops flip-flopping between supported platforms the version will just appear in the head row, so that saves a ton of space.

@Lagoja
Copy link
Contributor

Lagoja commented Mar 11, 2024

Would it make sense to have the output paginate by default? That way the most relevant hit is shown first, instead of having to scroll up.

@kadaan
Copy link
Contributor Author

kadaan commented Mar 11, 2024

It could. Normal Unix would be to either pipe to a pager or use $PAGER to do the paging.

Copy link
Contributor

@Lagoja Lagoja left a comment

Choose a reason for hiding this comment

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

Ok, my proposal is:

  1. Let's implement pagination. I think it's important to have the most relevant result in the search show up first.
  2. @mikeland73 let's put this behind a feature flag, and advertise it in the upcoming pre-release. If we test it and like it, we can promote it to a default feature.

Thoughts?

@kadaan kadaan force-pushed the kadaan/better_search_results branch from e797404 to 4e73e8d Compare March 15, 2024 16:56
@kadaan
Copy link
Contributor Author

kadaan commented Apr 2, 2024

I'm game to take a stab at implementing paging if you are all in agreement that it will be a useful addition.

@kadaan
Copy link
Contributor Author

kadaan commented Apr 2, 2024

@Lagoja I was considering relying on the system pager ($PAGER) or an devbox specific config ($DEVBOX_PAGER). The could would look like:

	if command, args, ok := findPager(); ok {
		cmd := exec.Command(command, args...)
		cmd.Stdout = w
		pipe, err := cmd.StdinPipe()
		if err != nil {
			return err
		}
		err = cmd.Start()
		if err != nil {
			return errors.WithStack(err)
		}
		defer func(cmd *exec.Cmd) {
			if err := cmd.Wait(); err != nil {
				ux.Ferror(w, "Error running pager: %s\n", err)
			}
		}(cmd)

		w = pipe
		defer func(pipe io.WriteCloser) {
			_ = pipe.Close()
		}(pipe)
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants