diff options
Diffstat (limited to 'vendor/github.com/nsf/termbox-go/collect_terminfo.py')
| -rw-r--r-- | vendor/github.com/nsf/termbox-go/collect_terminfo.py | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/vendor/github.com/nsf/termbox-go/collect_terminfo.py b/vendor/github.com/nsf/termbox-go/collect_terminfo.py new file mode 100644 index 0000000..613a467 --- /dev/null +++ b/vendor/github.com/nsf/termbox-go/collect_terminfo.py | |||
| @@ -0,0 +1,113 @@ | |||
| 1 | #!/usr/bin/env python | ||
| 2 | |||
| 3 | import sys, os, subprocess | ||
| 4 | |||
| 5 | def escaped(s): | ||
| 6 | return repr(s)[1:-1] | ||
| 7 | |||
| 8 | def tput(term, name): | ||
| 9 | try: | ||
| 10 | return subprocess.check_output(['tput', '-T%s' % term, name]).decode() | ||
| 11 | except subprocess.CalledProcessError as e: | ||
| 12 | return e.output.decode() | ||
| 13 | |||
| 14 | |||
| 15 | def w(s): | ||
| 16 | if s == None: | ||
| 17 | return | ||
| 18 | sys.stdout.write(s) | ||
| 19 | |||
| 20 | terminals = { | ||
| 21 | 'xterm' : 'xterm', | ||
| 22 | 'rxvt-256color' : 'rxvt_256color', | ||
| 23 | 'rxvt-unicode' : 'rxvt_unicode', | ||
| 24 | 'linux' : 'linux', | ||
| 25 | 'Eterm' : 'eterm', | ||
| 26 | 'screen' : 'screen' | ||
| 27 | } | ||
| 28 | |||
| 29 | keys = [ | ||
| 30 | "F1", "kf1", | ||
| 31 | "F2", "kf2", | ||
| 32 | "F3", "kf3", | ||
| 33 | "F4", "kf4", | ||
| 34 | "F5", "kf5", | ||
| 35 | "F6", "kf6", | ||
| 36 | "F7", "kf7", | ||
| 37 | "F8", "kf8", | ||
| 38 | "F9", "kf9", | ||
| 39 | "F10", "kf10", | ||
| 40 | "F11", "kf11", | ||
| 41 | "F12", "kf12", | ||
| 42 | "INSERT", "kich1", | ||
| 43 | "DELETE", "kdch1", | ||
| 44 | "HOME", "khome", | ||
| 45 | "END", "kend", | ||
| 46 | "PGUP", "kpp", | ||
| 47 | "PGDN", "knp", | ||
| 48 | "KEY_UP", "kcuu1", | ||
| 49 | "KEY_DOWN", "kcud1", | ||
| 50 | "KEY_LEFT", "kcub1", | ||
| 51 | "KEY_RIGHT", "kcuf1" | ||
| 52 | ] | ||
| 53 | |||
| 54 | funcs = [ | ||
| 55 | "T_ENTER_CA", "smcup", | ||
| 56 | "T_EXIT_CA", "rmcup", | ||
| 57 | "T_SHOW_CURSOR", "cnorm", | ||
| 58 | "T_HIDE_CURSOR", "civis", | ||
| 59 | "T_CLEAR_SCREEN", "clear", | ||
| 60 | "T_SGR0", "sgr0", | ||
| 61 | "T_UNDERLINE", "smul", | ||
| 62 | "T_BOLD", "bold", | ||
| 63 | "T_BLINK", "blink", | ||
| 64 | "T_REVERSE", "rev", | ||
| 65 | "T_ENTER_KEYPAD", "smkx", | ||
| 66 | "T_EXIT_KEYPAD", "rmkx" | ||
| 67 | ] | ||
| 68 | |||
| 69 | def iter_pairs(iterable): | ||
| 70 | iterable = iter(iterable) | ||
| 71 | while True: | ||
| 72 | try: | ||
| 73 | yield (next(iterable), next(iterable)) | ||
| 74 | except StopIteration: | ||
| 75 | return | ||
| 76 | |||
| 77 | def do_term(term, nick): | ||
| 78 | w("// %s\n" % term) | ||
| 79 | w("var %s_keys = []string{\n\t" % nick) | ||
| 80 | for k, v in iter_pairs(keys): | ||
| 81 | w('"') | ||
| 82 | w(escaped(tput(term, v))) | ||
| 83 | w('",') | ||
| 84 | w("\n}\n") | ||
| 85 | w("var %s_funcs = []string{\n\t" % nick) | ||
| 86 | for k,v in iter_pairs(funcs): | ||
| 87 | w('"') | ||
| 88 | if v == "sgr": | ||
| 89 | w("\\033[3%d;4%dm") | ||
| 90 | elif v == "cup": | ||
| 91 | w("\\033[%d;%dH") | ||
| 92 | else: | ||
| 93 | w(escaped(tput(term, v))) | ||
| 94 | w('", ') | ||
| 95 | w("\n}\n\n") | ||
| 96 | |||
| 97 | def do_terms(d): | ||
| 98 | w("var terms = []struct {\n") | ||
| 99 | w("\tname string\n") | ||
| 100 | w("\tkeys []string\n") | ||
| 101 | w("\tfuncs []string\n") | ||
| 102 | w("}{\n") | ||
| 103 | for k, v in d.items(): | ||
| 104 | w('\t{"%s", %s_keys, %s_funcs},\n' % (k, v, v)) | ||
| 105 | w("}\n\n") | ||
| 106 | |||
| 107 | w("// +build !windows\n\npackage termbox\n\n") | ||
| 108 | |||
| 109 | for k,v in terminals.items(): | ||
| 110 | do_term(k, v) | ||
| 111 | |||
| 112 | do_terms(terminals) | ||
| 113 | |||
