Skip to content
Myr

tcell_test.go

This file

Path

src/tui/tcell_test.go

473 lines · 23.3 KiB · Go

Last changed by

Not known.

History of this file

Take it

1//go:build tcell || windows23package tui45import (6	"os"7	"testing"89	"github.com/gdamore/tcell/v2"10	"github.com/junegunn/fzf/src/util"11)1213func assert(t *testing.T, context string, got any, want any) bool {14	if got == want {15		return true16	} else {17		t.Errorf("%s = (%T)%v, want (%T)%v", context, got, got, want, want)18		return false19	}20}2122// Test the handling of the tcell keyboard events.23func TestGetCharEventKey(t *testing.T) {24	if util.IsTty(os.Stdout) {25		// This test is skipped when output goes to terminal, because it causes26		// some glitches:27		// - output lines may not start at the beginning of a row which makes28		//   the output unreadable29		// - terminal may get cleared which prevents you from seeing results of30		//   previous tests31		// Good ways to prevent the glitches are piping the output to a pager32		// or redirecting to a file. I've found `less +G` to be trouble-free.33		t.Skip("Skipped because this test misbehaves in terminal, pipe to a pager or redirect output to a file to run it safely.")34	} else if testing.Verbose() {35		// I have observed a behaviour when this test outputted more than 819236		// bytes (32*256) into the 'less' pager, both the go's test executable37		// and the pager hanged. The go's executable was blocking on printing.38		// I was able to create minimal working example of that behaviour, but39		// that example hanged after 12256 bytes (32*(256+127)).40		t.Log("If you are piping this test to a pager and it hangs, make the pager greedy for input, e.g. 'less +G'.")41	}4243	if !HasFullscreenRenderer() {44		t.Skip("Can't test FullscreenRenderer.")45	}4647	// construct test cases48	type giveKey struct {49		Type tcell.Key50		Char rune51		Mods tcell.ModMask52	}53	type wantKey = Event54	type testCase struct {55		giveKey56		wantKey57	}58	/*59		Some test cases are marked "fabricated". It means that giveKey value60		is valid, but it is not what you get when you press the keys. For61		example Ctrl+C will NOT give you tcell.KeyCtrlC, but tcell.KeyETX62		(End-Of-Text character, causing SIGINT).63		I was trying to accompany the fabricated test cases with real ones.6465		Some test cases are marked "unhandled". It means that giveKey.Type66		is not present in tcell.go source code. It can still be handled via67		implicit or explicit alias.6869		If not said otherwise, test cases are for US keyboard.7071		(tabstop=44)72	*/73	tests := []testCase{7475		// section 1: Ctrl+(Alt)+[a-z]76		{giveKey{tcell.KeyCtrlA, rune(tcell.KeyCtrlA), tcell.ModCtrl}, wantKey{CtrlA, 0, nil}},77		{giveKey{tcell.KeyCtrlC, rune(tcell.KeyCtrlC), tcell.ModCtrl}, wantKey{CtrlC, 0, nil}}, // fabricated78		{giveKey{tcell.KeyETX, rune(tcell.KeyETX), tcell.ModCtrl}, wantKey{CtrlC, 0, nil}},     // this is SIGINT (Ctrl+C)79		{giveKey{tcell.KeyCtrlZ, rune(tcell.KeyCtrlZ), tcell.ModCtrl}, wantKey{CtrlZ, 0, nil}}, // fabricated80		// KeyTab is alias for KeyTAB81		{giveKey{tcell.KeyCtrlI, rune(tcell.KeyCtrlI), tcell.ModCtrl}, wantKey{Tab, 0, nil}}, // fabricated82		{giveKey{tcell.KeyTab, rune(tcell.KeyTab), tcell.ModNone}, wantKey{Tab, 0, nil}},     // unhandled, actual "Tab" keystroke83		{giveKey{tcell.KeyTAB, rune(tcell.KeyTAB), tcell.ModNone}, wantKey{Tab, 0, nil}},     // fabricated, unhandled84		// KeyEnter is alias for KeyCR85		{giveKey{tcell.KeyCtrlM, rune(tcell.KeyCtrlM), tcell.ModNone}, wantKey{Enter, 0, nil}}, // actual "Enter" keystroke86		{giveKey{tcell.KeyCR, rune(tcell.KeyCR), tcell.ModNone}, wantKey{Enter, 0, nil}},       // fabricated, unhandled87		{giveKey{tcell.KeyEnter, rune(tcell.KeyEnter), tcell.ModNone}, wantKey{Enter, 0, nil}}, // fabricated, unhandled88		// Ctrl+Alt keys89		{giveKey{tcell.KeyCtrlA, rune(tcell.KeyCtrlA), tcell.ModCtrl | tcell.ModAlt}, wantKey{CtrlAlt, 'a', nil}},                  // fabricated90		{giveKey{tcell.KeyCtrlA, rune(tcell.KeyCtrlA), tcell.ModCtrl | tcell.ModAlt | tcell.ModShift}, wantKey{CtrlAlt, 'a', nil}}, // fabricated9192		// section 2: Ctrl+[ \]_]93		{giveKey{tcell.KeyCtrlSpace, rune(tcell.KeyCtrlSpace), tcell.ModCtrl}, wantKey{CtrlSpace, 0, nil}}, // fabricated94		{giveKey{tcell.KeyNUL, rune(tcell.KeyNUL), tcell.ModNone}, wantKey{CtrlSpace, 0, nil}},             // fabricated, unhandled95		{giveKey{tcell.KeyRune, ' ', tcell.ModCtrl}, wantKey{CtrlSpace, 0, nil}},                           // actual Ctrl+' '96		{giveKey{tcell.KeyCtrlBackslash, rune(tcell.KeyCtrlBackslash), tcell.ModCtrl}, wantKey{CtrlBackSlash, 0, nil}},97		{giveKey{tcell.KeyCtrlRightSq, rune(tcell.KeyCtrlRightSq), tcell.ModCtrl}, wantKey{CtrlRightBracket, 0, nil}},98		{giveKey{tcell.KeyCtrlCarat, rune(tcell.KeyCtrlCarat), tcell.ModShift | tcell.ModCtrl}, wantKey{CtrlCaret, 0, nil}}, // fabricated99		{giveKey{tcell.KeyRS, rune(tcell.KeyRS), tcell.ModShift | tcell.ModCtrl}, wantKey{CtrlCaret, 0, nil}},               // actual Ctrl+Shift+6 (i.e. Ctrl+^) keystroke100		{giveKey{tcell.KeyCtrlUnderscore, rune(tcell.KeyCtrlUnderscore), tcell.ModShift | tcell.ModCtrl}, wantKey{CtrlSlash, 0, nil}},101102		// section 3: (Alt)+Backspace2103		// KeyBackspace2 is alias for KeyDEL = 0x7F (ASCII) (allegedly unused by Windows)104		// KeyDelete = 0x2E (VK_DELETE constant in Windows)105		// KeyBackspace is alias for KeyBS = 0x08 (ASCII) (implicit alias with KeyCtrlH)106		{giveKey{tcell.KeyBackspace2, 0, tcell.ModNone}, wantKey{Backspace, 0, nil}},   // fabricated107		{giveKey{tcell.KeyBackspace2, 0, tcell.ModAlt}, wantKey{AltBackspace, 0, nil}}, // fabricated108		{giveKey{tcell.KeyDEL, 0, tcell.ModNone}, wantKey{Backspace, 0, nil}},          // fabricated, unhandled109		{giveKey{tcell.KeyDelete, 0, tcell.ModNone}, wantKey{Delete, 0, nil}},110		{giveKey{tcell.KeyDelete, 0, tcell.ModAlt}, wantKey{AltDelete, 0, nil}},111		{giveKey{tcell.KeyBackspace, 0, tcell.ModCtrl}, wantKey{CtrlBackspace, 0, nil}},112		{giveKey{tcell.KeyBackspace, 0, tcell.ModCtrl | tcell.ModAlt}, wantKey{CtrlAltBackspace, 0, nil}},113		{giveKey{tcell.KeyBackspace, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}},                                                  // fabricated, unhandled114		{giveKey{tcell.KeyBS, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}},                                                         // fabricated, unhandled115		{giveKey{tcell.KeyCtrlH, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}},                                                      // fabricated, unhandled116		{giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModNone}, wantKey{Backspace, 0, nil}},                                 // actual "Backspace" keystroke117		{giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModAlt}, wantKey{AltBackspace, 0, nil}},                               // actual "Alt+Backspace" keystroke118		{giveKey{tcell.KeyDEL, rune(tcell.KeyDEL), tcell.ModCtrl}, wantKey{CtrlBackspace, 0, nil}},                                 // actual "Ctrl+Backspace" keystroke119		{giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModShift}, wantKey{Backspace, 0, nil}},                                // actual "Shift+Backspace" keystroke120		{giveKey{tcell.KeyCtrlH, 0, tcell.ModCtrl | tcell.ModAlt}, wantKey{CtrlAltBackspace, 0, nil}},                              // actual "Ctrl+Alt+Backspace" keystroke121		{giveKey{tcell.KeyCtrlH, 0, tcell.ModCtrl | tcell.ModShift}, wantKey{CtrlBackspace, 0, nil}},                               // actual "Ctrl+Shift+Backspace" keystroke122		{giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModShift | tcell.ModAlt}, wantKey{AltBackspace, 0, nil}},              // actual "Shift+Alt+Backspace" keystroke123		{giveKey{tcell.KeyCtrlH, 0, tcell.ModCtrl | tcell.ModAlt | tcell.ModShift}, wantKey{CtrlAltBackspace, 0, nil}},             // actual "Ctrl+Shift+Alt+Backspace" keystroke124		{giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModCtrl}, wantKey{CtrlH, 0, nil}},                                     // actual "Ctrl+H" keystroke125		{giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModCtrl | tcell.ModAlt}, wantKey{CtrlAlt, 'h', nil}},                  // fabricated "Ctrl+Alt+H" keystroke126		{giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModCtrl | tcell.ModShift}, wantKey{CtrlH, 0, nil}},                    // actual "Ctrl+Shift+H" keystroke127		{giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModCtrl | tcell.ModAlt | tcell.ModShift}, wantKey{CtrlAlt, 'h', nil}}, // fabricated "Ctrl+Shift+Alt+H" keystroke128129		// section 4: (Alt+Shift)+Key(Up|Down|Left|Right)130		{giveKey{tcell.KeyUp, 0, tcell.ModNone}, wantKey{Up, 0, nil}},131		{giveKey{tcell.KeyDown, 0, tcell.ModNone}, wantKey{Down, 0, nil}},132		{giveKey{tcell.KeyLeft, 0, tcell.ModNone}, wantKey{Left, 0, nil}},133		{giveKey{tcell.KeyRight, 0, tcell.ModNone}, wantKey{Right, 0, nil}},134		{giveKey{tcell.KeyUp, 0, tcell.ModNone}, wantKey{Up, 0, nil}},135		{giveKey{tcell.KeyDown, 0, tcell.ModNone}, wantKey{Down, 0, nil}},136		{giveKey{tcell.KeyRight, 0, tcell.ModNone}, wantKey{Right, 0, nil}},137		{giveKey{tcell.KeyLeft, 0, tcell.ModNone}, wantKey{Left, 0, nil}},138		{giveKey{tcell.KeyUp, 0, tcell.ModCtrl}, wantKey{CtrlUp, 0, nil}},139		{giveKey{tcell.KeyDown, 0, tcell.ModCtrl}, wantKey{CtrlDown, 0, nil}},140		{giveKey{tcell.KeyRight, 0, tcell.ModCtrl}, wantKey{CtrlRight, 0, nil}},141		{giveKey{tcell.KeyLeft, 0, tcell.ModCtrl}, wantKey{CtrlLeft, 0, nil}},142		{giveKey{tcell.KeyUp, 0, tcell.ModShift}, wantKey{ShiftUp, 0, nil}},143		{giveKey{tcell.KeyDown, 0, tcell.ModShift}, wantKey{ShiftDown, 0, nil}},144		{giveKey{tcell.KeyRight, 0, tcell.ModShift}, wantKey{ShiftRight, 0, nil}},145		{giveKey{tcell.KeyLeft, 0, tcell.ModShift}, wantKey{ShiftLeft, 0, nil}},146		{giveKey{tcell.KeyUp, 0, tcell.ModAlt}, wantKey{AltUp, 0, nil}},147		{giveKey{tcell.KeyDown, 0, tcell.ModAlt}, wantKey{AltDown, 0, nil}},148		{giveKey{tcell.KeyRight, 0, tcell.ModAlt}, wantKey{AltRight, 0, nil}},149		{giveKey{tcell.KeyLeft, 0, tcell.ModAlt}, wantKey{AltLeft, 0, nil}},150		{giveKey{tcell.KeyUp, 0, tcell.ModCtrl | tcell.ModShift}, wantKey{CtrlShiftUp, 0, nil}},151		{giveKey{tcell.KeyDown, 0, tcell.ModCtrl | tcell.ModShift}, wantKey{CtrlShiftDown, 0, nil}},152		{giveKey{tcell.KeyRight, 0, tcell.ModCtrl | tcell.ModShift}, wantKey{CtrlShiftRight, 0, nil}},153		{giveKey{tcell.KeyLeft, 0, tcell.ModCtrl | tcell.ModShift}, wantKey{CtrlShiftLeft, 0, nil}},154		{giveKey{tcell.KeyUp, 0, tcell.ModCtrl | tcell.ModAlt}, wantKey{CtrlAltUp, 0, nil}},155		{giveKey{tcell.KeyDown, 0, tcell.ModCtrl | tcell.ModAlt}, wantKey{CtrlAltDown, 0, nil}},156		{giveKey{tcell.KeyRight, 0, tcell.ModCtrl | tcell.ModAlt}, wantKey{CtrlAltRight, 0, nil}},157		{giveKey{tcell.KeyLeft, 0, tcell.ModCtrl | tcell.ModAlt}, wantKey{CtrlAltLeft, 0, nil}},158		{giveKey{tcell.KeyUp, 0, tcell.ModShift | tcell.ModAlt}, wantKey{AltShiftUp, 0, nil}},159		{giveKey{tcell.KeyDown, 0, tcell.ModShift | tcell.ModAlt}, wantKey{AltShiftDown, 0, nil}},160		{giveKey{tcell.KeyRight, 0, tcell.ModShift | tcell.ModAlt}, wantKey{AltShiftRight, 0, nil}},161		{giveKey{tcell.KeyLeft, 0, tcell.ModShift | tcell.ModAlt}, wantKey{AltShiftLeft, 0, nil}},162		{giveKey{tcell.KeyUp, 0, tcell.ModCtrl | tcell.ModShift | tcell.ModAlt}, wantKey{CtrlAltShiftUp, 0, nil}},163		{giveKey{tcell.KeyDown, 0, tcell.ModCtrl | tcell.ModShift | tcell.ModAlt}, wantKey{CtrlAltShiftDown, 0, nil}},164		{giveKey{tcell.KeyRight, 0, tcell.ModCtrl | tcell.ModShift | tcell.ModAlt}, wantKey{CtrlAltShiftRight, 0, nil}},165		{giveKey{tcell.KeyLeft, 0, tcell.ModCtrl | tcell.ModShift | tcell.ModAlt}, wantKey{CtrlAltShiftLeft, 0, nil}},166		{giveKey{tcell.KeyUpLeft, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}},    // fabricated, unhandled167		{giveKey{tcell.KeyUpRight, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}},   // fabricated, unhandled168		{giveKey{tcell.KeyDownLeft, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}},  // fabricated, unhandled169		{giveKey{tcell.KeyDownRight, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}}, // fabricated, unhandled170		{giveKey{tcell.KeyCenter, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}},    // fabricated, unhandled171		// section 5: (Insert|Home|Delete|End|PgUp|PgDn|BackTab|F1-F12)172		{giveKey{tcell.KeyInsert, 0, tcell.ModNone}, wantKey{Insert, 0, nil}},173		{giveKey{tcell.KeyF1, 0, tcell.ModNone}, wantKey{F1, 0, nil}},174		{giveKey{tcell.KeyHome, 0, tcell.ModNone}, wantKey{Home, 0, nil}},175		{giveKey{tcell.KeyEnd, 0, tcell.ModNone}, wantKey{End, 0, nil}},176		{giveKey{tcell.KeyDelete, 0, tcell.ModNone}, wantKey{Delete, 0, nil}},177		{giveKey{tcell.KeyPgUp, 0, tcell.ModNone}, wantKey{PageUp, 0, nil}},178		{giveKey{tcell.KeyPgDn, 0, tcell.ModNone}, wantKey{PageDown, 0, nil}},179		{giveKey{tcell.KeyHome, 0, tcell.ModCtrl}, wantKey{CtrlHome, 0, nil}},180		{giveKey{tcell.KeyEnd, 0, tcell.ModCtrl}, wantKey{CtrlEnd, 0, nil}},181		{giveKey{tcell.KeyDelete, 0, tcell.ModCtrl}, wantKey{CtrlDelete, 0, nil}},182		{giveKey{tcell.KeyPgUp, 0, tcell.ModCtrl}, wantKey{CtrlPageUp, 0, nil}},183		{giveKey{tcell.KeyPgDn, 0, tcell.ModCtrl}, wantKey{CtrlPageDown, 0, nil}},184		{giveKey{tcell.KeyHome, 0, tcell.ModShift}, wantKey{ShiftHome, 0, nil}},185		{giveKey{tcell.KeyEnd, 0, tcell.ModShift}, wantKey{ShiftEnd, 0, nil}},186		{giveKey{tcell.KeyDelete, 0, tcell.ModShift}, wantKey{ShiftDelete, 0, nil}},187		{giveKey{tcell.KeyPgUp, 0, tcell.ModShift}, wantKey{ShiftPageUp, 0, nil}},188		{giveKey{tcell.KeyPgDn, 0, tcell.ModShift}, wantKey{ShiftPageDown, 0, nil}},189		{giveKey{tcell.KeyHome, 0, tcell.ModAlt}, wantKey{AltHome, 0, nil}},190		{giveKey{tcell.KeyEnd, 0, tcell.ModAlt}, wantKey{AltEnd, 0, nil}},191		{giveKey{tcell.KeyDelete, 0, tcell.ModAlt}, wantKey{AltDelete, 0, nil}},192		{giveKey{tcell.KeyPgUp, 0, tcell.ModAlt}, wantKey{AltPageUp, 0, nil}},193		{giveKey{tcell.KeyPgDn, 0, tcell.ModAlt}, wantKey{AltPageDown, 0, nil}},194		{giveKey{tcell.KeyHome, 0, tcell.ModCtrl | tcell.ModShift}, wantKey{CtrlShiftHome, 0, nil}},195		{giveKey{tcell.KeyEnd, 0, tcell.ModCtrl | tcell.ModShift}, wantKey{CtrlShiftEnd, 0, nil}},196		{giveKey{tcell.KeyDelete, 0, tcell.ModCtrl | tcell.ModShift}, wantKey{CtrlShiftDelete, 0, nil}},197		{giveKey{tcell.KeyPgUp, 0, tcell.ModCtrl | tcell.ModShift}, wantKey{CtrlShiftPageUp, 0, nil}},198		{giveKey{tcell.KeyPgDn, 0, tcell.ModCtrl | tcell.ModShift}, wantKey{CtrlShiftPageDown, 0, nil}},199		{giveKey{tcell.KeyHome, 0, tcell.ModCtrl | tcell.ModAlt}, wantKey{CtrlAltHome, 0, nil}},200		{giveKey{tcell.KeyEnd, 0, tcell.ModCtrl | tcell.ModAlt}, wantKey{CtrlAltEnd, 0, nil}},201		{giveKey{tcell.KeyDelete, 0, tcell.ModCtrl | tcell.ModAlt}, wantKey{CtrlAltDelete, 0, nil}},202		{giveKey{tcell.KeyPgUp, 0, tcell.ModCtrl | tcell.ModAlt}, wantKey{CtrlAltPageUp, 0, nil}},203		{giveKey{tcell.KeyPgDn, 0, tcell.ModCtrl | tcell.ModAlt}, wantKey{CtrlAltPageDown, 0, nil}},204		{giveKey{tcell.KeyHome, 0, tcell.ModShift | tcell.ModAlt}, wantKey{AltShiftHome, 0, nil}},205		{giveKey{tcell.KeyEnd, 0, tcell.ModShift | tcell.ModAlt}, wantKey{AltShiftEnd, 0, nil}},206		{giveKey{tcell.KeyDelete, 0, tcell.ModShift | tcell.ModAlt}, wantKey{AltShiftDelete, 0, nil}},207		{giveKey{tcell.KeyPgUp, 0, tcell.ModShift | tcell.ModAlt}, wantKey{AltShiftPageUp, 0, nil}},208		{giveKey{tcell.KeyPgDn, 0, tcell.ModShift | tcell.ModAlt}, wantKey{AltShiftPageDown, 0, nil}},209		{giveKey{tcell.KeyHome, 0, tcell.ModCtrl | tcell.ModShift | tcell.ModAlt}, wantKey{CtrlAltShiftHome, 0, nil}},210		{giveKey{tcell.KeyEnd, 0, tcell.ModCtrl | tcell.ModShift | tcell.ModAlt}, wantKey{CtrlAltShiftEnd, 0, nil}},211		{giveKey{tcell.KeyDelete, 0, tcell.ModCtrl | tcell.ModShift | tcell.ModAlt}, wantKey{CtrlAltShiftDelete, 0, nil}},212		{giveKey{tcell.KeyPgUp, 0, tcell.ModCtrl | tcell.ModShift | tcell.ModAlt}, wantKey{CtrlAltShiftPageUp, 0, nil}},213		{giveKey{tcell.KeyPgDn, 0, tcell.ModCtrl | tcell.ModShift | tcell.ModAlt}, wantKey{CtrlAltShiftPageDown, 0, nil}},214		// section 6: (Ctrl+Alt)+'rune'215		{giveKey{tcell.KeyRune, 'a', tcell.ModNone}, wantKey{Rune, 'a', nil}},216		{giveKey{tcell.KeyRune, 'a', tcell.ModCtrl}, wantKey{Rune, 'a', nil}}, // fabricated217		{giveKey{tcell.KeyRune, 'a', tcell.ModAlt}, wantKey{Alt, 'a', nil}},218		{giveKey{tcell.KeyRune, 'A', tcell.ModAlt}, wantKey{Alt, 'A', nil}},219		{giveKey{tcell.KeyRune, '`', tcell.ModAlt}, wantKey{Alt, '`', nil}},220		/*221			"Input method" in Windows Language options:222			US: "US Keyboard" does not generate any characters (and thus any events) in Ctrl+Alt+[a-z] range223			CS: "Czech keyboard"224			DE: "German keyboard"225226			Note that right Alt is not just `tcell.ModAlt` on foreign language keyboards, but it is the AltGr `tcell.ModCtrl|tcell.ModAlt`.227		*/228		{giveKey{tcell.KeyRune, '{', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, '{', nil}}, // CS: Ctrl+Alt+b = "{" // Note that this does not interfere with CtrlB, since the "b" is replaced with "{" on OS level229		{giveKey{tcell.KeyRune, '$', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, '$', nil}}, // CS: Ctrl+Alt+ů = "$"230		{giveKey{tcell.KeyRune, '~', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, '~', nil}}, // CS: Ctrl+Alt++ = "~"231		{giveKey{tcell.KeyRune, '`', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, '`', nil}}, // CS: Ctrl+Alt+ý,Space = "`" // this is dead key, space is required to emit the char232233		{giveKey{tcell.KeyRune, '{', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, '{', nil}}, // DE: Ctrl+Alt+7 = "{"234		{giveKey{tcell.KeyRune, '@', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, '@', nil}}, // DE: Ctrl+Alt+q = "@"235		{giveKey{tcell.KeyRune, 'µ', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, 'µ', nil}}, // DE: Ctrl+Alt+m = "µ"236237		// section 7: Esc238		// KeyEsc and KeyEscape are aliases for KeyESC239		{giveKey{tcell.KeyEsc, rune(tcell.KeyEsc), tcell.ModNone}, wantKey{Esc, 0, nil}},               // fabricated240		{giveKey{tcell.KeyESC, rune(tcell.KeyESC), tcell.ModNone}, wantKey{Esc, 0, nil}},               // unhandled241		{giveKey{tcell.KeyEscape, rune(tcell.KeyEscape), tcell.ModNone}, wantKey{Esc, 0, nil}},         // fabricated, unhandled242		{giveKey{tcell.KeyESC, rune(tcell.KeyESC), tcell.ModCtrl}, wantKey{Esc, 0, nil}},               // actual Ctrl+[ keystroke243		{giveKey{tcell.KeyCtrlLeftSq, rune(tcell.KeyCtrlLeftSq), tcell.ModCtrl}, wantKey{Esc, 0, nil}}, // fabricated, unhandled244245		// section 8: Invalid246		{giveKey{tcell.KeyRune, 'a', tcell.ModMeta}, wantKey{Rune, 'a', nil}}, // fabricated247		{giveKey{tcell.KeyF24, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}},248		{giveKey{tcell.KeyHelp, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}},   // fabricated, unhandled249		{giveKey{tcell.KeyExit, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}},   // fabricated, unhandled250		{giveKey{tcell.KeyClear, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}},  // unhandled, actual keystroke Numpad_5 with Numlock OFF251		{giveKey{tcell.KeyCancel, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}}, // fabricated, unhandled252		{giveKey{tcell.KeyPrint, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}},  // fabricated, unhandled253		{giveKey{tcell.KeyPause, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}},  // unhandled254255	}256	r := NewFullscreenRenderer(&ColorTheme{}, false, false, 8)257	r.Init()258259	// run and evaluate the tests260	initialResizeAsInvalid := true261	for _, test := range tests {262		// generate key event263		giveEvent := tcell.NewEventKey(test.giveKey.Type, test.giveKey.Char, test.giveKey.Mods)264		_screen.PostEventWait(giveEvent)265		t.Logf("giveEvent = %T{key: %v, ch: %q (%[3]v), mod: %#04b}\n", giveEvent, giveEvent.Key(), giveEvent.Rune(), giveEvent.Modifiers())266267		// process the event in fzf and evaluate the test268		gotEvent := r.GetChar(true)269		// skip Resize events, those are sometimes put in the buffer outside of this test270		if initialResizeAsInvalid && gotEvent.Type == Invalid {271			t.Logf("Resize as Invalid swallowed")272			initialResizeAsInvalid = false273			gotEvent = r.GetChar(true)274		}275		if gotEvent.Type == Resize {276			t.Logf("Resize swallowed")277			gotEvent = r.GetChar(true)278		}279		t.Logf("wantEvent = %T{Type: %v, Char: %q (%[3]v)}\n", test.wantKey, test.wantKey.Type, test.wantKey.Char)280		t.Logf("gotEvent = %T{Type: %v, Char: %q (%[3]v)}\n", gotEvent, gotEvent.Type, gotEvent.Char)281282		assert(t, "r.GetChar(true).Type", gotEvent.Type, test.wantKey.Type)283		assert(t, "r.GetChar(true).Char", gotEvent.Char, test.wantKey.Char)284	}285286	r.Close()287}288289/*290Quick reference291---------------292293(tabstop=18)294(this is not mapping table, it merely puts multiple constants ranges in one table)295296¹) the two columns are each other implicit alias297²) explicit aliases here298299%v	section #	tcell ctrl key¹	tcell ctrl char¹	tcell alias²	tui constants	tcell named keys	tcell mods300--	---------	--------------	---------------	-----------	-------------	----------------	----------3010	2	KeyCtrlSpace	KeyNUL = ^@ 		Rune		ModNone3021	1	KeyCtrlA	KeySOH = ^A		CtrlA		ModShift3032	1	KeyCtrlB	KeySTX = ^B		CtrlB		ModCtrl3043	1	KeyCtrlC	KeyETX = ^C		CtrlC3054	1	KeyCtrlD	KeyEOT = ^D		CtrlD		ModAlt3065	1	KeyCtrlE	KeyENQ = ^E		CtrlE3076	1	KeyCtrlF	KeyACK = ^F		CtrlF3087	1	KeyCtrlG	KeyBEL = ^G		CtrlG3098	1	KeyCtrlH	KeyBS = ^H	KeyBackspace	CtrlH		ModMeta3109	1	KeyCtrlI	KeyTAB = ^I	KeyTab	Tab31110	1	KeyCtrlJ	KeyLF = ^J		CtrlJ31211	1	KeyCtrlK	KeyVT = ^K		CtrlK31312	1	KeyCtrlL	KeyFF = ^L		CtrlL31413	1	KeyCtrlM	KeyCR = ^M	KeyEnter	Enter31514	1	KeyCtrlN	KeySO = ^N		CtrlN31615	1	KeyCtrlO	KeySI = ^O		CtrlO31716	1	KeyCtrlP	KeyDLE = ^P		CtrlP31817	1	KeyCtrlQ	KeyDC1 = ^Q		CtrlQ31918	1	KeyCtrlR	KeyDC2 = ^R		CtrlR32019	1	KeyCtrlS	KeyDC3 = ^S		CtrlS32120	1	KeyCtrlT	KeyDC4 = ^T		CtrlT32221	1	KeyCtrlU	KeyNAK = ^U		CtrlU32322	1	KeyCtrlV	KeySYN = ^V		CtrlV32423	1	KeyCtrlW	KeyETB = ^W		CtrlW32524	1	KeyCtrlX	KeyCAN = ^X		CtrlX32625	1	KeyCtrlY	KeyEM = ^Y		CtrlY32726	1	KeyCtrlZ	KeySUB = ^Z		CtrlZ32827	7	KeyCtrlLeftSq	KeyESC = ^[	KeyEsc, KeyEscape	ESC32928	2	KeyCtrlBackslash	KeyFS = ^\		CtrlSpace33029	2	KeyCtrlRightSq	KeyGS = ^]		CtrlBackSlash33130	2	KeyCtrlCarat	KeyRS = ^^		CtrlRightBracket33231	2	KeyCtrlUnderscore	KeyUS = ^_		CtrlCaret33332					CtrlSlash33433					Invalid33534					Resize33635					Mouse33736					DoubleClick33837					LeftClick33938					RightClick34039					BTab34140					Backspace34241					Del34342					PgUp34443					PgDn34544					Up34645					Down34746					Left34847					Right34948					Home35049					End35150					Insert35251					SUp35352					SDown35453					ShiftLeft35554					SRight35655					F135756					F235857					F335958					F436059					F536160					F636261					F736362					F836463					F936564					F1036665					F1136766					F1236867					Change36968					BackwardEOF37069					AltBackspace37170					AltUp37271					AltDown37372					AltLeft37473					AltRight37574					AltSUp37675					AltSDown37776					AltShiftLeft37877					AltShiftRight37978					Alt38079					CtrlAlt381..382127	3		  KeyDEL	KeyBackspace2383..384256	6					KeyRune385257	4					KeyUp386258	4					KeyDown387259	4					KeyRight388260	4					KeyLeft389261	8					KeyUpLeft390262	8					KeyUpRight391263	8					KeyDownLeft392264	8					KeyDownRight393265	8					KeyCenter394266	5					KeyPgUp395267	5					KeyPgDn396268	5					KeyHome397269	5					KeyEnd398270	5					KeyInsert399271	5					KeyDelete400272	8					KeyHelp401273	8					KeyExit402274	8					KeyClear403275	8		  			KeyCancel404276	8				  	KeyPrint405277	8					KeyPause406278	5					KeyBacktab407279	5					KeyF1408280	5					KeyF2409281	5					KeyF3410282	5					KeyF4411283	5					KeyF5412284	5					KeyF6413285	5					KeyF7414286	5					KeyF8415287	5					KeyF9416288	5					KeyF10417289	5					KeyF11418290	5					KeyF12419291	8					KeyF13420292	8					KeyF14421293	8					KeyF15422294	8					KeyF16423295	8					KeyF17424296	8					KeyF18425297	8					KeyF19426298	8					KeyF20427299	8					KeyF21428300	8					KeyF22429301	8					KeyF23430302	8					KeyF24431303	8					KeyF25432304	8					KeyF26433305	8					KeyF27434306	8					KeyF28435307	8					KeyF29436308	8					KeyF30437309	8					KeyF31438310	8					KeyF32439311	8					KeyF33440312	8					KeyF34441313	8					KeyF35442314	8					KeyF36443315	8					KeyF37444316	8					KeyF38445317	8					KeyF39446318	8					KeyF40447319	8					KeyF41448320	8					KeyF42449321	8					KeyF43450322	8					KeyF44451323	8					KeyF45452324	8					KeyF46453325	8					KeyF47454326	8					KeyF48455327	8					KeyF49456328	8					KeyF50457329	8					KeyF51458330	8					KeyF52459331	8					KeyF53460332	8					KeyF54461333	8					KeyF55462334	8					KeyF56463335	8					KeyF57464336	8					KeyF58465337	8					KeyF59466338	8					KeyF60467339	8					KeyF61468340	8					KeyF62469341	8					KeyF63470342	8					KeyF64471--	---------	--------------	---------------	-----------	-------------	----------------	----------472%v	section #	tcell ctrl key	tcell ctrl char	tcell alias	tui constants	tcell named keys	tcell mods473*/