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

Skip to content

Commit fee35dd

Browse files
authored
redirect cursor hide/show to stderr (anchore#456)
Signed-off-by: Alex Goodman <[email protected]>
1 parent ecf4e55 commit fee35dd

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ require (
2121
github.com/gookit/color v1.2.7
2222
github.com/hashicorp/go-multierror v1.1.0
2323
github.com/hashicorp/go-version v1.2.0
24-
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213
2524
github.com/mitchellh/go-homedir v1.1.0
2625
github.com/mitchellh/mapstructure v1.3.1
2726
github.com/olekukonko/tablewriter v0.0.4

go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X
466466
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
467467
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
468468
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
469-
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213 h1:qGQQKEcAR99REcMpsXCp3lJ03zYT1PkRd3kQGPn9GVg=
470469
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
471470
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
472471
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=

internal/ui/ephemeral_terminal_ui.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7+
"io"
78
"os"
89
"sync"
910

1011
"github.com/anchore/syft/internal/log"
1112
"github.com/anchore/syft/internal/logger"
1213
syftEvent "github.com/anchore/syft/syft/event"
1314
"github.com/anchore/syft/ui"
14-
"github.com/k0kubun/go-ansi"
1515
"github.com/wagoodman/go-partybus"
1616
"github.com/wagoodman/jotframe/pkg/frame"
1717
)
@@ -38,18 +38,20 @@ type ephemeralTerminalUI struct {
3838
waitGroup *sync.WaitGroup
3939
frame *frame.Frame
4040
logBuffer *bytes.Buffer
41+
output *os.File
4142
}
4243

4344
func NewEphemeralTerminalUI() UI {
4445
return &ephemeralTerminalUI{
4546
handler: ui.NewHandler(),
4647
waitGroup: &sync.WaitGroup{},
48+
output: os.Stderr,
4749
}
4850
}
4951

5052
func (h *ephemeralTerminalUI) Setup(unsubscribe func() error) error {
5153
h.unsubscribe = unsubscribe
52-
ansi.CursorHide()
54+
hideCursor(h.output)
5355

5456
// prep the logger to not clobber the screen from now on (logrus only)
5557
h.logBuffer = bytes.NewBufferString("")
@@ -93,7 +95,7 @@ func (h *ephemeralTerminalUI) openScreen() error {
9395
config := frame.Config{
9496
PositionPolicy: frame.PolicyFloatForward,
9597
// only report output to stderr, reserve report output for stdout
96-
Output: os.Stderr,
98+
Output: h.output,
9799
}
98100

99101
fr, err := frame.New(config)
@@ -126,14 +128,22 @@ func (h *ephemeralTerminalUI) flushLog() {
126128
logWrapper, ok := log.Log.(*logger.LogrusLogger)
127129
if ok {
128130
fmt.Fprint(logWrapper.Output, h.logBuffer.String())
129-
logWrapper.Logger.SetOutput(os.Stderr)
131+
logWrapper.Logger.SetOutput(h.output)
130132
} else {
131-
fmt.Fprint(os.Stderr, h.logBuffer.String())
133+
fmt.Fprint(h.output, h.logBuffer.String())
132134
}
133135
}
134136

135137
func (h *ephemeralTerminalUI) Teardown(force bool) error {
136138
h.closeScreen(force)
137-
ansi.CursorShow()
139+
showCursor(h.output)
138140
return nil
139141
}
142+
143+
func hideCursor(output io.Writer) {
144+
fmt.Fprint(output, "\x1b[?25l")
145+
}
146+
147+
func showCursor(output io.Writer) {
148+
fmt.Fprint(output, "\x1b[?25h")
149+
}

0 commit comments

Comments
 (0)