mirror of
https://github.com/anchore/syft.git
synced 2026-10-30 14:02:26 +01:00
force UI teardown when event is sourced from a signal interrupt (#453)
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
@@ -77,7 +77,7 @@ func (h *ephemeralTerminalUI) Handle(event partybus.Event) error {
|
||||
case event.Type == syftEvent.PresenterReady:
|
||||
// we need to close the screen now since signaling the the presenter is ready means that we
|
||||
// are about to write bytes to stdout, so we should reset the terminal state first
|
||||
h.closeScreen()
|
||||
h.closeScreen(false)
|
||||
|
||||
if err := handleCatalogerPresenterReady(event); err != nil {
|
||||
log.Errorf("unable to show %s event: %+v", event.Type, err)
|
||||
@@ -105,11 +105,13 @@ func (h *ephemeralTerminalUI) openScreen() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *ephemeralTerminalUI) closeScreen() {
|
||||
func (h *ephemeralTerminalUI) closeScreen(force bool) {
|
||||
// we may have other background processes still displaying progress, wait for them to
|
||||
// finish before discontinuing dynamic content and showing the final report
|
||||
if !h.frame.IsClosed() {
|
||||
h.waitGroup.Wait()
|
||||
if !force {
|
||||
h.waitGroup.Wait()
|
||||
}
|
||||
h.frame.Close()
|
||||
// TODO: there is a race condition within frame.Close() that sometimes leads to an extra blank line being output
|
||||
frame.Close()
|
||||
@@ -130,8 +132,8 @@ func (h *ephemeralTerminalUI) flushLog() {
|
||||
}
|
||||
}
|
||||
|
||||
func (h *ephemeralTerminalUI) Teardown() error {
|
||||
h.closeScreen()
|
||||
func (h *ephemeralTerminalUI) Teardown(force bool) error {
|
||||
h.closeScreen(force)
|
||||
ansi.CursorShow()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -33,6 +33,6 @@ func (l loggerUI) Handle(event partybus.Event) error {
|
||||
return l.unsubscribe()
|
||||
}
|
||||
|
||||
func (l loggerUI) Teardown() error {
|
||||
func (l loggerUI) Teardown(_ bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,5 +7,5 @@ import (
|
||||
type UI interface {
|
||||
Setup(unsubscribe func() error) error
|
||||
partybus.Handler
|
||||
Teardown() error
|
||||
Teardown(force bool) error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user