mirror of
https://github.com/docker/compose.git
synced 2025-11-18 21:00:38 +01:00
add (restore) support for detach keys
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
45def51117
commit
6e55832b1c
@ -22,6 +22,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -90,6 +91,7 @@ const (
|
|||||||
type LogKeyboard struct {
|
type LogKeyboard struct {
|
||||||
kError KeyboardError
|
kError KeyboardError
|
||||||
Watch *KeyboardWatch
|
Watch *KeyboardWatch
|
||||||
|
Detach func()
|
||||||
IsDockerDesktopActive bool
|
IsDockerDesktopActive bool
|
||||||
logLevel KEYBOARD_LOG_LEVEL
|
logLevel KEYBOARD_LOG_LEVEL
|
||||||
signalChannel chan<- os.Signal
|
signalChannel chan<- os.Signal
|
||||||
@ -161,29 +163,23 @@ func (lk *LogKeyboard) printNavigationMenu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (lk *LogKeyboard) navigationMenu() string {
|
func (lk *LogKeyboard) navigationMenu() string {
|
||||||
var openDDInfo string
|
var items []string
|
||||||
if lk.IsDockerDesktopActive {
|
if lk.IsDockerDesktopActive {
|
||||||
openDDInfo = shortcutKeyColor("v") + navColor(" View in Docker Desktop")
|
items = append(items, shortcutKeyColor("v")+navColor(" View in Docker Desktop"))
|
||||||
}
|
}
|
||||||
|
|
||||||
var openDDUI string
|
|
||||||
if openDDInfo != "" {
|
|
||||||
openDDUI = navColor(" ")
|
|
||||||
}
|
|
||||||
if lk.IsDockerDesktopActive {
|
if lk.IsDockerDesktopActive {
|
||||||
openDDUI = openDDUI + shortcutKeyColor("o") + navColor(" View Config")
|
items = append(items, shortcutKeyColor("o")+navColor(" View Config"))
|
||||||
}
|
}
|
||||||
|
|
||||||
var watchInfo string
|
|
||||||
if openDDInfo != "" || openDDUI != "" {
|
|
||||||
watchInfo = navColor(" ")
|
|
||||||
}
|
|
||||||
isEnabled := " Enable"
|
isEnabled := " Enable"
|
||||||
if lk.Watch != nil && lk.Watch.Watching {
|
if lk.Watch != nil && lk.Watch.Watching {
|
||||||
isEnabled = " Disable"
|
isEnabled = " Disable"
|
||||||
}
|
}
|
||||||
watchInfo = watchInfo + shortcutKeyColor("w") + navColor(isEnabled+" Watch")
|
items = append(items, shortcutKeyColor("w")+navColor(isEnabled+" Watch"))
|
||||||
return openDDInfo + openDDUI + watchInfo
|
items = append(items, shortcutKeyColor("d")+navColor(" Detach"))
|
||||||
|
|
||||||
|
return strings.Join(items, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lk *LogKeyboard) clearNavigationMenu() {
|
func (lk *LogKeyboard) clearNavigationMenu() {
|
||||||
@ -290,6 +286,9 @@ func (lk *LogKeyboard) ToggleWatch(ctx context.Context, options api.UpOptions) {
|
|||||||
|
|
||||||
func (lk *LogKeyboard) HandleKeyEvents(ctx context.Context, event keyboard.KeyEvent, project *types.Project, options api.UpOptions) {
|
func (lk *LogKeyboard) HandleKeyEvents(ctx context.Context, event keyboard.KeyEvent, project *types.Project, options api.UpOptions) {
|
||||||
switch kRune := event.Rune; kRune {
|
switch kRune := event.Rune; kRune {
|
||||||
|
case 'd':
|
||||||
|
lk.clearNavigationMenu()
|
||||||
|
lk.Detach()
|
||||||
case 'v':
|
case 'v':
|
||||||
lk.openDockerDesktop(ctx, project)
|
lk.openDockerDesktop(ctx, project)
|
||||||
case 'w':
|
case 'w':
|
||||||
@ -336,6 +335,10 @@ func (lk *LogKeyboard) EnableWatch(enabled bool, watcher Feature) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (lk *LogKeyboard) EnableDetach(detach func()) {
|
||||||
|
lk.Detach = detach
|
||||||
|
}
|
||||||
|
|
||||||
func allocateSpace(lines int) {
|
func allocateSpace(lines int) {
|
||||||
for i := 0; i < lines; i++ {
|
for i := 0; i < lines; i++ {
|
||||||
clearLine()
|
clearLine()
|
||||||
|
|||||||
@ -152,11 +152,12 @@ func (s *composeService) getContainerStreams(ctx context.Context, container stri
|
|||||||
var stdout io.ReadCloser
|
var stdout io.ReadCloser
|
||||||
var stdin io.WriteCloser
|
var stdin io.WriteCloser
|
||||||
cnx, err := s.apiClient().ContainerAttach(ctx, container, containerType.AttachOptions{
|
cnx, err := s.apiClient().ContainerAttach(ctx, container, containerType.AttachOptions{
|
||||||
Stream: true,
|
Stream: true,
|
||||||
Stdin: true,
|
Stdin: true,
|
||||||
Stdout: true,
|
Stdout: true,
|
||||||
Stderr: true,
|
Stderr: true,
|
||||||
Logs: false,
|
Logs: false,
|
||||||
|
DetachKeys: s.configFile().DetachKeys,
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
stdout = ContainerStdout{HijackedResponse: cnx}
|
stdout = ContainerStdout{HijackedResponse: cnx}
|
||||||
|
|||||||
@ -31,8 +31,13 @@ func (s *composeService) Attach(ctx context.Context, projectName string, options
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
detachKeys := options.DetachKeys
|
||||||
|
if detachKeys == "" {
|
||||||
|
detachKeys = s.configFile().DetachKeys
|
||||||
|
}
|
||||||
|
|
||||||
var attach container.AttachOptions
|
var attach container.AttachOptions
|
||||||
attach.DetachKeys = options.DetachKeys
|
attach.DetachKeys = detachKeys
|
||||||
attach.NoStdin = options.NoStdin
|
attach.NoStdin = options.NoStdin
|
||||||
attach.Proxy = options.Proxy
|
attach.Proxy = options.Proxy
|
||||||
return container.RunAttach(ctx, s.dockerCli, target.ID, &attach)
|
return container.RunAttach(ctx, s.dockerCli, target.ID, &attach)
|
||||||
|
|||||||
@ -49,6 +49,7 @@ func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.
|
|||||||
OpenStdin: !opts.Detach && opts.Interactive,
|
OpenStdin: !opts.Detach && opts.Interactive,
|
||||||
Attach: !opts.Detach,
|
Attach: !opts.Detach,
|
||||||
Containers: []string{containerID},
|
Containers: []string{containerID},
|
||||||
|
DetachKeys: s.configFile().DetachKeys,
|
||||||
})
|
})
|
||||||
var stErr cli.StatusError
|
var stErr cli.StatusError
|
||||||
if errors.As(err, &stErr) {
|
if errors.As(err, &stErr) {
|
||||||
|
|||||||
@ -107,6 +107,10 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
|
|||||||
globalCtx, cancel := context.WithCancel(ctx)
|
globalCtx, cancel := context.WithCancel(ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
if navigationMenu != nil {
|
||||||
|
navigationMenu.EnableDetach(cancel)
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
eg errgroup.Group
|
eg errgroup.Group
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
|
|||||||
@ -597,6 +597,7 @@ func (s *composeService) exec(ctx context.Context, project *types.Project, servi
|
|||||||
exec.Privileged = x.Privileged
|
exec.Privileged = x.Privileged
|
||||||
exec.Command = x.Command
|
exec.Command = x.Command
|
||||||
exec.Workdir = x.WorkingDir
|
exec.Workdir = x.WorkingDir
|
||||||
|
exec.DetachKeys = s.configFile().DetachKeys
|
||||||
for _, v := range x.Environment.ToMapping().Values() {
|
for _, v := range x.Environment.ToMapping().Values() {
|
||||||
err := exec.Env.Set(v)
|
err := exec.Env.Set(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user