feat(log): add copy to clipboard link in log view

Closes derailed/k9s#395
mine
Antoine Meausoone 2020-06-30 22:09:02 +02:00
parent e3725817f0
commit 624c6427d2
2 changed files with 12 additions and 2 deletions

View File

@ -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, "-")

View File

@ -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))