added copy to clipboard shortcut

pull/202/head
Yassine Safraoui 10 months ago
parent c9db4dce55
commit 37828263d3
  1. 28
      cmd/cli/main.go

@ -14,6 +14,7 @@ import (
"sync"
"time"
"github.com/atotto/clipboard"
"github.com/awesome-gocui/gocui"
"github.com/curusarn/resh/internal/cfg"
"github.com/curusarn/resh/internal/datadir"
@ -160,6 +161,10 @@ func runReshCli(out *output.Output, config cfg.Config) (string, int) {
out.FatalE(errMsg, err)
}
if err := g.SetKeybinding("", gocui.KeyCtrlY, gocui.ModNone, layout.CopyCommand); err != nil {
out.FatalE(errMsg, err)
}
ctx := context.Background()
layout.updateData(ctx, *query)
layout.updateRawData(ctx, *query)
@ -252,6 +257,27 @@ func (m manager) AbortPaste(g *gocui.Gui, v *gocui.View) error {
return nil
}
func (m manager) CopyCommand(g *gocui.Gui, v *gocui.View) error {
m.s.lock.Lock()
defer m.s.lock.Unlock()
if m.s.rawMode {
if m.s.highlightedItem < len(m.s.rawData) {
err := clipboard.WriteAll(m.s.rawData[m.s.highlightedItem].CmdLineOut)
if err != nil {
return err
}
}
} else {
if m.s.highlightedItem < len(m.s.data) {
err := clipboard.WriteAll(m.s.data[m.s.highlightedItem].CmdLineOut)
if err != nil {
return err
}
}
}
return nil
}
func (m manager) updateData(ctx context.Context, input string) {
timeStart := time.Now()
sugar := m.out.Logger.Sugar()
@ -543,7 +569,7 @@ func (m manager) normalMode(g *gocui.Gui, v *gocui.View) error {
var statusLineHeight int = len(statusLine)
helpLineHeight := 1
const helpLine = "HELP: type to search, UP/DOWN or CTRL+P/N to select, RIGHT to edit, ENTER to execute, CTRL+G to abort, CTRL+C/D to quit; " +
const helpLine = "HELP: type to search, UP/DOWN or CTRL+P/N to select, RIGHT to edit, ENTER to execute, CTRL+G to abort, CTRL+C/D to quit; CTRL+Y to copy; " +
"FLAGS: G = this git repo, E# = exit status #"
// "TIP: when resh-cli is launched command line is used as initial search query"

Loading…
Cancel
Save