Merge pull request #342 from syvanpera/copy-yaml-to-clipboard

Add copy YAML to clipboard
mine
Fernand Galiana 2019-10-08 20:46:39 -07:00 committed by GitHub
commit b0285ca4be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -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,14 @@ func (v *detailsView) saveCmd(evt *tcell.EventKey) *tcell.EventKey {
return nil
}
func (v *detailsView) cpCmd(evt *tcell.EventKey) *tcell.EventKey {
v.app.Flash().Info("Content 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()