@@ -13,10 +13,11 @@ import (
13
13
"github.com/normen/whatscli/messages"
14
14
"github.com/rivo/tview"
15
15
"github.com/skratchdot/open-golang/open"
16
+ "github.com/zyedidia/clipboard"
16
17
"gitlab.com/tslocum/cbind"
17
18
)
18
19
19
- var VERSION string = "v1.0.1 "
20
+ var VERSION string = "v1.0.2 "
20
21
21
22
var sndTxt string = ""
22
23
var currentReceiver messages.Chat = messages.Chat {}
@@ -203,10 +204,23 @@ func handleCommand(command string) func(ev *tcell.EventKey) *tcell.EventKey {
203
204
204
205
func handleCopyUser (ev * tcell.EventKey ) * tcell.EventKey {
205
206
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
+ }
207
213
ResetMsgSelection ()
208
214
} 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 )
210
224
}
211
225
return nil
212
226
}
@@ -306,6 +320,7 @@ func handleExitMessages(ev *tcell.EventKey) *tcell.EventKey {
306
320
307
321
// load the key map
308
322
func LoadShortcuts () {
323
+ // global bindings for app
309
324
keyBindings = cbind .NewConfiguration ()
310
325
if err := keyBindings .Set (config .Config .Keymap .FocusMessages , handleFocusMessage ); err != nil {
311
326
PrintErrorMsg ("focus_messages:" , err )
@@ -322,8 +337,11 @@ func LoadShortcuts() {
322
337
if err := keyBindings .Set (config .Config .Keymap .CommandRead , handleCommand ("read" )); err != nil {
323
338
PrintErrorMsg ("command_read:" , err )
324
339
}
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 )
327
345
}
328
346
if err := keyBindings .Set (config .Config .Keymap .CommandBacklog , handleCommand ("backlog" )); err != nil {
329
347
PrintErrorMsg ("command_backlog:" , err )
@@ -338,15 +356,19 @@ func LoadShortcuts() {
338
356
PrintErrorMsg ("command_help:" , err )
339
357
}
340
358
app .SetInputCapture (keyBindings .Capture )
359
+ // bindings for text input
341
360
keysMessages := cbind .NewConfiguration ()
342
361
if err := keysMessages .Set (config .Config .Keymap .MessageDownload , handleMessageCommand ("download" )); err != nil {
343
362
PrintErrorMsg ("message_download:" , err )
344
363
}
345
364
if err := keysMessages .Set (config .Config .Keymap .MessageOpen , handleMessageCommand ("open" )); err != nil {
346
365
PrintErrorMsg ("message_open:" , err )
347
366
}
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 )
350
372
}
351
373
if err := keysMessages .Set (config .Config .Keymap .MessageShow , handleMessageCommand ("show" )); err != nil {
352
374
PrintErrorMsg ("message_show:" , err )
@@ -419,15 +441,15 @@ func PrintHelp() {
419
441
fmt .Fprintln (textView , "[::b] " + cmdPrefix + "remove[::-] [user-id[] = Remove user from group" )
420
442
fmt .Fprintln (textView , "[::b] " + cmdPrefix + "admin[::-] [user-id[] = Set admin role for user in group" )
421
443
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" )
423
446
fmt .Fprintln (textView , "" )
424
447
fmt .Fprintln (textView , "Configuration:" )
425
448
fmt .Fprintln (textView , " ->" , config .GetConfigFilePath ())
426
449
fmt .Fprintln (textView , "" )
427
450
}
428
451
429
452
// called when text is entered by the user
430
- // TODO: parse and map commands automatically
431
453
func EnterCommand (key tcell.Key ) {
432
454
if sndTxt == "" {
433
455
return
0 commit comments