Skip to content

Commit e8d9f26

Browse files
committed
allow pasting even if theres no system clipboard
1 parent 2763bb1 commit e8d9f26

File tree

3 files changed

+35
-32
lines changed

3 files changed

+35
-32
lines changed

config/settings.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ type Keymap struct {
3535
FocusMessages string
3636
FocusInput string
3737
FocusChats string
38+
Copyuser string
39+
Pasteuser string
3840
CommandBacklog string
3941
CommandRead string
40-
CommandCopyuser string
4142
CommandConnect string
4243
CommandQuit string
4344
CommandHelp string
@@ -86,7 +87,8 @@ var Config = IniFile{
8687
FocusChats: "Ctrl+e",
8788
CommandBacklog: "Ctrl+b",
8889
CommandRead: "Ctrl+n",
89-
CommandCopyuser: "Ctrl+c",
90+
Copyuser: "Ctrl+c",
91+
Pasteuser: "Ctrl+v",
9092
CommandConnect: "Ctrl+r",
9193
CommandQuit: "Ctrl+q",
9294
CommandHelp: "Ctrl+?",

main.go

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import (
1313
"github.com/normen/whatscli/messages"
1414
"github.com/rivo/tview"
1515
"github.com/skratchdot/open-golang/open"
16+
"github.com/zyedidia/clipboard"
1617
"gitlab.com/tslocum/cbind"
1718
)
1819

19-
var VERSION string = "v1.0.1"
20+
var VERSION string = "v1.0.2"
2021

2122
var sndTxt string = ""
2223
var currentReceiver messages.Chat = messages.Chat{}
@@ -203,10 +204,23 @@ func handleCommand(command string) func(ev *tcell.EventKey) *tcell.EventKey {
203204

204205
func handleCopyUser(ev *tcell.EventKey) *tcell.EventKey {
205206
if hls := textView.GetHighlights(); len(hls) > 0 {
206-
sessionManager.CommandChannel <- messages.Command{"copyuser", []string{hls[0]}}
207+
for _, val := range curRegions {
208+
if val.Id == hls[0] {
209+
clipboard.WriteAll(val.ContactId, "clipboard")
210+
PrintText("copied id of " + val.ContactName + " to clipboard")
211+
}
212+
}
207213
ResetMsgSelection()
208214
} else if currentReceiver.Id != "" {
209-
sessionManager.CommandChannel <- messages.Command{"copyuser", nil}
215+
clipboard.WriteAll(currentReceiver.Id, "clipboard")
216+
PrintText("copied id of " + currentReceiver.Name + " to clipboard")
217+
}
218+
return nil
219+
}
220+
221+
func handlePasteUser(ev *tcell.EventKey) *tcell.EventKey {
222+
if clip, err := clipboard.ReadAll("clipboard"); err == nil {
223+
textInput.SetText(textInput.GetText() + " " + clip)
210224
}
211225
return nil
212226
}
@@ -306,6 +320,7 @@ func handleExitMessages(ev *tcell.EventKey) *tcell.EventKey {
306320

307321
// load the key map
308322
func LoadShortcuts() {
323+
// global bindings for app
309324
keyBindings = cbind.NewConfiguration()
310325
if err := keyBindings.Set(config.Config.Keymap.FocusMessages, handleFocusMessage); err != nil {
311326
PrintErrorMsg("focus_messages:", err)
@@ -322,8 +337,11 @@ func LoadShortcuts() {
322337
if err := keyBindings.Set(config.Config.Keymap.CommandRead, handleCommand("read")); err != nil {
323338
PrintErrorMsg("command_read:", err)
324339
}
325-
if err := keyBindings.Set(config.Config.Keymap.CommandCopyuser, handleCopyUser); err != nil {
326-
PrintErrorMsg("command_copyuser:", err)
340+
if err := keyBindings.Set(config.Config.Keymap.Copyuser, handleCopyUser); err != nil {
341+
PrintErrorMsg("copyuser:", err)
342+
}
343+
if err := keyBindings.Set(config.Config.Keymap.Pasteuser, handlePasteUser); err != nil {
344+
PrintErrorMsg("pasteuser:", err)
327345
}
328346
if err := keyBindings.Set(config.Config.Keymap.CommandBacklog, handleCommand("backlog")); err != nil {
329347
PrintErrorMsg("command_backlog:", err)
@@ -338,15 +356,19 @@ func LoadShortcuts() {
338356
PrintErrorMsg("command_help:", err)
339357
}
340358
app.SetInputCapture(keyBindings.Capture)
359+
// bindings for text input
341360
keysMessages := cbind.NewConfiguration()
342361
if err := keysMessages.Set(config.Config.Keymap.MessageDownload, handleMessageCommand("download")); err != nil {
343362
PrintErrorMsg("message_download:", err)
344363
}
345364
if err := keysMessages.Set(config.Config.Keymap.MessageOpen, handleMessageCommand("open")); err != nil {
346365
PrintErrorMsg("message_open:", err)
347366
}
348-
if err := keysMessages.Set(config.Config.Keymap.CommandCopyuser, handleCopyUser); err != nil {
349-
PrintErrorMsg("command_copyuser:", err)
367+
if err := keysMessages.Set(config.Config.Keymap.Copyuser, handleCopyUser); err != nil {
368+
PrintErrorMsg("copyuser:", err)
369+
}
370+
if err := keysMessages.Set(config.Config.Keymap.Pasteuser, handlePasteUser); err != nil {
371+
PrintErrorMsg("pasteuser:", err)
350372
}
351373
if err := keysMessages.Set(config.Config.Keymap.MessageShow, handleMessageCommand("show")); err != nil {
352374
PrintErrorMsg("message_show:", err)
@@ -419,15 +441,15 @@ func PrintHelp() {
419441
fmt.Fprintln(textView, "[::b] "+cmdPrefix+"remove[::-] [user-id[] = Remove user from group")
420442
fmt.Fprintln(textView, "[::b] "+cmdPrefix+"admin[::-] [user-id[] = Set admin role for user in group")
421443
fmt.Fprintln(textView, "[::b] "+cmdPrefix+"removeadmin[::-] [user-id[] = Remove admin role for user in group")
422-
fmt.Fprintln(textView, "Use[::b]", config.Config.Keymap.CommandCopyuser, "[::-]to copy a selected user id")
444+
fmt.Fprintln(textView, "Use[::b]", config.Config.Keymap.Copyuser, "[::-]to copy a selected user id to clipboard")
445+
fmt.Fprintln(textView, "Use[::b]", config.Config.Keymap.Pasteuser, "[::-]to paste clipboard to text input")
423446
fmt.Fprintln(textView, "")
424447
fmt.Fprintln(textView, "Configuration:")
425448
fmt.Fprintln(textView, " ->", config.GetConfigFilePath())
426449
fmt.Fprintln(textView, "")
427450
}
428451

429452
// called when text is entered by the user
430-
// TODO: parse and map commands automatically
431453
func EnterCommand(key tcell.Key) {
432454
if sndTxt == "" {
433455
return

messages/session_manager.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/normen/whatscli/config"
2121
"github.com/normen/whatscli/qrcode"
2222
"github.com/rivo/tview"
23-
"github.com/zyedidia/clipboard"
2423
"mvdan.cc/xurls/v2"
2524
)
2625

@@ -340,26 +339,6 @@ func (sm *SessionManager) execCommand(command Command) {
340339
} else {
341340
sm.printCommandUsage("info", "[message-id[]")
342341
}
343-
case "copyuser":
344-
if checkParam(command.Params, 1) {
345-
if msg, ok := sm.db.messagesById[command.Params[0]]; ok {
346-
if msg.Info.SenderJid != "" {
347-
clipboard.WriteAll(msg.Info.SenderJid, "clipboard")
348-
sm.uiHandler.PrintText("copied " + sm.db.GetIdShort(msg.Info.SenderJid))
349-
} else {
350-
clipboard.WriteAll(msg.Info.RemoteJid, "clipboard")
351-
sm.uiHandler.PrintText("copied " + sm.db.GetIdShort(msg.Info.RemoteJid))
352-
}
353-
}
354-
} else {
355-
if sm.currentReceiver == "" {
356-
sm.printCommandUsage("copyuser", "[message-id[]")
357-
sm.printCommandUsage("copyuser", "-> in chat")
358-
} else {
359-
clipboard.WriteAll(sm.currentReceiver, "clipboard")
360-
sm.uiHandler.PrintText("copied " + sm.db.GetIdShort(sm.currentReceiver))
361-
}
362-
}
363342
case "download":
364343
if checkParam(command.Params, 1) {
365344
if path, err := sm.downloadMessage(command.Params[0], false); err != nil {

0 commit comments

Comments
 (0)