aboutsummaryrefslogtreecommitdiffstats
path: root/src/e_keys.go
blob: 2d053802c3427e7b4fc41d669041f87865e7b837 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
/*
 * ========================
 * =====    ===============
 * ======  ================
 * ======  ================
 * ======  ====   ====   ==
 * ======  ===     ==  =  =
 * ======  ===  =  ==     =
 * =  ===  ===  =  ==  ====
 * =  ===  ===  =  ==  =  =
 * ==     =====   ====   ==
 * ========================
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *
 * Copyright (c) 2023-2024, Joe
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the organization nor the names of its
 *    contributors may be used to endorse or promote products derived from
 *    this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * hardflip: src/e_keys.go
 * Mon May 13 10:51:48 2024
 * Joe
 *
 * events in the keys
 */

package main

import (
	"os"
	"strconv"
	"strings"

	"github.com/gdamore/tcell/v2"
)

func e_normal_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
	if event.Key() == tcell.KeyCtrlC ||
	   event.Rune() == 'q' {
		ui.s.Fini()
		os.Exit(0)
	} else if event.Rune() == 'j' ||
			  event.Key() == tcell.KeyDown {
		data.litems.inc(+1)
	} else if event.Rune() == 'k' ||
			  event.Key() == tcell.KeyUp {
		data.litems.inc(-1)
	} else if event.Key() == tcell.KeyCtrlD ||
			  event.Key() == tcell.KeyPgDn {
		data.litems.inc(+(ui.dim[H] / 3))
	} else if event.Key() == tcell.KeyCtrlU ||
			  event.Key() == tcell.KeyPgUp {
		data.litems.inc(-(ui.dim[H] / 3))
	} else if event.Key() == tcell.KeyCtrlF {
		// TODO: maybe keymap these
	} else if event.Key() == tcell.KeyCtrlB {
		// TODO: maybe keymap these
	} else if event.Rune() == '}' ||
			  event.Rune() == ']' {
		if next := data.litems.curr.next_dir(); next != nil {
			data.litems.curr = next
		}
	} else if event.Rune() == '{' ||
			  event.Rune() == '[' {
		if prev := data.litems.curr.prev_dir(); prev != nil {
			data.litems.curr = prev
		}
	} else if event.Rune() == 'g' ||
			  event.Key() == tcell.KeyHome {
		data.litems.curr = data.litems.head
		data.litems.draw = data.litems.head
	} else if event.Rune() == 'G' ||
			  event.Key() == tcell.KeyEnd {
		data.litems.curr = data.litems.last
	} else if event.Rune() == 'D' &&
			  data.litems.head != nil &&
			  data.litems.curr != nil {
		ui.mode = DELETE_MODE
	} else if event.Rune() == 'H' {
		for curr := data.litems.last; curr != nil; curr = curr.prev {
			if curr.is_dir() == true && data.folds[curr.Dirs] == nil {
				e_fold_dir(data, curr)
			}
		}
		data.litems.curr = data.litems.head
		data.litems.draw = data.litems.curr
	} else if event.Rune() == 'h' ||
			  event.Key() == tcell.KeyLeft {
		for curr := data.litems.curr;
			curr != nil;
			curr = curr.prev {
			if curr.is_dir() == true {
				if data.folds[curr.Dirs] == nil {
					e_fold_dir(data, curr)
					data.litems.curr = curr
					data.litems.draw = data.litems.curr
					return true
				} else {
					if data.folds[curr.Dirs.Parent] == nil {
						parent := curr.Dirs.Parent
						for curr_new := curr;
							curr_new != nil;
							curr_new = curr_new.prev {
							if curr_new.is_dir() == true {
								if curr_new.Dirs == parent {
									e_fold_dir(data, curr_new)
									data.litems.curr = curr_new
									data.litems.draw = data.litems.curr
									return true
								} else {
									if data.folds[curr_new.Dirs] ==
									   nil {
										e_fold_dir(data, curr_new)
									}
								}
							}
						}
					}
					return true
				}
			}
		}
	} else if event.Rune() == 'l' ||
			  event.Key() == tcell.KeyRight ||
			  event.Key() == tcell.KeyEnter {
		if data.litems.curr == nil {
			return true
		} else if data.litems.curr.is_dir() == false {
			c_exec(data.litems.curr.Host, data.opts, ui)
		} else if data.litems.curr.Dirs != nil &&
				  data.folds[data.litems.curr.Dirs] == nil {
			e_fold_dir(data, data.litems.curr)
		} else {
			e_unfold_dir(data, data.litems.curr)
		}
	} else if event.Rune() == ' ' {
		if data.litems.curr == nil ||
		   data.litems.curr.is_dir() == false {
			return true
		}
		if data.litems.curr.Dirs != nil &&
		   data.folds[data.litems.curr.Dirs] == nil {
			e_fold_dir(data, data.litems.curr)
		} else {
			e_unfold_dir(data, data.litems.curr)
		}
	} else if event.Rune() == 'a' ||
			  event.Rune() == 'i' {
		ui.mode = INSERT_MODE
		ui.insert_method = INSERT_ADD
		ui.insert_sel = 0
		ui.insert_sel_ok = false
		ui.insert_scroll = 0
	} else if event.Rune() == 'e' &&
			  data.litems.curr != nil &&
			  data.litems.curr.is_dir() == false {
		tmp := e_deep_copy_host(data.litems.curr.Host)
		data.insert = &tmp
		e_set_protocol_max(data, data.insert)
		if data.insert.Protocol == PROTOCOL_RDP && data.insert.Drive != nil {
			e_set_drive_keys(data)
		}
		ui.mode = INSERT_MODE
		ui.insert_method = INSERT_EDIT
		ui.insert_sel = INS_PROTOCOL
		ui.insert_sel_ok = false
	} else if event.Key() == tcell.KeyCtrlR {
		e_reload_data(data)
	} else if event.Rune() == 'm' ||
			  event.Key() == tcell.KeyF7 {
		ui.mode = MKDIR_MODE
	} else if event.Rune() == 'y' &&
			(data.litems.curr == nil ||
			 data.litems.curr.is_dir() == true) == false {
		ui.insert_method = INSERT_COPY
		data.yank = data.litems.curr
		ui.msg_buff = "yanked " + data.yank.Host.Name +
			" (" + data.yank.Host.parent.path() + data.yank.Host.filename + ")"
	} else if event.Rune() == 'd' &&
			(data.litems.curr == nil ||
			 data.litems.curr.is_dir() == true) == false {
		ui.insert_method = INSERT_MOVE
		data.yank = data.litems.curr
		ui.msg_buff = "yanked " + data.yank.Host.Name +
			" (" + data.yank.Host.parent.path() + data.yank.Host.filename + ")"
	} else if event.Rune() == 'p' && data.yank != nil {
		new_host := e_deep_copy_host(data.yank.Host)
		if ui.insert_method == INSERT_COPY {
			new_host.Name += " (copy)"
		} else if ui.insert_method == INSERT_MOVE && data.litems.curr != nil &&
				  data.litems.curr.path_node() == data.yank.path_node() {
			data.yank = nil
			return true
		}
		if data.litems.curr.is_dir() == true {
			new_host.parent = data.litems.curr.Dirs
			if data.folds[data.litems.curr.Dirs] != nil {
				e_unfold_dir(data, data.litems.curr)
			}
		} else {
			new_host.parent = data.litems.curr.Host.parent
		}
		if err := i_insert_host(data, &new_host); err != nil {
			return true
		}
		if ui.insert_method == INSERT_MOVE {
			data.litems.del(data.yank)
			file_path := data.data_dir + data.yank.Host.parent.path() +
						 data.yank.Host.filename
			if err := os.Remove(file_path); err != nil {
				c_error_mode("can't remove " + file_path, err, &data.ui)
				return true
			}
		}
		data.yank = nil
		ui.msg_buff = "pasted " + new_host.Name
	} else if (event.Rune() == 'c' ||
			   event.Rune() == 'C' ||
			   event.Rune() == 'A') &&
			  data.litems.curr != nil {
		ui.mode = RENAME_MODE
		if data.litems.curr.is_dir() == false {
			ui.buff = data.litems.curr.Host.Name
		} else {
			ui.buff = data.litems.curr.Dirs.Name
		}
	} else if event.Rune() == '?' {
		ui.mode = HELP_MODE
		ui.help_scroll = 0
	}
	return false
}

func e_delete_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
	if event.Key() == tcell.KeyEscape ||
	   event.Key() == tcell.KeyCtrlC ||
	   event.Rune() == 'n' {
		ui.mode = NORMAL_MODE
	} else if event.Key() == tcell.KeyEnter ||
			  event.Rune() == 'y' {
		if data.yank == data.litems.curr {
			data.yank = nil
		}
		if err := e_delete_host(data); err == nil {
			ui.mode = NORMAL_MODE
			return true
		}
	}
	return false
}

func e_load_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
	return true
}

func e_error_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
	if event.Rune() != 0 ||
	   event.Key() == tcell.KeyEscape ||
	   event.Key() == tcell.KeyEnter {
		ui.mode = NORMAL_MODE
		data.load_err = nil
	}
	return false
}

func e_welcome_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
	if event.Key() == tcell.KeyEscape ||
	   event.Key() == tcell.KeyCtrlC {
		ui.s.Fini()
		os.Exit(0)
	}
	if len(data.opts.GPG) == 0 {
		if event.Rune() < '1' || event.Rune() > '9' {
			return true
		} else {
			data.opts.GPG = data.keys[event.Rune() - 48 - 1][0]
			ui.s.HideCursor()
		}
	} else {
		if event.Rune() == 'y' {
			ui.mode = NORMAL_MODE
			c_write_options(data.opts.file, data.opts, &data.load_err)
		} else if event.Rune() == 'n' {
			data.opts.GPG = ""
		}
	}
	return false
}

func e_mkdir_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
	if event.Key() == tcell.KeyEscape ||
	   event.Key() == tcell.KeyCtrlC {
		ui.s.HideCursor()
		ui.mode = NORMAL_MODE
		ui.buff = ""
		data.insert = nil
	} else if event.Key() == tcell.KeyEnter {
		e_mkdir(data, ui)
		ui.s.HideCursor()
		ui.mode = NORMAL_MODE
		ui.buff = ""
	} else {
		e_readline(event, &ui.buff)
	}
	return false
}

func e_insert_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
	if data.insert == nil {
		if event.Key() == tcell.KeyEscape ||
		event.Key() == tcell.KeyCtrlC {
			ui.s.HideCursor()
			ui.mode = NORMAL_MODE
			ui.insert_sel = 0
			data.insert = nil
			ui.buff = ""
		} else if event.Key() == tcell.KeyEnter {
			if ui.buff == "" {
				ui.s.HideCursor()
				ui.mode = NORMAL_MODE
				ui.insert_sel = 0
				ui.insert_sel_ok = false
				data.insert = nil
				ui.buff = ""
				return true
			}
			ui.s.HideCursor()
			data.insert = &HostNode{}
			e_set_protocol_defaults(data, data.insert)
			data.insert.Name = ui.buff
			ui.buff = ""
			if data.litems.curr != nil {
				data.insert.parent = data.litems.curr.path_node()
			} else {
				data.insert.parent = data.ldirs.head
			}
		} else {
			e_readline(event, &ui.buff)
		}
	} else if data.insert != nil {
		if data.insert_err != nil {
			if event.Rune() != 0 ||
			   event.Key() == tcell.KeyEscape ||
			   event.Key() == tcell.KeyEnter {
				data.insert_err = nil
			}
		} else if ui.insert_sel_ok == false {
			if event.Key() == tcell.KeyEscape ||
			   event.Key() == tcell.KeyCtrlC ||
			   event.Rune() == 'q' {
				ui.s.HideCursor()
				ui.mode = NORMAL_MODE
				ui.insert_sel = 0
				data.insert = nil
				ui.buff = ""
			} else if event.Rune() == 'j' ||
					  event.Key() == tcell.KeyDown ||
					  event.Key() == tcell.KeyTab {
				if data.insert.Protocol == PROTOCOL_RDP &&
				   ui.insert_sel == INS_PROTOCOL {
					ui.insert_sel = INS_RDP_HOST
				} else if data.insert.Protocol == PROTOCOL_RDP &&
						  ui.insert_sel == INS_RDP_JUMP_HOST +
							len(data.insert.Drive) &&
						  len(data.insert.Jump.Host) == 0 {
					ui.insert_sel = INS_RDP_NOTE + len(data.insert.Drive)
				} else if data.insert.Protocol == PROTOCOL_CMD &&
						  ui.insert_sel == INS_PROTOCOL {
					ui.insert_sel = INS_CMD_CMD
				} else if data.insert.Protocol == PROTOCOL_OS &&
						  ui.insert_sel == INS_PROTOCOL {
					ui.insert_sel = INS_OS_HOST
				} else if data.insert.Protocol == PROTOCOL_SSH &&
						  ui.insert_sel == INS_SSH_JUMP_HOST &&
						  len(data.insert.Jump.Host) == 0 {
					ui.insert_sel = INS_SSH_NOTE
				} else if ui.insert_sel < ui.insert_sel_max {
					ui.insert_sel += 1
				}
				if ui.insert_butt == false {
					ui.insert_scroll += 2
				}
			} else if event.Rune() == 'k' ||
					  event.Key() == tcell.KeyUp {
				if data.insert.Protocol == PROTOCOL_RDP &&
				   ui.insert_sel == INS_RDP_HOST {
					ui.insert_sel = INS_PROTOCOL
				} else if data.insert.Protocol == PROTOCOL_RDP &&
						  ui.insert_sel == INS_RDP_NOTE +
							len(data.insert.Drive) &&
						  len(data.insert.Jump.Host) == 0 {
					ui.insert_sel = INS_RDP_JUMP_HOST + len(data.insert.Drive)
				} else if data.insert.Protocol == PROTOCOL_CMD &&
						  ui.insert_sel == INS_CMD_CMD {
					ui.insert_sel = INS_PROTOCOL
				} else if data.insert.Protocol == PROTOCOL_OS &&
						  ui.insert_sel == INS_OS_HOST {
					ui.insert_sel = INS_PROTOCOL
				} else if data.insert.Protocol == PROTOCOL_SSH &&
						  ui.insert_sel == INS_SSH_NOTE &&
						  len(data.insert.Jump.Host) == 0 {
					ui.insert_sel = INS_SSH_JUMP_HOST
				} else if ui.insert_sel > INS_PROTOCOL {
					ui.insert_sel -= 1
				}
				if ui.insert_scroll > 0 {
					ui.insert_scroll -= 2
					if ui.insert_scroll < 0 {
						ui.insert_scroll = 0
					}
				}
			} else if event.Rune() == 'g' ||
					  event.Rune() == 'h' ||
					  event.Key() == tcell.KeyLeft {
				ui.insert_sel = INS_PROTOCOL
				ui.insert_scroll = 0
			} else if event.Rune() == 'G' ||
					  event.Rune() == 'l' ||
					  event.Key() == tcell.KeyRight {
				ui.insert_sel = ui.insert_sel_max
				for data.ui.insert_butt == false {
					ui.insert_scroll += 2
					i_draw_insert_panel(&data.ui, data.insert, data.home_dir)
				}
				data.ui.s.Show()
			} else if event.Rune() == 'i' ||
					  event.Rune() == 'a' ||
					  event.Rune() == ' ' ||
					  event.Key() == tcell.KeyEnter {
				ui.insert_sel_ok = true
				switch ui.insert_sel {
				case INS_SSH_OK,
					 INS_RDP_OK + len(data.insert.Drive),
					 INS_CMD_OK,
					 INS_OS_OK:
					ui.insert_sel_ok = false
					i_insert_check_ok(data, data.insert)
					if data.insert_err != nil {
						return true
					}
					i_insert_host(data, data.insert)
				case INS_SSH_HOST,
					 INS_RDP_HOST,
					 INS_OS_HOST:
					ui.buff = data.insert.Host
				case INS_SSH_PORT,
					 INS_RDP_PORT:
					if data.insert.Port > 0 {
						ui.buff = strconv.Itoa(int(data.insert.Port))
					}
				case INS_SSH_USER,
					 INS_RDP_USER,
					 INS_OS_USER:
					ui.buff = data.insert.User
				case INS_SSH_PASS,
					 INS_RDP_PASS,
					 INS_OS_PASS:
					return true
				case INS_SSH_PRIV: ui.buff = data.insert.Priv
				case INS_SSH_EXEC: ui.buff = data.insert.Exec
				case INS_SSH_JUMP_HOST,
					 INS_RDP_JUMP_HOST + len(data.insert.Drive):
					ui.buff = data.insert.Jump.Host
				case INS_SSH_JUMP_PORT,
					 INS_RDP_JUMP_PORT + len(data.insert.Drive):
					if data.insert.Jump.Port > 0 {
						ui.buff = strconv.Itoa(int(
						data.insert.Jump.Port))
					}
				case INS_SSH_JUMP_USER,
					 INS_RDP_JUMP_USER + len(data.insert.Drive):
					ui.buff = data.insert.Jump.User
				case INS_SSH_JUMP_PASS,
					 INS_RDP_JUMP_PASS + len(data.insert.Drive):
					return true
				case INS_SSH_JUMP_PRIV,
					 INS_RDP_JUMP_PRIV + len(data.insert.Drive):
					ui.buff = data.insert.Jump.Priv
				case INS_RDP_DOMAIN: ui.buff = data.insert.Domain
				case INS_RDP_FILE: ui.buff = data.insert.RDPFile
				case INS_RDP_SCREENSIZE: return true
				case INS_RDP_DYNAMIC:
					ui.insert_sel_ok = false
					if data.insert.Dynamic == true {
						data.insert.Dynamic = false
					} else {
						data.insert.Dynamic = true
					}
					return true
				case INS_RDP_FULLSCR:
					ui.insert_sel_ok = false
					if data.insert.FullScr == true {
						data.insert.FullScr = false
					} else {
						data.insert.FullScr = true
					}
					return true
				case INS_RDP_MULTIMON:
					ui.insert_sel_ok = false
					if data.insert.MultiMon == true {
						data.insert.MultiMon = false
					} else {
						data.insert.MultiMon = true
					}
					return true
				case INS_RDP_QUALITY: return true
				case INS_RDP_DRIVE + len(data.insert.Drive): return true
				case INS_CMD_CMD: ui.buff = data.insert.Host
				case INS_CMD_SHELL: ui.buff = data.insert.Shell[0]
				case INS_CMD_SILENT:
					ui.insert_sel_ok = false
					if data.insert.Silent == true {
						data.insert.Silent = false
					} else {
						data.insert.Silent = true
					}
					return true
				case INS_OS_USERDOMAINID:
					ui.buff = data.insert.Stack.UserDomainID
				case INS_OS_PROJECTID:
					ui.buff = data.insert.Stack.ProjectID
				case INS_OS_REGION:
					ui.buff = data.insert.Stack.RegionName
				case INS_OS_ENDTYPE:
					ui.buff = data.insert.Stack.EndpointType
				case INS_OS_INTERFACE:
					ui.buff = data.insert.Stack.Interface
				case INS_OS_IDAPI:
					ui.buff = data.insert.Stack.IdentityAPI
				case INS_OS_IMGAPI:
					ui.buff = data.insert.Stack.ImageAPI
				case INS_OS_NETAPI:
					ui.buff = data.insert.Stack.NetworkAPI
				case INS_OS_VOLAPI:
					ui.buff = data.insert.Stack.VolumeAPI
				case INS_SSH_NOTE,
					 INS_RDP_NOTE + len(data.insert.Drive),
					 INS_CMD_NOTE,
					 INS_OS_NOTE:
					ui.buff = data.insert.Note
				}
			}
		} else {
			if event.Key() == tcell.KeyEscape ||
			   event.Key() == tcell.KeyCtrlC {
				ui.insert_sel_ok = false
				ui.buff = ""
				ui.drives_buff = ""
				ui.s.HideCursor()
			}
			if len(data.insert.Drive) > 0 &&
			   (ui.insert_sel >= INS_RDP_DRIVE &&
			   ui.insert_sel < INS_RDP_DRIVE +
			   len(data.insert.Drive)) {
				if event.Rune() == 'y' ||
				event.Rune() == 'Y' ||
				event.Key() == tcell.KeyEnter {
					delete(data.insert.Drive,
						   data.insert.drive_keys[
						   ui.insert_sel - INS_RDP_DRIVE])
					if len(data.insert.Drive) == 0 {
						data.insert.Drive = nil
					}
					e_set_drive_keys(data)
				}
				ui.insert_sel_ok = false
				return true
			}
			switch ui.insert_sel {
			case INS_PROTOCOL:
				if event.Rune() < '1' || event.Rune() > '4' {
					ui.insert_sel_ok = false
					ui.buff = ""
					ui.s.HideCursor()
					return true
				} else {
					filename := data.insert.filename
					name := data.insert.Name
					parent := data.insert.parent
					data.insert = nil
					data.insert = &HostNode{}
					data.insert.Name = name
					data.insert.parent = parent
					data.insert.filename = filename
					data.insert.Protocol = int8(event.Rune() - 48 - 1)
					ui.insert_sel_ok = false
					ui.s.HideCursor()
					e_set_protocol_defaults(data, data.insert)
				}
			case INS_RDP_SCREENSIZE:
				if event.Rune() < '1' || event.Rune() > '7' {
					ui.insert_sel_ok = false
					ui.buff = ""
					ui.s.HideCursor()
					return true
				} else {
					s := strings.Split(
						RDP_SCREENSIZE[uint8(event.Rune() - 48 - 1)],
						"x")
					if len(s) != 2 {
						return true
					}
					tmp, _ := strconv.Atoi(s[W])
					data.insert.Width = uint16(tmp)
					tmp, _ = strconv.Atoi(s[H])
					data.insert.Height = uint16(tmp)
					ui.insert_sel_ok = false
					ui.s.HideCursor()
				}
			case INS_RDP_QUALITY:
				if event.Rune() < '1' || event.Rune() > '3' {
					ui.insert_sel_ok = false
					ui.buff = ""
					ui.s.HideCursor()
					return true
				} else {
					data.insert.Quality = uint8(event.Rune() - 48 - 1)
					ui.insert_sel_ok = false
					ui.s.HideCursor()
				}
			case INS_RDP_DRIVE + len(data.insert.Drive):
				if len(ui.drives_buff) == 0 {
					if event.Key() == tcell.KeyEnter {
						if len(ui.buff) == 0 {
							ui.insert_sel_ok = false
							ui.drives_buff = ""
							ui.buff = ""
							ui.s.HideCursor()
							return true
						}
						ui.drives_buff = ui.buff
						ui.buff = ""
					} else {
						e_readline(event, &ui.buff)
					}
				} else {
					if event.Key() == tcell.KeyEnter {
						if len(ui.buff) == 0 {
							ui.insert_sel_ok = false
							ui.drives_buff = ""
							ui.buff = ""
							ui.s.HideCursor()
							return true
						}
						if len(data.insert.Drive) == 0 {
							data.insert.Drive = make(map[string]string)
						}
						data.insert.Drive[ui.drives_buff] = ui.buff
						e_set_drive_keys(data)
						ui.insert_sel_ok = false
						ui.drives_buff = ""
						ui.buff = ""
						ui.s.HideCursor()
					} else {
						e_readline(event, &ui.buff)
					}
				}
			case INS_SSH_HOST,
				 INS_SSH_PORT,
				 INS_SSH_USER,
				 INS_SSH_PASS,
				 INS_SSH_PRIV,
				 INS_SSH_EXEC,
				 INS_SSH_JUMP_HOST,
				 INS_SSH_JUMP_PORT,
				 INS_SSH_JUMP_USER,
				 INS_SSH_JUMP_PASS,
				 INS_SSH_JUMP_PRIV,
				 INS_RDP_JUMP_HOST + len(data.insert.Drive),
				 INS_RDP_JUMP_PORT + len(data.insert.Drive),
				 INS_RDP_JUMP_USER + len(data.insert.Drive),
				 INS_RDP_JUMP_PASS + len(data.insert.Drive),
				 INS_RDP_JUMP_PRIV + len(data.insert.Drive),
				 INS_SSH_NOTE,
				 INS_RDP_HOST,
				 INS_RDP_PORT,
				 INS_RDP_DOMAIN,
				 INS_RDP_USER,
				 INS_RDP_PASS,
				 INS_RDP_FILE,
				 INS_RDP_NOTE + len(data.insert.Drive),
				 INS_CMD_CMD,
				 INS_CMD_SHELL,
				 INS_CMD_NOTE,
				 INS_OS_HOST,
				 INS_OS_USER,
				 INS_OS_PASS,
				 INS_OS_USERDOMAINID,
				 INS_OS_PROJECTID,
				 INS_OS_REGION,
				 INS_OS_ENDTYPE,
				 INS_OS_INTERFACE,
				 INS_OS_IDAPI,
				 INS_OS_IMGAPI,
				 INS_OS_NETAPI,
				 INS_OS_VOLAPI,
				 INS_OS_NOTE:
				if event.Key() == tcell.KeyEnter {
					switch ui.insert_sel {
					case INS_SSH_HOST,
						 INS_RDP_HOST,
						 INS_OS_HOST:
						data.insert.Host = ui.buff
					case INS_SSH_PORT,
						 INS_RDP_PORT:
						tmp, _ := strconv.Atoi(ui.buff)
						data.insert.Port = uint16(tmp)
					case INS_SSH_USER,
						 INS_RDP_USER,
						 INS_OS_USER:
						data.insert.User = ui.buff
					case INS_SSH_PASS,
						 INS_RDP_PASS,
						 INS_OS_PASS:
						if len(ui.buff) == 0 {
							data.insert.Pass = ""
							return true
						} else {
							data.insert.Pass, _ = c_encrypt_str(ui.buff,
													data.opts.GPG)
						}
					case INS_SSH_PRIV: data.insert.Priv = ui.buff
					case INS_SSH_EXEC: data.insert.Exec = ui.buff
					case INS_SSH_JUMP_HOST,
						 INS_RDP_JUMP_HOST + len(data.insert.Drive):
						data.insert.Jump.Host = ui.buff
						if len(ui.buff) > 0 {
							data.insert.Jump.Port = 22
						} else {
							data.insert.Jump.Port = 0
						}
					case INS_SSH_JUMP_PORT,
						 INS_RDP_JUMP_PORT + len(data.insert.Drive):
						tmp, _ := strconv.Atoi(ui.buff)
						data.insert.Jump.Port = uint16(tmp)
					case INS_SSH_JUMP_USER,
						 INS_RDP_JUMP_USER + len(data.insert.Drive):
						data.insert.Jump.User = ui.buff
					case INS_SSH_JUMP_PASS,
						 INS_RDP_JUMP_PASS + len(data.insert.Drive):
						if len(ui.buff) == 0 {
							data.insert.Jump.Pass = ""
						} else {
							data.insert.Jump.Pass, _ = c_encrypt_str(ui.buff,
														data.opts.GPG)
						}
					case INS_SSH_JUMP_PRIV,
						 INS_RDP_JUMP_PRIV + len(data.insert.Drive):
						data.insert.Jump.Priv = ui.buff
					case INS_RDP_DOMAIN:
						data.insert.Domain = ui.buff
					case INS_RDP_FILE:
						data.insert.RDPFile = ui.buff
					case INS_CMD_CMD:
						data.insert.Host = ui.buff
					case INS_CMD_SHELL:
						data.insert.Shell[0] = ui.buff
					case INS_OS_USERDOMAINID:
						data.insert.Stack.UserDomainID = ui.buff
					case INS_OS_PROJECTID:
						data.insert.Stack.ProjectID = ui.buff
					case INS_OS_REGION:
						data.insert.Stack.RegionName = ui.buff
					case INS_OS_ENDTYPE:
						data.insert.Stack.EndpointType = ui.buff
					case INS_OS_INTERFACE:
						data.insert.Stack.Interface = ui.buff
					case INS_OS_IDAPI:
						data.insert.Stack.IdentityAPI = ui.buff
					case INS_OS_IMGAPI:
						data.insert.Stack.ImageAPI = ui.buff
					case INS_OS_NETAPI:
						data.insert.Stack.NetworkAPI = ui.buff
					case INS_OS_VOLAPI:
						data.insert.Stack.VolumeAPI = ui.buff
					case INS_SSH_NOTE,
						 INS_RDP_NOTE + len(data.insert.Drive),
						 INS_CMD_NOTE,
						 INS_OS_NOTE:
						data.insert.Note = ui.buff
					}
					ui.insert_sel_ok = false
					ui.buff = ""
					ui.s.HideCursor()
				} else {
					e_readline(event, &ui.buff)
				}
			}
		}
	}
	return false
}

func e_rename_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
	if event.Key() == tcell.KeyEscape ||
	   event.Key() == tcell.KeyCtrlC {
		data.insert = nil
	} else if event.Key() == tcell.KeyEnter {
		if err := e_rename(data, ui); err != nil {
			ui.s.HideCursor()
			ui.buff = ""
			return true
		}
	} else {
		e_readline(event, &ui.buff)
		return true
	}
	ui.s.HideCursor()
	ui.mode = NORMAL_MODE
	ui.buff = ""
	return false
}

func e_help_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
	if event.Key() == tcell.KeyEscape ||
	   event.Key() == tcell.KeyCtrlC ||
	   event.Rune() == 'q' ||
	   event.Rune() == '?' {
		ui.mode = NORMAL_MODE
		ui.help_scroll = 0
		return true
	} else if event.Rune() == 'j' ||
			  event.Key() == tcell.KeyDown {
		if ui.help_end == true {
			return true
		}
		ui.help_scroll += 1
	} else if event.Rune() == 'k' ||
			  event.Key() == tcell.KeyUp {
		if ui.help_scroll <= 0 {
			ui.help_scroll = 0
			return true
		}
		ui.help_scroll -= 1
	} else if event.Rune() == 'g' {
		ui.help_scroll = 0
	} else if event.Rune() == 'G' {
		for ui.help_end != true {
			ui.help_scroll += 1
			i_draw_help(ui)
		}
	}
	return false
}