mirror of
https://github.com/docker/compose.git
synced 2025-07-23 21:54:40 +02:00
Does not start keyboard manager if there is no tty
Signed-off-by: Joana Hrotko <joana.hrotko@docker.com>
This commit is contained in:
parent
339b331a86
commit
ff20b641c7
@ -79,6 +79,16 @@ func (opts upOptions) apply(project *types.Project, services []string) (*types.P
|
|||||||
return project, nil
|
return project, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (opts *upOptions) validateNavigationMenu(dockerCli command.Cli, experimentals *experimental.State) {
|
||||||
|
if !dockerCli.Out().IsTerminal() {
|
||||||
|
opts.navigationMenu = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !opts.navigationMenuChanged {
|
||||||
|
opts.navigationMenu = SetUnchangedOption(ComposeMenu, experimentals.NavBar())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service, experiments *experimental.State) *cobra.Command {
|
func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service, experiments *experimental.State) *cobra.Command {
|
||||||
up := upOptions{}
|
up := upOptions{}
|
||||||
create := createOptions{}
|
create := createOptions{}
|
||||||
@ -100,7 +110,10 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service, ex
|
|||||||
if len(up.attach) != 0 && up.attachDependencies {
|
if len(up.attach) != 0 && up.attachDependencies {
|
||||||
return errors.New("cannot combine --attach and --attach-dependencies")
|
return errors.New("cannot combine --attach and --attach-dependencies")
|
||||||
}
|
}
|
||||||
return runUp(ctx, dockerCli, backend, experiments, create, up, build, project, services)
|
|
||||||
|
up.validateNavigationMenu(dockerCli, experiments)
|
||||||
|
|
||||||
|
return runUp(ctx, dockerCli, backend, create, up, build, project, services)
|
||||||
}),
|
}),
|
||||||
ValidArgsFunction: completeServiceNames(dockerCli, p),
|
ValidArgsFunction: completeServiceNames(dockerCli, p),
|
||||||
}
|
}
|
||||||
@ -170,7 +183,6 @@ func runUp(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
dockerCli command.Cli,
|
dockerCli command.Cli,
|
||||||
backend api.Service,
|
backend api.Service,
|
||||||
experimentals *experimental.State,
|
|
||||||
createOptions createOptions,
|
createOptions createOptions,
|
||||||
upOptions upOptions,
|
upOptions upOptions,
|
||||||
buildOptions buildOptions,
|
buildOptions buildOptions,
|
||||||
@ -190,9 +202,6 @@ func runUp(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !upOptions.navigationMenuChanged {
|
|
||||||
upOptions.navigationMenu = SetUnchangedOption(ComposeMenu, experimentals.NavBar())
|
|
||||||
}
|
|
||||||
|
|
||||||
var build *api.BuildOptions
|
var build *api.BuildOptions
|
||||||
if !createOptions.noBuild {
|
if !createOptions.noBuild {
|
||||||
|
@ -275,10 +275,6 @@ func (lk *LogKeyboard) StartWatch(ctx context.Context, project *types.Project, o
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lk *LogKeyboard) KeyboardClose() {
|
|
||||||
_ = keyboard.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Context, project *types.Project, options api.UpOptions) {
|
func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Context, project *types.Project, options api.UpOptions) {
|
||||||
switch kRune := event.Rune; kRune {
|
switch kRune := event.Rune; kRune {
|
||||||
case 'v':
|
case 'v':
|
||||||
@ -288,8 +284,7 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont
|
|||||||
}
|
}
|
||||||
switch key := event.Key; key {
|
switch key := event.Key; key {
|
||||||
case keyboard.KeyCtrlC:
|
case keyboard.KeyCtrlC:
|
||||||
lk.KeyboardClose()
|
_ = keyboard.Close()
|
||||||
|
|
||||||
lk.clearNavigationMenu()
|
lk.clearNavigationMenu()
|
||||||
ShowCursor()
|
ShowCursor()
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ import (
|
|||||||
"github.com/docker/compose/v2/pkg/progress"
|
"github.com/docker/compose/v2/pkg/progress"
|
||||||
"github.com/eiannone/keyboard"
|
"github.com/eiannone/keyboard"
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *composeService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error { //nolint:gocyclo
|
func (s *composeService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error { //nolint:gocyclo
|
||||||
@ -90,20 +91,20 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
|
|||||||
}
|
}
|
||||||
|
|
||||||
var kEvents <-chan keyboard.KeyEvent
|
var kEvents <-chan keyboard.KeyEvent
|
||||||
isWatchConfigured := s.shouldWatch(project)
|
|
||||||
isDockerDesktopActive := s.isDesktopIntegrationActive()
|
|
||||||
|
|
||||||
tracing.KeyboardMetrics(ctx, options.Start.NavigationMenu, isDockerDesktopActive, isWatchConfigured)
|
|
||||||
if options.Start.NavigationMenu {
|
if options.Start.NavigationMenu {
|
||||||
kEvents, err = keyboard.GetKeys(100)
|
kEvents, err = keyboard.GetKeys(100)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
logrus.Warn("could not start menu, an error occurred while starting.")
|
||||||
}
|
} else {
|
||||||
|
isWatchConfigured := s.shouldWatch(project)
|
||||||
|
isDockerDesktopActive := s.isDesktopIntegrationActive()
|
||||||
|
tracing.KeyboardMetrics(ctx, options.Start.NavigationMenu, isDockerDesktopActive, isWatchConfigured)
|
||||||
|
|
||||||
formatter.NewKeyboardManager(ctx, isDockerDesktopActive, isWatchConfigured, signalChan, s.Watch)
|
formatter.NewKeyboardManager(ctx, isDockerDesktopActive, isWatchConfigured, signalChan, s.Watch)
|
||||||
if options.Start.Watch {
|
if options.Start.Watch {
|
||||||
formatter.KeyboardManager.StartWatch(ctx, project, options)
|
formatter.KeyboardManager.StartWatch(ctx, project, options)
|
||||||
}
|
}
|
||||||
defer formatter.KeyboardManager.KeyboardClose()
|
}
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user