Repository navigation
refactor(up): inject the navigation menu instead of importing cmd/formatter #14324
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
Merged
glours
merged 3 commits into
docker:main
from
ndeloof:refactor/navigation-menu-inversion
Oct 12, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| /* | ||
| Copyright 2020 Docker Compose CLI authors | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package formatter | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/compose-spec/compose-go/v2/types" | ||
| "github.com/eiannone/keyboard" | ||
| "gotest.tools/v3/assert" | ||
|
|
||
| "github.com/docker/compose/v5/pkg/api" | ||
| ) | ||
|
|
||
| func TestRunHandlesKeysUntilContextIsDone(t *testing.T) { | ||
| detached := make(chan struct{}) | ||
| keys := make(chan keyboard.KeyEvent, 1) | ||
| lk := NewKeyboardManager(false, false, make(chan os.Signal, 1)) | ||
| lk.keys = keys | ||
| lk.EnableDetach(func() { close(detached) }) | ||
|
|
||
| ctx, cancel := context.WithCancel(t.Context()) | ||
| done := make(chan struct{}) | ||
| go func() { | ||
| lk.Run(ctx, &types.Project{}, api.UpOptions{}) | ||
| close(done) | ||
| }() | ||
|
|
||
| keys <- keyboard.KeyEvent{Rune: 'd'} | ||
| select { | ||
| case <-detached: | ||
| case <-time.After(5 * time.Second): | ||
| t.Fatal("the detach key was not handled") | ||
| } | ||
|
|
||
| cancel() | ||
| select { | ||
| case <-done: | ||
| case <-time.After(5 * time.Second): | ||
| t.Fatal("Run must return once its context is done") | ||
| } | ||
| assert.NilError(t, lk.Close(), "Close must be harmless when the keyboard was never opened") | ||
| assert.NilError(t, lk.Close(), "Close must be idempotent") | ||
| } | ||
|
|
||
| func TestRunReturnsWhenKeyboardIsClosed(t *testing.T) { | ||
| keys := make(chan keyboard.KeyEvent) | ||
| lk := NewKeyboardManager(false, false, make(chan os.Signal, 1)) | ||
| lk.keys = keys | ||
|
|
||
| done := make(chan struct{}) | ||
| go func() { | ||
| lk.Run(t.Context(), &types.Project{}, api.UpOptions{}) | ||
| close(done) | ||
| }() | ||
|
|
||
| close(keys) // what keyboard.Close does to the channel it handed out | ||
| select { | ||
| case <-done: | ||
| case <-time.After(5 * time.Second): | ||
| t.Fatal("Run must return once the keyboard channel is closed") | ||
| } | ||
| } | ||
|
|
||
| func TestRunWithoutOpenReturnsImmediately(t *testing.T) { | ||
| lk := NewKeyboardManager(false, false, make(chan os.Signal, 1)) | ||
| done := make(chan struct{}) | ||
| go func() { | ||
| lk.Run(t.Context(), &types.Project{}, api.UpOptions{}) | ||
| close(done) | ||
| }() | ||
| select { | ||
| case <-done: | ||
| case <-time.After(5 * time.Second): | ||
| t.Fatal("Run must not wait for keys that can't come") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| Copyright 2020 Docker Compose CLI authors | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package api | ||
|
|
||
| import "context" | ||
|
|
||
| // Feature is a compose feature that can be started and stopped on demand, | ||
| // e.g. by a command of the interactive menu of `compose up`. | ||
| type Feature interface { | ||
| Start(context.Context) error | ||
| Stop() error | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /* | ||
| Copyright 2020 Docker Compose CLI authors | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package compose | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
|
|
||
| "github.com/compose-spec/compose-go/v2/types" | ||
|
|
||
| "github.com/docker/compose/v5/pkg/api" | ||
| ) | ||
|
|
||
| // NavigationMenu is the interactive keyboard menu of a foreground `compose up`. | ||
| // The terminal rendering is up to the implementation, which the CLI provides | ||
| // (see WithNavigationMenu): the library only drives it. | ||
| type NavigationMenu interface { | ||
| // Decorate returns a LogConsumer that keeps the menu displayed below the logs | ||
| Decorate(api.LogConsumer) api.LogConsumer | ||
| // EnableWatch makes the menu able to toggle watch, which is initially enabled or not | ||
| EnableWatch(enabled bool, watcher api.Feature) | ||
| // EnableDetach sets the function run when the user asks to detach | ||
| EnableDetach(detach func()) | ||
| // Open takes control of the keyboard. Keys typed from then on are kept until | ||
| // Run consumes them. An error means the menu can't be used (no terminal, …) | ||
| // and the session carries on without it. | ||
| Open() error | ||
| // Run reacts to the keys typed by the user until ctx is done. It is called | ||
| // once, after Open and after the menu has been fully configured. | ||
| Run(ctx context.Context, project *types.Project, options api.UpOptions) | ||
| // Close gives the keyboard back. It can be called several times, and also | ||
| // when Open failed. | ||
| Close() error | ||
| } | ||
|
|
||
| // NavigationMenuFactory creates the NavigationMenu of an `up` session. It must | ||
| // return a nil interface, not a typed nil pointer, when there is no menu. | ||
| // isDockerDesktopActive and isLogsViewEnabled tell which Docker Desktop | ||
| // integrations the menu can offer, and signals is the channel the menu notifies | ||
| // with an interruption when the user asks to stop the application. | ||
| type NavigationMenuFactory func(isDockerDesktopActive, isLogsViewEnabled bool, signals chan<- os.Signal) NavigationMenu | ||
|
|
||
| // WithNavigationMenu configures the interactive menu displayed by a foreground | ||
| // `up` when api.StartOptions.NavigationMenu is set. Without it, no menu is | ||
| // displayed. | ||
| func WithNavigationMenu(factory NavigationMenuFactory) Option { | ||
| return func(s *composeService) error { | ||
| s.navigationMenu = factory | ||
| return nil | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.