From 07f4fdca42177770d21c2cbed1a8ed6a164dfbee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tuomo=20Syv=C3=A4nper=C3=A4?= Date: Tue, 8 Oct 2019 21:25:17 +0300 Subject: [PATCH 1/3] Add copy YAML to clipboard --- internal/views/details.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/views/details.go b/internal/views/details.go index b39732c8..3d31560b 100644 --- a/internal/views/details.go +++ b/internal/views/details.go @@ -6,6 +6,7 @@ import ( "strconv" "strings" + "github.com/atotto/clipboard" "github.com/derailed/k9s/internal/config" "github.com/derailed/k9s/internal/ui" "github.com/derailed/tview" @@ -77,6 +78,7 @@ func (v *detailsView) bindKeys() { tcell.KeyTab: ui.NewKeyAction("Next Match", v.nextCmd, false), tcell.KeyBacktab: ui.NewKeyAction("Previous Match", v.prevCmd, false), tcell.KeyCtrlS: ui.NewKeyAction("Save", v.saveCmd, true), + ui.KeyC: ui.NewKeyAction("Copy", v.cpCmd, false), } } @@ -111,6 +113,16 @@ func (v *detailsView) saveCmd(evt *tcell.EventKey) *tcell.EventKey { return nil } +func (v *detailsView) cpCmd(evt *tcell.EventKey) *tcell.EventKey { + log.Debug().Msgf("Copied YAML to clipboard") + v.app.Flash().Info("YAML copied to clipboard...") + if err := clipboard.WriteAll(v.GetText(true)); err != nil { + v.app.Flash().Err(err) + } + + return nil +} + func (v *detailsView) backCmd(evt *tcell.EventKey) *tcell.EventKey { if !v.cmdBuff.Empty() { v.cmdBuff.Reset() From ea3710545ab89638cd215fe333238934d58f0f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tuomo=20Syv=C3=A4nper=C3=A4?= Date: Tue, 8 Oct 2019 21:57:04 +0300 Subject: [PATCH 2/3] Change log and flash message to be more accurate --- internal/views/details.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/views/details.go b/internal/views/details.go index 3d31560b..fcd6432e 100644 --- a/internal/views/details.go +++ b/internal/views/details.go @@ -114,12 +114,11 @@ func (v *detailsView) saveCmd(evt *tcell.EventKey) *tcell.EventKey { } func (v *detailsView) cpCmd(evt *tcell.EventKey) *tcell.EventKey { - log.Debug().Msgf("Copied YAML to clipboard") - v.app.Flash().Info("YAML copied to clipboard...") + log.Debug().Msgf("Copied content to clipboard") + v.app.Flash().Info("Content copied to clipboard...") if err := clipboard.WriteAll(v.GetText(true)); err != nil { v.app.Flash().Err(err) } - return nil } From 23849437ad60db42fc444dfc2b52e588ef8a338d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tuomo=20Syv=C3=A4nper=C3=A4?= Date: Tue, 8 Oct 2019 21:58:43 +0300 Subject: [PATCH 3/3] Remove redundant debug log --- internal/views/details.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/views/details.go b/internal/views/details.go index fcd6432e..d6901609 100644 --- a/internal/views/details.go +++ b/internal/views/details.go @@ -114,7 +114,6 @@ func (v *detailsView) saveCmd(evt *tcell.EventKey) *tcell.EventKey { } func (v *detailsView) cpCmd(evt *tcell.EventKey) *tcell.EventKey { - log.Debug().Msgf("Copied content to clipboard") v.app.Flash().Info("Content copied to clipboard...") if err := clipboard.WriteAll(v.GetText(true)); err != nil { v.app.Flash().Err(err)