From 624c6427d2dce41001310561c4755f9a11e5c85d Mon Sep 17 00:00:00 2001 From: Antoine Meausoone Date: Tue, 30 Jun 2020 22:09:02 +0200 Subject: [PATCH 1/2] feat(log): add copy to clipboard link in log view Closes derailed/k9s#395 --- internal/view/log.go | 12 +++++++++++- internal/view/log_int_test.go | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/view/log.go b/internal/view/log.go index 8d8238ac..c6b2636b 100644 --- a/internal/view/log.go +++ b/internal/view/log.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "github.com/atotto/clipboard" "io" "os" "path/filepath" @@ -184,13 +185,14 @@ func (l *Log) bindKeys() { ui.Key4: ui.NewKeyAction("30m", l.sinceCmd(30*60), true), ui.Key5: ui.NewKeyAction("1h", l.sinceCmd(60*60), true), tcell.KeyEnter: ui.NewSharedKeyAction("Filter", l.filterCmd, false), - ui.KeyC: ui.NewKeyAction("Clear", l.clearCmd, true), + ui.KeyL: ui.NewKeyAction("Clear", l.clearCmd, true), ui.KeyM: ui.NewKeyAction("Mark", l.markCmd, true), ui.KeyS: ui.NewKeyAction("Toggle AutoScroll", l.toggleAutoScrollCmd, true), ui.KeyF: ui.NewKeyAction("Toggle FullScreen", l.toggleFullScreenCmd, true), ui.KeyT: ui.NewKeyAction("Toggle Timestamp", l.toggleTimestampCmd, true), ui.KeyW: ui.NewKeyAction("Toggle Wrap", l.toggleTextWrapCmd, true), tcell.KeyCtrlS: ui.NewKeyAction("Save", l.SaveCmd, true), + ui.KeyC: ui.NewKeyAction("Copy", l.cpCmd, true), }) } @@ -288,6 +290,14 @@ func (l *Log) SaveCmd(evt *tcell.EventKey) *tcell.EventKey { return nil } +func (l *Log) cpCmd(evt *tcell.EventKey) *tcell.EventKey { + l.app.Flash().Info("Content copied to clipboard...") + if err := clipboard.WriteAll(l.logs.GetText(true)); err != nil { + l.app.Flash().Err(err) + } + return nil +} + func sanitizeFilename(name string) string { processedString := invalidPathCharsRX.ReplaceAllString(name, "-") diff --git a/internal/view/log_int_test.go b/internal/view/log_int_test.go index 80cef2f6..1c89ce69 100644 --- a/internal/view/log_int_test.go +++ b/internal/view/log_int_test.go @@ -16,7 +16,7 @@ func TestLogAutoScroll(t *testing.T) { v.GetModel().Set(dao.LogItems{dao.NewLogItemFromString("blee"), dao.NewLogItemFromString("bozo")}) v.GetModel().Notify() - assert.Equal(t, 14, len(v.Hints())) + assert.Equal(t, 15, len(v.Hints())) v.toggleAutoScrollCmd(nil) assert.Equal(t, "Autoscroll: Off FullScreen: Off Timestamps: Off Wrap: Off", v.Indicator().GetText(true)) From fae083b90bc5d0b8bebfac5c38937fe0277963d9 Mon Sep 17 00:00:00 2001 From: Antoine Meausoone Date: Thu, 2 Jul 2020 21:27:26 +0200 Subject: [PATCH 2/2] feat(log): use better key --- internal/view/log.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/view/log.go b/internal/view/log.go index c6b2636b..9218a383 100644 --- a/internal/view/log.go +++ b/internal/view/log.go @@ -185,7 +185,7 @@ func (l *Log) bindKeys() { ui.Key4: ui.NewKeyAction("30m", l.sinceCmd(30*60), true), ui.Key5: ui.NewKeyAction("1h", l.sinceCmd(60*60), true), tcell.KeyEnter: ui.NewSharedKeyAction("Filter", l.filterCmd, false), - ui.KeyL: ui.NewKeyAction("Clear", l.clearCmd, true), + tcell.KeyCtrlK: ui.NewKeyAction("Clear", l.clearCmd, true), ui.KeyM: ui.NewKeyAction("Mark", l.markCmd, true), ui.KeyS: ui.NewKeyAction("Toggle AutoScroll", l.toggleAutoScrollCmd, true), ui.KeyF: ui.NewKeyAction("Toggle FullScreen", l.toggleFullScreenCmd, true),