-
Notifications
You must be signed in to change notification settings - Fork 13
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
Clean up state search
UI
#3099
Clean up state search
UI
#3099
Conversation
internal/runners/packages/search.go
Outdated
table, err := createSearchTable(v.width, v.height, processedPackages, vulns) | ||
if err != nil { | ||
return errs.Wrap(err, "Could not create search table") | ||
} | ||
v.content = table.Content() | ||
v.packageNames = table.packageNames |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like the table should itself be the view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated this a bit so that the view is more encapsulated. We are still using this type to process the search results but any view processing for the viewport is now done elsewhere.
internal/runners/packages/search.go
Outdated
if s.out.Type().IsStructured() { | ||
s.out.Print(table) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handling structured output through the table feels overloaded. It seems the table is both responsible for handling view logic and for handling data parsing. I'd try to calculate the structured data first and foremost, and if that's all the user requested we never even touch any bubbletea or view logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved the table view calculation to the actual view type. We are still using this table type to calculate the structured search results and the view does further processing for the plain output. Otherwise we dump the table from the search results.
} | ||
|
||
func NewView() (*view, error) { | ||
width, height, err := term.GetSize(int(os.Stdout.Fd())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use os
directly, instead use output.Config().OutWriter
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is expecting a file descriptor. The OutWriter
is an io.Writer
interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add the Fd()
method on Outwriter
? I'm not confident that we'll end up using this long term but having everything agree on a same source of truth will make refactoring this later easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a method to the output Config
type.
Co-authored-by: Nathan Rijksen <nathanr@activestate.com>
Co-authored-by: Nathan Rijksen <nathanr@activestate.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't select text in my terminal when viewing search results. There's a weird symbol on my cursor that I think indicates it has some sort of lock. Possibly this is something the viewport imposes, but we might be able to configure it?
cmds []tea.Cmd | ||
) | ||
|
||
switch msg := msg.(type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like scrolling is already handled through the viewport lib:
https://github.com/charmbracelet/bubbles/blob/master/viewport/viewport.go#L287
Is there a reason we can't make use of that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took some time to try and use this. The Update
method does not implement the correct interface so it's not a simple replacement. We would likely have to do some wrapping. I didn't realize the viewport had these methods as I was following the example that I linked in my initial comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you just call the viewport's Update()
method from your Update()
method? ie. handle whatever you need to handle, then defer the rest to the viewport package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took another look at this and no, it's not that simple. Again, the Update()
function return a struct that doesn't satisfy the tea.Model
interface. This means that we can't just return the values that the Update()
function returns.
I didn't spend a lot of time trying to get this working but I managed to by replacing the underlying viewport. Unfortunately, this means we lose the header and footer spacing that we want to setup so it looks a bit off.
Looking at bit more at the code you linked it's not immediately evident what benefit we get from using this Update
function. It would be handling the scrolling keys for us but that's about it.
If there is some other benefit or if this is something that we need before this can be merged I can try to get it working but it will take some time. If you have an idea on how this might work that I'm not seeing feel free to take a stab at it or just let me know.
Co-authored-by: Nathan Rijksen <nathanr@activestate.com>
Unfortunately, it doesn't appear that this is currently supported: charmbracelet/bubbletea#162 |
Try holding down Shift and click-dragging with the mouse. At least in Linux this should work with terminals whose current applications are handling mouse events. |
Bah.. ok let's revert mouse scrolling then. It's more important that you can select text than that you can scroll with your mouse. And @mitchell-as shift+click didn't do anything for me in iTerm :\ |
result.Name = ptr.From(pkg.Ingredient.Name, "") | ||
result.Description = ptr.From(pkg.Ingredient.Description, "") | ||
result.Website = pkg.Ingredient.Website.String() | ||
result.License = ptr.From(pkg.LatestVersion.LicenseExpression, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Author information is missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have noted this somewhere but we discussed during stand that retrieving the author information requires us to make a separate API call for each package in the search results. We deemed that this would slow down the command too much so opted to leave the authors out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, forgot about that. I filed DX-2581 and a blocker with XT to hopefully get this resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed the vulnerabilities key on the last round of changes. Should be updated now as well as the vulnerability colours. As for the authors see this comment: #3099 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
This uses the
viewport
bubble to handle rendering and scrolling. Example here for reference.