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

Make terminal interface pluggable #10

Merged
merged 2 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ const rootID = "root"
type runner func(ctx context.Context, t terminalapi.Terminal, c *container.Container, opts ...termdash.Option) error

func Run() error {
return run(termdash.Run)
}

func run(r runner) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

t, err := termbox.New(termbox.ColorMode(terminalapi.ColorMode256))
if err != nil {
return fmt.Errorf("failed to generate terminal interface: %w", err)
}
defer t.Close()
return run(t, termdash.Run)
}

func run(t *termbox.Terminal, r runner) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

c, err := container.New(t, container.ID(rootID))
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions gui/gui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (

"github.com/mum4k/termdash"
"github.com/mum4k/termdash/container"
"github.com/mum4k/termdash/terminal/termbox"
"github.com/mum4k/termdash/terminal/terminalapi"
"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
)

// TODO: Ensure to kill all goroutine when running unit tests.
/*func TestMain(m *testing.M) {
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}*/
}

func TestRun(t *testing.T) {
tests := []struct {
Expand All @@ -39,7 +40,7 @@ func TestRun(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := run(tt.r)
err := run(&termbox.Terminal{}, tt.r)
assert.Equal(t, tt.wantErr, err != nil)
})
}
Expand Down