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

Skip to content

Conversation

@wagoodman
Copy link
Contributor

@wagoodman wagoodman commented Jun 27, 2021

Today the event loop is coupled with the specific UI details, which is not ideal. This PR splits out those concerns, migrating the event loop from the ui package to cmd and extracting the ui.UI function into an interface for setting up a UI, handling individual events from the event loop, and tearing down the UI. This allows for flow control, signal handling, and worker/event management to be shared, and the UI specifics to be implemented behind an interface --this allows for the ability to swap out the ETUI implementation for the logger implementation, but now without duplicating flow control logic.

Closes #416

Signed-off-by: Alex Goodman <[email protected]>
@wagoodman wagoodman added the enhancement New feature or request label Jun 27, 2021
@wagoodman wagoodman requested a review from a team June 27, 2021 03:38
@wagoodman wagoodman self-assigned this Jun 27, 2021
@github-actions
Copy link

github-actions bot commented Jun 27, 2021

Benchmark Test Results

Benchmark results from the latest changes vs base branch
name                                                   old time/op    new time/op    delta
ImagePackageCatalogers/ruby-gemspec-cataloger-2           759µs ± 1%     780µs ± 0%  +2.84%  (p=0.008 n=5+5)
ImagePackageCatalogers/python-package-cataloger-2        1.02ms ± 0%    1.06ms ± 1%  +4.11%  (p=0.008 n=5+5)
ImagePackageCatalogers/javascript-package-cataloger-2     381µs ± 1%     401µs ± 1%  +5.29%  (p=0.008 n=5+5)
ImagePackageCatalogers/dpkgdb-cataloger-2                 359µs ± 0%     381µs ± 2%  +6.15%  (p=0.016 n=4+5)
ImagePackageCatalogers/rpmdb-cataloger-2                  378µs ± 2%     409µs ± 1%  +8.08%  (p=0.008 n=5+5)
ImagePackageCatalogers/java-cataloger-2                  5.12ms ± 1%    5.49ms ± 2%  +7.17%  (p=0.008 n=5+5)
ImagePackageCatalogers/apkdb-cataloger-2                  572µs ± 0%     606µs ± 1%  +5.96%  (p=0.008 n=5+5)
ImagePackageCatalogers/go-cataloger-2                     199µs ± 0%     211µs ± 1%  +6.50%  (p=0.008 n=5+5)
ImagePackageCatalogers/rust-cataloger-2                   304µs ± 0%     316µs ± 1%  +4.13%  (p=0.008 n=5+5)

name                                                   old alloc/op   new alloc/op   delta
ImagePackageCatalogers/ruby-gemspec-cataloger-2          97.4kB ± 0%    97.5kB ± 0%  +0.10%  (p=0.032 n=5+5)
ImagePackageCatalogers/python-package-cataloger-2         579kB ± 0%     579kB ± 0%    ~     (p=0.841 n=5+5)
ImagePackageCatalogers/javascript-package-cataloger-2     111kB ± 0%     111kB ± 0%    ~     (p=0.690 n=5+5)
ImagePackageCatalogers/dpkgdb-cataloger-2                 115kB ± 0%     115kB ± 0%    ~     (p=1.000 n=5+5)
ImagePackageCatalogers/rpmdb-cataloger-2                  134kB ± 0%     134kB ± 0%  +0.01%  (p=0.008 n=5+5)
ImagePackageCatalogers/java-cataloger-2                  1.79MB ± 0%    1.79MB ± 0%    ~     (p=0.056 n=5+5)
ImagePackageCatalogers/apkdb-cataloger-2                 1.14MB ± 0%    1.14MB ± 0%  +0.00%  (p=0.016 n=5+5)
ImagePackageCatalogers/go-cataloger-2                    53.7kB ± 0%    53.9kB ± 0%  +0.27%  (p=0.008 n=5+5)
ImagePackageCatalogers/rust-cataloger-2                  89.0kB ± 0%    88.9kB ± 0%  -0.01%  (p=0.000 n=5+4)

name                                                   old allocs/op  new allocs/op  delta
ImagePackageCatalogers/ruby-gemspec-cataloger-2           1.96k ± 0%     1.96k ± 0%    ~     (all equal)
ImagePackageCatalogers/python-package-cataloger-2         5.89k ± 0%     5.89k ± 0%    ~     (all equal)
ImagePackageCatalogers/javascript-package-cataloger-2     1.93k ± 0%     1.93k ± 0%    ~     (all equal)
ImagePackageCatalogers/dpkgdb-cataloger-2                 2.37k ± 0%     2.37k ± 0%    ~     (all equal)
ImagePackageCatalogers/rpmdb-cataloger-2                  3.19k ± 0%     3.19k ± 0%    ~     (all equal)
ImagePackageCatalogers/java-cataloger-2                   22.3k ± 0%     22.3k ± 0%    ~     (p=0.167 n=5+5)
ImagePackageCatalogers/apkdb-cataloger-2                  1.85k ± 0%     1.85k ± 0%    ~     (all equal)
ImagePackageCatalogers/go-cataloger-2                     1.44k ± 0%     1.44k ± 0%    ~     (all equal)
ImagePackageCatalogers/rust-cataloger-2                   2.75k ± 0%     2.75k ± 0%    ~     (all equal)

@wagoodman wagoodman marked this pull request as draft June 28, 2021 14:17
@wagoodman wagoodman linked an issue Jun 28, 2021 that may be closed by this pull request
Signed-off-by: Alex Goodman <[email protected]>
Copy link
Contributor

@luhring luhring left a comment

Choose a reason for hiding this comment

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

Thanks! 🎉

cmd/packages.go Outdated
ux := ui.Select(appConfig.CliOptions.Verbosity > 0, appConfig.Quiet)
return ux(errs, eventSubscription)
return eventLoop(
packagesExecWorker(args[0]),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: If we're passing in a specific arg, it could be a nice hint to the reader to identify the arg via an explicit parameter for packagesExec, rather than receive the whole slice and grab item 0 just in time.

github.com/gookit/color v1.2.7
github.com/hashicorp/go-multierror v1.1.0
github.com/hashicorp/go-version v1.2.0
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213
Copy link
Contributor

Choose a reason for hiding this comment

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

Just double-checking that this was intended, since I couldn't remember if we're adding new ANSI logic here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've used this package before and decided to use it for the hide/show of the cursor (was intended)

const statusSet = common.SpinnerDotSet // SpinnerCircleOutlineSet
const completedStatus = "✔" // "●"
const statusSet = components.SpinnerDotSet // SpinnerCircleOutlineSet
const completedStatus = "✔" // "●"
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious: What is "●" for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can remove this --it was used during early development when I was flopping between options

@wagoodman wagoodman marked this pull request as ready for review June 29, 2021 18:25
@wagoodman wagoodman enabled auto-merge (squash) June 29, 2021 18:25
@wagoodman wagoodman merged commit 962e822 into main Jun 29, 2021
@wagoodman wagoodman deleted the split-ui-and-event-handling branch June 29, 2021 18:28
GijsCalis pushed a commit to GijsCalis/syft that referenced this pull request Feb 19, 2024
* split UI from event handling

Signed-off-by: Alex Goodman <[email protected]>

* add event loop tests

Signed-off-by: Alex Goodman <[email protected]>

* use stereoscope cleanup function during signal handling

Signed-off-by: Alex Goodman <[email protected]>

* correct error wrapping in packages cmd

Signed-off-by: Alex Goodman <[email protected]>

* migrate ui event handlers to ui package

Signed-off-by: Alex Goodman <[email protected]>

* clarify command worker input var + remove dead comments

Signed-off-by: Alex Goodman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disk space not freed after syft command

2 participants