Browse Source

vendored deps

Stephen McQuay 2 years ago
parent
commit
9f47b066db
No known key found for this signature in database
71 changed files with 13618 additions and 0 deletions
  1. 26
    0
      vendor/github.com/mattn/go-runewidth/README.mkd
  2. 464
    0
      vendor/github.com/mattn/go-runewidth/runewidth.go
  3. 8
    0
      vendor/github.com/mattn/go-runewidth/runewidth_js.go
  4. 69
    0
      vendor/github.com/mattn/go-runewidth/runewidth_posix.go
  5. 229
    0
      vendor/github.com/mattn/go-runewidth/runewidth_test.go
  6. 24
    0
      vendor/github.com/mattn/go-runewidth/runewidth_windows.go
  7. 4
    0
      vendor/github.com/nsf/termbox-go/AUTHORS
  8. 19
    0
      vendor/github.com/nsf/termbox-go/LICENSE
  9. 25
    0
      vendor/github.com/nsf/termbox-go/README.md
  10. 459
    0
      vendor/github.com/nsf/termbox-go/api.go
  11. 187
    0
      vendor/github.com/nsf/termbox-go/api_common.go
  12. 239
    0
      vendor/github.com/nsf/termbox-go/api_windows.go
  13. 110
    0
      vendor/github.com/nsf/termbox-go/collect_terminfo.py
  14. 39
    0
      vendor/github.com/nsf/termbox-go/syscalls.go
  15. 41
    0
      vendor/github.com/nsf/termbox-go/syscalls_darwin.go
  16. 40
    0
      vendor/github.com/nsf/termbox-go/syscalls_darwin_amd64.go
  17. 39
    0
      vendor/github.com/nsf/termbox-go/syscalls_freebsd.go
  18. 33
    0
      vendor/github.com/nsf/termbox-go/syscalls_linux.go
  19. 39
    0
      vendor/github.com/nsf/termbox-go/syscalls_netbsd.go
  20. 39
    0
      vendor/github.com/nsf/termbox-go/syscalls_openbsd.go
  21. 61
    0
      vendor/github.com/nsf/termbox-go/syscalls_windows.go
  22. 514
    0
      vendor/github.com/nsf/termbox-go/termbox.go
  23. 59
    0
      vendor/github.com/nsf/termbox-go/termbox_common.go
  24. 856
    0
      vendor/github.com/nsf/termbox-go/termbox_windows.go
  25. 221
    0
      vendor/github.com/nsf/termbox-go/terminfo.go
  26. 64
    0
      vendor/github.com/nsf/termbox-go/terminfo_builtin.go
  27. 174
    0
      vendor/github.com/spf13/cobra/LICENSE.txt
  28. 892
    0
      vendor/github.com/spf13/cobra/README.md
  29. 602
    0
      vendor/github.com/spf13/cobra/bash_completions.go
  30. 206
    0
      vendor/github.com/spf13/cobra/bash_completions.md
  31. 140
    0
      vendor/github.com/spf13/cobra/bash_completions_test.go
  32. 171
    0
      vendor/github.com/spf13/cobra/cobra.go
  33. 1188
    0
      vendor/github.com/spf13/cobra/cobra_test.go
  34. 1217
    0
      vendor/github.com/spf13/cobra/command.go
  35. 5
    0
      vendor/github.com/spf13/cobra/command_notwin.go
  36. 114
    0
      vendor/github.com/spf13/cobra/command_test.go
  37. 26
    0
      vendor/github.com/spf13/cobra/command_win.go
  38. 28
    0
      vendor/github.com/spf13/pflag/LICENSE
  39. 256
    0
      vendor/github.com/spf13/pflag/README.md
  40. 97
    0
      vendor/github.com/spf13/pflag/bool.go
  41. 180
    0
      vendor/github.com/spf13/pflag/bool_test.go
  42. 97
    0
      vendor/github.com/spf13/pflag/count.go
  43. 55
    0
      vendor/github.com/spf13/pflag/count_test.go
  44. 86
    0
      vendor/github.com/spf13/pflag/duration.go
  45. 77
    0
      vendor/github.com/spf13/pflag/example_test.go
  46. 29
    0
      vendor/github.com/spf13/pflag/export_test.go
  47. 934
    0
      vendor/github.com/spf13/pflag/flag.go
  48. 913
    0
      vendor/github.com/spf13/pflag/flag_test.go
  49. 91
    0
      vendor/github.com/spf13/pflag/float32.go
  50. 87
    0
      vendor/github.com/spf13/pflag/float64.go
  51. 104
    0
      vendor/github.com/spf13/pflag/golangflag.go
  52. 39
    0
      vendor/github.com/spf13/pflag/golangflag_test.go
  53. 87
    0
      vendor/github.com/spf13/pflag/int.go
  54. 91
    0
      vendor/github.com/spf13/pflag/int32.go
  55. 87
    0
      vendor/github.com/spf13/pflag/int64.go
  56. 91
    0
      vendor/github.com/spf13/pflag/int8.go
  57. 128
    0
      vendor/github.com/spf13/pflag/int_slice.go
  58. 162
    0
      vendor/github.com/spf13/pflag/int_slice_test.go
  59. 96
    0
      vendor/github.com/spf13/pflag/ip.go
  60. 63
    0
      vendor/github.com/spf13/pflag/ip_test.go
  61. 122
    0
      vendor/github.com/spf13/pflag/ipmask.go
  62. 100
    0
      vendor/github.com/spf13/pflag/ipnet.go
  63. 70
    0
      vendor/github.com/spf13/pflag/ipnet_test.go
  64. 82
    0
      vendor/github.com/spf13/pflag/string.go
  65. 111
    0
      vendor/github.com/spf13/pflag/string_slice.go
  66. 161
    0
      vendor/github.com/spf13/pflag/string_slice_test.go
  67. 91
    0
      vendor/github.com/spf13/pflag/uint.go
  68. 89
    0
      vendor/github.com/spf13/pflag/uint16.go
  69. 89
    0
      vendor/github.com/spf13/pflag/uint32.go
  70. 91
    0
      vendor/github.com/spf13/pflag/uint64.go
  71. 91
    0
      vendor/github.com/spf13/pflag/uint8.go

+ 26
- 0
vendor/github.com/mattn/go-runewidth/README.mkd View File

@@ -0,0 +1,26 @@
1
+go-runewidth
2
+============
3
+
4
+[![Build Status](https://travis-ci.org/mattn/go-runewidth.png?branch=master)](https://travis-ci.org/mattn/go-runewidth)
5
+[![Coverage Status](https://coveralls.io/repos/mattn/go-runewidth/badge.png?branch=HEAD)](https://coveralls.io/r/mattn/go-runewidth?branch=HEAD)
6
+[![GoDoc](https://godoc.org/github.com/mattn/go-runewidth?status.svg)](http://godoc.org/github.com/mattn/go-runewidth)
7
+
8
+Provides functions to get fixed width of the character or string.
9
+
10
+Usage
11
+-----
12
+
13
+```go
14
+runewidth.StringWidth("つのだ☆HIRO") == 12
15
+```
16
+
17
+
18
+Author
19
+------
20
+
21
+Yasuhiro Matsumoto
22
+
23
+License
24
+-------
25
+
26
+under the MIT License: http://mattn.mit-license.org/2013

+ 464
- 0
vendor/github.com/mattn/go-runewidth/runewidth.go View File

@@ -0,0 +1,464 @@
1
+package runewidth
2
+
3
+var EastAsianWidth = IsEastAsian()
4
+var DefaultCondition = &Condition{EastAsianWidth}
5
+
6
+type interval struct {
7
+	first rune
8
+	last  rune
9
+}
10
+
11
+var combining = []interval{
12
+	{0x0300, 0x036F}, {0x0483, 0x0486}, {0x0488, 0x0489},
13
+	{0x0591, 0x05BD}, {0x05BF, 0x05BF}, {0x05C1, 0x05C2},
14
+	{0x05C4, 0x05C5}, {0x05C7, 0x05C7}, {0x0600, 0x0603},
15
+	{0x0610, 0x0615}, {0x064B, 0x065E}, {0x0670, 0x0670},
16
+	{0x06D6, 0x06E4}, {0x06E7, 0x06E8}, {0x06EA, 0x06ED},
17
+	{0x070F, 0x070F}, {0x0711, 0x0711}, {0x0730, 0x074A},
18
+	{0x07A6, 0x07B0}, {0x07EB, 0x07F3}, {0x0901, 0x0902},
19
+	{0x093C, 0x093C}, {0x0941, 0x0948}, {0x094D, 0x094D},
20
+	{0x0951, 0x0954}, {0x0962, 0x0963}, {0x0981, 0x0981},
21
+	{0x09BC, 0x09BC}, {0x09C1, 0x09C4}, {0x09CD, 0x09CD},
22
+	{0x09E2, 0x09E3}, {0x0A01, 0x0A02}, {0x0A3C, 0x0A3C},
23
+	{0x0A41, 0x0A42}, {0x0A47, 0x0A48}, {0x0A4B, 0x0A4D},
24
+	{0x0A70, 0x0A71}, {0x0A81, 0x0A82}, {0x0ABC, 0x0ABC},
25
+	{0x0AC1, 0x0AC5}, {0x0AC7, 0x0AC8}, {0x0ACD, 0x0ACD},
26
+	{0x0AE2, 0x0AE3}, {0x0B01, 0x0B01}, {0x0B3C, 0x0B3C},
27
+	{0x0B3F, 0x0B3F}, {0x0B41, 0x0B43}, {0x0B4D, 0x0B4D},
28
+	{0x0B56, 0x0B56}, {0x0B82, 0x0B82}, {0x0BC0, 0x0BC0},
29
+	{0x0BCD, 0x0BCD}, {0x0C3E, 0x0C40}, {0x0C46, 0x0C48},
30
+	{0x0C4A, 0x0C4D}, {0x0C55, 0x0C56}, {0x0CBC, 0x0CBC},
31
+	{0x0CBF, 0x0CBF}, {0x0CC6, 0x0CC6}, {0x0CCC, 0x0CCD},
32
+	{0x0CE2, 0x0CE3}, {0x0D41, 0x0D43}, {0x0D4D, 0x0D4D},
33
+	{0x0DCA, 0x0DCA}, {0x0DD2, 0x0DD4}, {0x0DD6, 0x0DD6},
34
+	{0x0E31, 0x0E31}, {0x0E34, 0x0E3A}, {0x0E47, 0x0E4E},
35
+	{0x0EB1, 0x0EB1}, {0x0EB4, 0x0EB9}, {0x0EBB, 0x0EBC},
36
+	{0x0EC8, 0x0ECD}, {0x0F18, 0x0F19}, {0x0F35, 0x0F35},
37
+	{0x0F37, 0x0F37}, {0x0F39, 0x0F39}, {0x0F71, 0x0F7E},
38
+	{0x0F80, 0x0F84}, {0x0F86, 0x0F87}, {0x0F90, 0x0F97},
39
+	{0x0F99, 0x0FBC}, {0x0FC6, 0x0FC6}, {0x102D, 0x1030},
40
+	{0x1032, 0x1032}, {0x1036, 0x1037}, {0x1039, 0x1039},
41
+	{0x1058, 0x1059}, {0x1160, 0x11FF}, {0x135F, 0x135F},
42
+	{0x1712, 0x1714}, {0x1732, 0x1734}, {0x1752, 0x1753},
43
+	{0x1772, 0x1773}, {0x17B4, 0x17B5}, {0x17B7, 0x17BD},
44
+	{0x17C6, 0x17C6}, {0x17C9, 0x17D3}, {0x17DD, 0x17DD},
45
+	{0x180B, 0x180D}, {0x18A9, 0x18A9}, {0x1920, 0x1922},
46
+	{0x1927, 0x1928}, {0x1932, 0x1932}, {0x1939, 0x193B},
47
+	{0x1A17, 0x1A18}, {0x1B00, 0x1B03}, {0x1B34, 0x1B34},
48
+	{0x1B36, 0x1B3A}, {0x1B3C, 0x1B3C}, {0x1B42, 0x1B42},
49
+	{0x1B6B, 0x1B73}, {0x1DC0, 0x1DCA}, {0x1DFE, 0x1DFF},
50
+	{0x200B, 0x200F}, {0x202A, 0x202E}, {0x2060, 0x2063},
51
+	{0x206A, 0x206F}, {0x20D0, 0x20EF}, {0x302A, 0x302F},
52
+	{0x3099, 0x309A}, {0xA806, 0xA806}, {0xA80B, 0xA80B},
53
+	{0xA825, 0xA826}, {0xFB1E, 0xFB1E}, {0xFE00, 0xFE0F},
54
+	{0xFE20, 0xFE23}, {0xFEFF, 0xFEFF}, {0xFFF9, 0xFFFB},
55
+	{0x10A01, 0x10A03}, {0x10A05, 0x10A06}, {0x10A0C, 0x10A0F},
56
+	{0x10A38, 0x10A3A}, {0x10A3F, 0x10A3F}, {0x1D167, 0x1D169},
57
+	{0x1D173, 0x1D182}, {0x1D185, 0x1D18B}, {0x1D1AA, 0x1D1AD},
58
+	{0x1D242, 0x1D244}, {0xE0001, 0xE0001}, {0xE0020, 0xE007F},
59
+	{0xE0100, 0xE01EF},
60
+}
61
+
62
+type ctype int
63
+
64
+const (
65
+	narrow ctype = iota
66
+	ambiguous
67
+	wide
68
+	halfwidth
69
+	fullwidth
70
+	neutral
71
+)
72
+
73
+type intervalType struct {
74
+	first rune
75
+	last  rune
76
+	ctype ctype
77
+}
78
+
79
+var ctypes = []intervalType{
80
+	{0x0020, 0x007E, narrow},
81
+	{0x00A1, 0x00A1, ambiguous},
82
+	{0x00A2, 0x00A3, narrow},
83
+	{0x00A4, 0x00A4, ambiguous},
84
+	{0x00A5, 0x00A6, narrow},
85
+	{0x00A7, 0x00A8, ambiguous},
86
+	{0x00AA, 0x00AA, ambiguous},
87
+	{0x00AC, 0x00AC, narrow},
88
+	{0x00AD, 0x00AE, ambiguous},
89
+	{0x00AF, 0x00AF, narrow},
90
+	{0x00B0, 0x00B4, ambiguous},
91
+	{0x00B6, 0x00BA, ambiguous},
92
+	{0x00BC, 0x00BF, ambiguous},
93
+	{0x00C6, 0x00C6, ambiguous},
94
+	{0x00D0, 0x00D0, ambiguous},
95
+	{0x00D7, 0x00D8, ambiguous},
96
+	{0x00DE, 0x00E1, ambiguous},
97
+	{0x00E6, 0x00E6, ambiguous},
98
+	{0x00E8, 0x00EA, ambiguous},
99
+	{0x00EC, 0x00ED, ambiguous},
100
+	{0x00F0, 0x00F0, ambiguous},
101
+	{0x00F2, 0x00F3, ambiguous},
102
+	{0x00F7, 0x00FA, ambiguous},
103
+	{0x00FC, 0x00FC, ambiguous},
104
+	{0x00FE, 0x00FE, ambiguous},
105
+	{0x0101, 0x0101, ambiguous},
106
+	{0x0111, 0x0111, ambiguous},
107
+	{0x0113, 0x0113, ambiguous},
108
+	{0x011B, 0x011B, ambiguous},
109
+	{0x0126, 0x0127, ambiguous},
110
+	{0x012B, 0x012B, ambiguous},
111
+	{0x0131, 0x0133, ambiguous},
112
+	{0x0138, 0x0138, ambiguous},
113
+	{0x013F, 0x0142, ambiguous},
114
+	{0x0144, 0x0144, ambiguous},
115
+	{0x0148, 0x014B, ambiguous},
116
+	{0x014D, 0x014D, ambiguous},
117
+	{0x0152, 0x0153, ambiguous},
118
+	{0x0166, 0x0167, ambiguous},
119
+	{0x016B, 0x016B, ambiguous},
120
+	{0x01CE, 0x01CE, ambiguous},
121
+	{0x01D0, 0x01D0, ambiguous},
122
+	{0x01D2, 0x01D2, ambiguous},
123
+	{0x01D4, 0x01D4, ambiguous},
124
+	{0x01D6, 0x01D6, ambiguous},
125
+	{0x01D8, 0x01D8, ambiguous},
126
+	{0x01DA, 0x01DA, ambiguous},
127
+	{0x01DC, 0x01DC, ambiguous},
128
+	{0x0251, 0x0251, ambiguous},
129
+	{0x0261, 0x0261, ambiguous},
130
+	{0x02C4, 0x02C4, ambiguous},
131
+	{0x02C7, 0x02C7, ambiguous},
132
+	{0x02C9, 0x02CB, ambiguous},
133
+	{0x02CD, 0x02CD, ambiguous},
134
+	{0x02D0, 0x02D0, ambiguous},
135
+	{0x02D8, 0x02DB, ambiguous},
136
+	{0x02DD, 0x02DD, ambiguous},
137
+	{0x02DF, 0x02DF, ambiguous},
138
+	{0x0300, 0x036F, ambiguous},
139
+	{0x0391, 0x03A2, ambiguous},
140
+	{0x03A3, 0x03A9, ambiguous},
141
+	{0x03B1, 0x03C1, ambiguous},
142
+	{0x03C3, 0x03C9, ambiguous},
143
+	{0x0401, 0x0401, ambiguous},
144
+	{0x0410, 0x044F, ambiguous},
145
+	{0x0451, 0x0451, ambiguous},
146
+	{0x1100, 0x115F, wide},
147
+	{0x2010, 0x2010, ambiguous},
148
+	{0x2013, 0x2016, ambiguous},
149
+	{0x2018, 0x2019, ambiguous},
150
+	{0x201C, 0x201D, ambiguous},
151
+	{0x2020, 0x2022, ambiguous},
152
+	{0x2024, 0x2027, ambiguous},
153
+	{0x2030, 0x2030, ambiguous},
154
+	{0x2032, 0x2033, ambiguous},
155
+	{0x2035, 0x2035, ambiguous},
156
+	{0x203B, 0x203B, ambiguous},
157
+	{0x203E, 0x203E, ambiguous},
158
+	{0x2074, 0x2074, ambiguous},
159
+	{0x207F, 0x207F, ambiguous},
160
+	{0x2081, 0x2084, ambiguous},
161
+	{0x20A9, 0x20A9, halfwidth},
162
+	{0x20AC, 0x20AC, ambiguous},
163
+	{0x2103, 0x2103, ambiguous},
164
+	{0x2105, 0x2105, ambiguous},
165
+	{0x2109, 0x2109, ambiguous},
166
+	{0x2113, 0x2113, ambiguous},
167
+	{0x2116, 0x2116, ambiguous},
168
+	{0x2121, 0x2122, ambiguous},
169
+	{0x2126, 0x2126, ambiguous},
170
+	{0x212B, 0x212B, ambiguous},
171
+	{0x2153, 0x2154, ambiguous},
172
+	{0x215B, 0x215E, ambiguous},
173
+	{0x2160, 0x216B, ambiguous},
174
+	{0x2170, 0x2179, ambiguous},
175
+	{0x2189, 0x218A, ambiguous},
176
+	{0x2190, 0x2199, ambiguous},
177
+	{0x21B8, 0x21B9, ambiguous},
178
+	{0x21D2, 0x21D2, ambiguous},
179
+	{0x21D4, 0x21D4, ambiguous},
180
+	{0x21E7, 0x21E7, ambiguous},
181
+	{0x2200, 0x2200, ambiguous},
182
+	{0x2202, 0x2203, ambiguous},
183
+	{0x2207, 0x2208, ambiguous},
184
+	{0x220B, 0x220B, ambiguous},
185
+	{0x220F, 0x220F, ambiguous},
186
+	{0x2211, 0x2211, ambiguous},
187
+	{0x2215, 0x2215, ambiguous},
188
+	{0x221A, 0x221A, ambiguous},
189
+	{0x221D, 0x2220, ambiguous},
190
+	{0x2223, 0x2223, ambiguous},
191
+	{0x2225, 0x2225, ambiguous},
192
+	{0x2227, 0x222C, ambiguous},
193
+	{0x222E, 0x222E, ambiguous},
194
+	{0x2234, 0x2237, ambiguous},
195
+	{0x223C, 0x223D, ambiguous},
196
+	{0x2248, 0x2248, ambiguous},
197
+	{0x224C, 0x224C, ambiguous},
198
+	{0x2252, 0x2252, ambiguous},
199
+	{0x2260, 0x2261, ambiguous},
200
+	{0x2264, 0x2267, ambiguous},
201
+	{0x226A, 0x226B, ambiguous},
202
+	{0x226E, 0x226F, ambiguous},
203
+	{0x2282, 0x2283, ambiguous},
204
+	{0x2286, 0x2287, ambiguous},
205
+	{0x2295, 0x2295, ambiguous},
206
+	{0x2299, 0x2299, ambiguous},
207
+	{0x22A5, 0x22A5, ambiguous},
208
+	{0x22BF, 0x22BF, ambiguous},
209
+	{0x2312, 0x2312, ambiguous},
210
+	{0x2329, 0x232A, wide},
211
+	{0x2460, 0x24E9, ambiguous},
212
+	{0x24EB, 0x254B, ambiguous},
213
+	{0x2550, 0x2573, ambiguous},
214
+	{0x2580, 0x258F, ambiguous},
215
+	{0x2592, 0x2595, ambiguous},
216
+	{0x25A0, 0x25A1, ambiguous},
217
+	{0x25A3, 0x25A9, ambiguous},
218
+	{0x25B2, 0x25B3, ambiguous},
219
+	{0x25B6, 0x25B7, ambiguous},
220
+	{0x25BC, 0x25BD, ambiguous},
221
+	{0x25C0, 0x25C1, ambiguous},
222
+	{0x25C6, 0x25C8, ambiguous},
223
+	{0x25CB, 0x25CB, ambiguous},
224
+	{0x25CE, 0x25D1, ambiguous},
225
+	{0x25E2, 0x25E5, ambiguous},
226
+	{0x25EF, 0x25EF, ambiguous},
227
+	{0x2605, 0x2606, ambiguous},
228
+	{0x2609, 0x2609, ambiguous},
229
+	{0x260E, 0x260F, ambiguous},
230
+	{0x2614, 0x2615, ambiguous},
231
+	{0x261C, 0x261C, ambiguous},
232
+	{0x261E, 0x261E, ambiguous},
233
+	{0x2640, 0x2640, ambiguous},
234
+	{0x2642, 0x2642, ambiguous},
235
+	{0x2660, 0x2661, ambiguous},
236
+	{0x2663, 0x2665, ambiguous},
237
+	{0x2667, 0x266A, ambiguous},
238
+	{0x266C, 0x266D, ambiguous},
239
+	{0x266F, 0x266F, ambiguous},
240
+	{0x269E, 0x269F, ambiguous},
241
+	{0x26BE, 0x26BF, ambiguous},
242
+	{0x26C4, 0x26CD, ambiguous},
243
+	{0x26CF, 0x26E1, ambiguous},
244
+	{0x26E3, 0x26E3, ambiguous},
245
+	{0x26E8, 0x26FF, ambiguous},
246
+	{0x273D, 0x273D, ambiguous},
247
+	{0x2757, 0x2757, ambiguous},
248
+	{0x2776, 0x277F, ambiguous},
249
+	{0x27E6, 0x27ED, narrow},
250
+	{0x2985, 0x2986, narrow},
251
+	{0x2B55, 0x2B59, ambiguous},
252
+	{0x2E80, 0x2E9A, wide},
253
+	{0x2E9B, 0x2EF4, wide},
254
+	{0x2F00, 0x2FD6, wide},
255
+	{0x2FF0, 0x2FFC, wide},
256
+	{0x3000, 0x3000, fullwidth},
257
+	{0x3001, 0x303E, wide},
258
+	{0x3041, 0x3097, wide},
259
+	{0x3099, 0x3100, wide},
260
+	{0x3105, 0x312E, wide},
261
+	{0x3131, 0x318F, wide},
262
+	{0x3190, 0x31BB, wide},
263
+	{0x31C0, 0x31E4, wide},
264
+	{0x31F0, 0x321F, wide},
265
+	{0x3220, 0x3247, wide},
266
+	{0x3248, 0x324F, ambiguous},
267
+	{0x3250, 0x32FF, wide},
268
+	{0x3300, 0x4DBF, wide},
269
+	{0x4E00, 0xA48D, wide},
270
+	{0xA490, 0xA4C7, wide},
271
+	{0xA960, 0xA97D, wide},
272
+	{0xAC00, 0xD7A4, wide},
273
+	{0xE000, 0xF8FF, ambiguous},
274
+	{0xF900, 0xFAFF, wide},
275
+	{0xFE00, 0xFE0F, ambiguous},
276
+	{0xFE10, 0xFE1A, wide},
277
+	{0xFE30, 0xFE53, wide},
278
+	{0xFE54, 0xFE67, wide},
279
+	{0xFE68, 0xFE6C, wide},
280
+	{0xFF01, 0xFF60, fullwidth},
281
+	{0xFF61, 0xFFBF, halfwidth},
282
+	{0xFFC2, 0xFFC8, halfwidth},
283
+	{0xFFCA, 0xFFD0, halfwidth},
284
+	{0xFFD2, 0xFFD8, halfwidth},
285
+	{0xFFDA, 0xFFDD, halfwidth},
286
+	{0xFFE0, 0xFFE7, fullwidth},
287
+	{0xFFE8, 0xFFEF, halfwidth},
288
+	{0xFFFD, 0xFFFE, ambiguous},
289
+	{0x1B000, 0x1B002, wide},
290
+	{0x1F100, 0x1F10A, ambiguous},
291
+	{0x1F110, 0x1F12D, ambiguous},
292
+	{0x1F130, 0x1F169, ambiguous},
293
+	{0x1F170, 0x1F19B, ambiguous},
294
+	{0x1F200, 0x1F203, wide},
295
+	{0x1F210, 0x1F23B, wide},
296
+	{0x1F240, 0x1F249, wide},
297
+	{0x1F250, 0x1F252, wide},
298
+	{0x20000, 0x2FFFE, wide},
299
+	{0x30000, 0x3FFFE, wide},
300
+	{0xE0100, 0xE01F0, ambiguous},
301
+	{0xF0000, 0xFFFFD, ambiguous},
302
+	{0x100000, 0x10FFFE, ambiguous},
303
+}
304
+
305
+type Condition struct {
306
+	EastAsianWidth bool
307
+}
308
+
309
+func NewCondition() *Condition {
310
+	return &Condition{EastAsianWidth}
311
+}
312
+
313
+// RuneWidth returns the number of cells in r.
314
+// See http://www.unicode.org/reports/tr11/
315
+func (c *Condition) RuneWidth(r rune) int {
316
+	if r == 0 {
317
+		return 0
318
+	}
319
+	if r < 32 || (r >= 0x7f && r < 0xa0) {
320
+		return 1
321
+	}
322
+	for _, iv := range combining {
323
+		if iv.first <= r && r <= iv.last {
324
+			return 0
325
+		}
326
+	}
327
+
328
+	if c.EastAsianWidth && IsAmbiguousWidth(r) {
329
+		return 2
330
+	}
331
+
332
+	if r >= 0x1100 &&
333
+		(r <= 0x115f || r == 0x2329 || r == 0x232a ||
334
+			(r >= 0x2e80 && r <= 0xa4cf && r != 0x303f) ||
335
+			(r >= 0xac00 && r <= 0xd7a3) ||
336
+			(r >= 0xf900 && r <= 0xfaff) ||
337
+			(r >= 0xfe30 && r <= 0xfe6f) ||
338
+			(r >= 0xff00 && r <= 0xff60) ||
339
+			(r >= 0xffe0 && r <= 0xffe6) ||
340
+			(r >= 0x20000 && r <= 0x2fffd) ||
341
+			(r >= 0x30000 && r <= 0x3fffd)) {
342
+		return 2
343
+	}
344
+	return 1
345
+}
346
+
347
+func (c *Condition) StringWidth(s string) (width int) {
348
+	for _, r := range []rune(s) {
349
+		width += c.RuneWidth(r)
350
+	}
351
+	return width
352
+}
353
+
354
+func (c *Condition) Truncate(s string, w int, tail string) string {
355
+	if c.StringWidth(s) <= w {
356
+		return s
357
+	}
358
+	r := []rune(s)
359
+	tw := c.StringWidth(tail)
360
+	w -= tw
361
+	width := 0
362
+	i := 0
363
+	for ; i < len(r); i++ {
364
+		cw := c.RuneWidth(r[i])
365
+		if width+cw > w {
366
+			break
367
+		}
368
+		width += cw
369
+	}
370
+	return string(r[0:i]) + tail
371
+}
372
+
373
+func (c *Condition) Wrap(s string, w int) string {
374
+	width := 0
375
+	out := ""
376
+	for _, r := range []rune(s) {
377
+		cw := RuneWidth(r)
378
+		if r == '\n' {
379
+			out += string(r)
380
+			width = 0
381
+			continue
382
+		} else if width+cw > w {
383
+			out += "\n"
384
+			width = 0
385
+			out += string(r)
386
+			width += cw
387
+			continue
388
+		}
389
+		out += string(r)
390
+		width += cw
391
+	}
392
+	return out
393
+}
394
+
395
+func (c *Condition) FillLeft(s string, w int) string {
396
+	width := c.StringWidth(s)
397
+	count := w - width
398
+	if count > 0 {
399
+		b := make([]byte, count)
400
+		for i := range b {
401
+			b[i] = ' '
402
+		}
403
+		return string(b) + s
404
+	}
405
+	return s
406
+}
407
+
408
+func (c *Condition) FillRight(s string, w int) string {
409
+	width := c.StringWidth(s)
410
+	count := w - width
411
+	if count > 0 {
412
+		b := make([]byte, count)
413
+		for i := range b {
414
+			b[i] = ' '
415
+		}
416
+		return s + string(b)
417
+	}
418
+	return s
419
+}
420
+
421
+// RuneWidth returns the number of cells in r.
422
+// See http://www.unicode.org/reports/tr11/
423
+func RuneWidth(r rune) int {
424
+	return DefaultCondition.RuneWidth(r)
425
+}
426
+
427
+func ct(r rune) ctype {
428
+	for _, iv := range ctypes {
429
+		if iv.first <= r && r <= iv.last {
430
+			return iv.ctype
431
+		}
432
+	}
433
+	return neutral
434
+}
435
+
436
+// IsAmbiguousWidth returns whether is ambiguous width or not.
437
+func IsAmbiguousWidth(r rune) bool {
438
+	return ct(r) == ambiguous
439
+}
440
+
441
+// IsAmbiguousWidth returns whether is ambiguous width or not.
442
+func IsNeutralWidth(r rune) bool {
443
+	return ct(r) == neutral
444
+}
445
+
446
+func StringWidth(s string) (width int) {
447
+	return DefaultCondition.StringWidth(s)
448
+}
449
+
450
+func Truncate(s string, w int, tail string) string {
451
+	return DefaultCondition.Truncate(s, w, tail)
452
+}
453
+
454
+func Wrap(s string, w int) string {
455
+	return DefaultCondition.Wrap(s, w)
456
+}
457
+
458
+func FillLeft(s string, w int) string {
459
+	return DefaultCondition.FillLeft(s, w)
460
+}
461
+
462
+func FillRight(s string, w int) string {
463
+	return DefaultCondition.FillRight(s, w)
464
+}

+ 8
- 0
vendor/github.com/mattn/go-runewidth/runewidth_js.go View File

@@ -0,0 +1,8 @@
1
+// +build js
2
+
3
+package runewidth
4
+
5
+func IsEastAsian() bool {
6
+	// TODO: Implement this for the web. Detect east asian in a compatible way, and return true.
7
+	return false
8
+}

+ 69
- 0
vendor/github.com/mattn/go-runewidth/runewidth_posix.go View File

@@ -0,0 +1,69 @@
1
+// +build !windows,!js
2
+
3
+package runewidth
4
+
5
+import (
6
+	"os"
7
+	"regexp"
8
+	"strings"
9
+)
10
+
11
+var reLoc = regexp.MustCompile(`^[a-z][a-z][a-z]?(?:_[A-Z][A-Z])?\.(.+)`)
12
+
13
+func IsEastAsian() bool {
14
+	locale := os.Getenv("LC_CTYPE")
15
+	if locale == "" {
16
+		locale = os.Getenv("LANG")
17
+	}
18
+
19
+	// ignore C locale
20
+	if locale == "POSIX" || locale == "C" {
21
+		return false
22
+	}
23
+	if len(locale) > 1 && locale[0] == 'C' && (locale[1] == '.' || locale[1] == '-') {
24
+		return false
25
+	}
26
+
27
+	charset := strings.ToLower(locale)
28
+	r := reLoc.FindStringSubmatch(locale)
29
+	if len(r) == 2 {
30
+		charset = strings.ToLower(r[1])
31
+	}
32
+
33
+	if strings.HasSuffix(charset, "@cjk_narrow") {
34
+		return false
35
+	}
36
+
37
+	for pos, b := range []byte(charset) {
38
+		if b == '@' {
39
+			charset = charset[:pos]
40
+			break
41
+		}
42
+	}
43
+
44
+	mbc_max := 1
45
+	switch charset {
46
+	case "utf-8", "utf8":
47
+		mbc_max = 6
48
+	case "jis":
49
+		mbc_max = 8
50
+	case "eucjp":
51
+		mbc_max = 3
52
+	case "euckr", "euccn":
53
+		mbc_max = 2
54
+	case "sjis", "cp932", "cp51932", "cp936", "cp949", "cp950":
55
+		mbc_max = 2
56
+	case "big5":
57
+		mbc_max = 2
58
+	case "gbk", "gb2312":
59
+		mbc_max = 2
60
+	}
61
+
62
+	if mbc_max > 1 && (charset[0] != 'u' ||
63
+		strings.HasPrefix(locale, "ja") ||
64
+		strings.HasPrefix(locale, "ko") ||
65
+		strings.HasPrefix(locale, "zh")) {
66
+		return true
67
+	}
68
+	return false
69
+}

+ 229
- 0
vendor/github.com/mattn/go-runewidth/runewidth_test.go View File

@@ -0,0 +1,229 @@
1
+package runewidth
2
+
3
+import (
4
+	"testing"
5
+)
6
+
7
+var runewidthtests = []struct {
8
+	in  rune
9
+	out int
10
+}{
11
+	{'世', 2},
12
+	{'界', 2},
13
+	{'セ', 1},
14
+	{'カ', 1},
15
+	{'イ', 1},
16
+	{'☆', 2}, // double width in ambiguous
17
+	{'\x00', 0},
18
+	{'\x01', 1},
19
+	{'\u0300', 0},
20
+}
21
+
22
+func TestRuneWidth(t *testing.T) {
23
+	c := NewCondition()
24
+	c.EastAsianWidth = true
25
+	for _, tt := range runewidthtests {
26
+		if out := c.RuneWidth(tt.in); out != tt.out {
27
+			t.Errorf("Width(%q) = %q, want %q", tt.in, out, tt.out)
28
+		}
29
+	}
30
+}
31
+
32
+var isambiguouswidthtests = []struct {
33
+	in  rune
34
+	out bool
35
+}{
36
+	{'世', false},
37
+	{'■', true},
38
+	{'界', false},
39
+	{'○', true},
40
+	{'㈱', false},
41
+	{'①', true},
42
+	{'②', true},
43
+	{'③', true},
44
+	{'④', true},
45
+	{'⑤', true},
46
+	{'⑥', true},
47
+	{'⑦', true},
48
+	{'⑧', true},
49
+	{'⑨', true},
50
+	{'⑩', true},
51
+	{'⑪', true},
52
+	{'⑫', true},
53
+	{'⑬', true},
54
+	{'⑭', true},
55
+	{'⑮', true},
56
+	{'⑯', true},
57
+	{'⑰', true},
58
+	{'⑱', true},
59
+	{'⑲', true},
60
+	{'⑳', true},
61
+	{'☆', true},
62
+}
63
+
64
+func TestIsAmbiguousWidth(t *testing.T) {
65
+	for _, tt := range isambiguouswidthtests {
66
+		if out := IsAmbiguousWidth(tt.in); out != tt.out {
67
+			t.Errorf("IsAmbiguousWidth(%q) = %q, want %q", tt.in, out, tt.out)
68
+		}
69
+	}
70
+}
71
+
72
+var stringwidthtests = []struct {
73
+	in  string
74
+	out int
75
+}{
76
+	{"■㈱の世界①", 12},
77
+	{"スター☆", 8},
78
+}
79
+
80
+func TestStringWidth(t *testing.T) {
81
+	c := NewCondition()
82
+	c.EastAsianWidth = true
83
+	for _, tt := range stringwidthtests {
84
+		if out := c.StringWidth(tt.in); out != tt.out {
85
+			t.Errorf("StringWidth(%q) = %q, want %q", tt.in, out, tt.out)
86
+		}
87
+	}
88
+}
89
+
90
+func TestStringWidthInvalid(t *testing.T) {
91
+	s := "こんにちわ\x00世界"
92
+	if out := StringWidth(s); out != 14 {
93
+		t.Errorf("StringWidth(%q) = %q, want %q", s, out, 14)
94
+	}
95
+}
96
+
97
+func TestTruncateSmaller(t *testing.T) {
98
+	s := "あいうえお"
99
+	expected := "あいうえお"
100
+
101
+	if out := Truncate(s, 10, "..."); out != expected {
102
+		t.Errorf("Truncate(%q) = %q, want %q", s, out, expected)
103
+	}
104
+}
105
+
106
+func TestTruncate(t *testing.T) {
107
+	s := "あいうえおあいうえおえおおおおおおおおおおおおおおおおおおおおおおおおおおおおおお"
108
+	expected := "あいうえおあいうえおえおおおおおおおおおおおおおおおおおおおおおおおおおおお..."
109
+
110
+	out := Truncate(s, 80, "...")
111
+	if out != expected {
112
+		t.Errorf("Truncate(%q) = %q, want %q", s, out, expected)
113
+	}
114
+	width := StringWidth(out)
115
+	if width != 79 {
116
+		t.Errorf("width of Truncate(%q) should be %d, but %d", s, 79, width)
117
+	}
118
+}
119
+
120
+func TestTruncateFit(t *testing.T) {
121
+	s := "aあいうえおあいうえおえおおおおおおおおおおおおおおおおおおおおおおおおおおおおおお"
122
+	expected := "aあいうえおあいうえおえおおおおおおおおおおおおおおおおおおおおおおおおおおお..."
123
+
124
+	out := Truncate(s, 80, "...")
125
+	if out != expected {
126
+		t.Errorf("Truncate(%q) = %q, want %q", s, out, expected)
127
+	}
128
+	width := StringWidth(out)
129
+	if width != 80 {
130
+		t.Errorf("width of Truncate(%q) should be %d, but %d", s, 80, width)
131
+	}
132
+}
133
+
134
+func TestTruncateJustFit(t *testing.T) {
135
+	s := "あいうえおあいうえおえおおおおおおおおおおおおおおおおおおおおおおおおおおおおお"
136
+	expected := "あいうえおあいうえおえおおおおおおおおおおおおおおおおおおおおおおおおおおおおお"
137
+
138
+	out := Truncate(s, 80, "...")
139
+	if out != expected {
140
+		t.Errorf("Truncate(%q) = %q, want %q", s, out, expected)
141
+	}
142
+	width := StringWidth(out)
143
+	if width != 80 {
144
+		t.Errorf("width of Truncate(%q) should be %d, but %d", s, 80, width)
145
+	}
146
+}
147
+
148
+func TestWrap(t *testing.T) {
149
+	s := `東京特許許可局局長はよく柿喰う客だ/東京特許許可局局長はよく柿喰う客だ
150
+123456789012345678901234567890
151
+
152
+END`
153
+	expected := `東京特許許可局局長はよく柿喰う
154
+客だ/東京特許許可局局長はよく
155
+柿喰う客だ
156
+123456789012345678901234567890
157
+
158
+END`
159
+
160
+	if out := Wrap(s, 30); out != expected {
161
+		t.Errorf("Wrap(%q) = %q, want %q", s, out, expected)
162
+	}
163
+}
164
+
165
+func TestTruncateNoNeeded(t *testing.T) {
166
+	s := "あいうえおあい"
167
+	expected := "あいうえおあい"
168
+
169
+	if out := Truncate(s, 80, "..."); out != expected {
170
+		t.Errorf("Truncate(%q) = %q, want %q", s, out, expected)
171
+	}
172
+}
173
+
174
+var isneutralwidthtests = []struct {
175
+	in  rune
176
+	out bool
177
+}{
178
+	{'→', false},
179
+	{'┊', false},
180
+	{'┈', false},
181
+	{'~', false},
182
+	{'└', false},
183
+	{'⣀', true},
184
+	{'⣀', true},
185
+}
186
+
187
+func TestIsNeutralWidth(t *testing.T) {
188
+	for _, tt := range isneutralwidthtests {
189
+		if out := IsNeutralWidth(tt.in); out != tt.out {
190
+			t.Errorf("IsNeutralWidth(%q) = %q, want %q", tt.in, out, tt.out)
191
+		}
192
+	}
193
+}
194
+
195
+func TestFillLeft(t *testing.T) {
196
+	s := "あxいうえお"
197
+	expected := "    あxいうえお"
198
+
199
+	if out := FillLeft(s, 15); out != expected {
200
+		t.Errorf("FillLeft(%q) = %q, want %q", s, out, expected)
201
+	}
202
+}
203
+
204
+func TestFillLeftFit(t *testing.T) {
205
+	s := "あいうえお"
206
+	expected := "あいうえお"
207
+
208
+	if out := FillLeft(s, 10); out != expected {
209
+		t.Errorf("FillLeft(%q) = %q, want %q", s, out, expected)
210
+	}
211
+}
212
+
213
+func TestFillRight(t *testing.T) {
214
+	s := "あxいうえお"
215
+	expected := "あxいうえお    "
216
+
217
+	if out := FillRight(s, 15); out != expected {
218
+		t.Errorf("FillRight(%q) = %q, want %q", s, out, expected)
219
+	}
220
+}
221
+
222
+func TestFillRightFit(t *testing.T) {
223
+	s := "あいうえお"
224
+	expected := "あいうえお"
225
+
226
+	if out := FillRight(s, 10); out != expected {
227
+		t.Errorf("FillRight(%q) = %q, want %q", s, out, expected)
228
+	}
229
+}

+ 24
- 0
vendor/github.com/mattn/go-runewidth/runewidth_windows.go View File

@@ -0,0 +1,24 @@
1
+package runewidth
2
+
3
+import (
4
+	"syscall"
5
+)
6
+
7
+var (
8
+	kernel32               = syscall.NewLazyDLL("kernel32")
9
+	procGetConsoleOutputCP = kernel32.NewProc("GetConsoleOutputCP")
10
+)
11
+
12
+func IsEastAsian() bool {
13
+	r1, _, _ := procGetConsoleOutputCP.Call()
14
+	if r1 == 0 {
15
+		return false
16
+	}
17
+
18
+	switch int(r1) {
19
+	case 932, 51932, 936, 949, 950:
20
+		return true
21
+	}
22
+
23
+	return false
24
+}

+ 4
- 0
vendor/github.com/nsf/termbox-go/AUTHORS View File

@@ -0,0 +1,4 @@
1
+# Please keep this file sorted.
2
+
3
+Georg Reinke <guelfey@googlemail.com>
4
+nsf <no.smile.face@gmail.com>

+ 19
- 0
vendor/github.com/nsf/termbox-go/LICENSE View File

@@ -0,0 +1,19 @@
1
+Copyright (C) 2012 termbox-go authors
2
+
3
+Permission is hereby granted, free of charge, to any person obtaining a copy
4
+of this software and associated documentation files (the "Software"), to deal
5
+in the Software without restriction, including without limitation the rights
6
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+copies of the Software, and to permit persons to whom the Software is
8
+furnished to do so, subject to the following conditions:
9
+
10
+The above copyright notice and this permission notice shall be included in
11
+all copies or substantial portions of the Software.
12
+
13
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+THE SOFTWARE.

+ 25
- 0
vendor/github.com/nsf/termbox-go/README.md View File

@@ -0,0 +1,25 @@
1
+## Termbox
2
+Termbox is a library that provides a minimalistic API which allows the programmer to write text-based user interfaces. The library is crossplatform and has both terminal-based implementations on *nix operating systems and a winapi console based implementation for windows operating systems. The basic idea is an abstraction of the greatest common subset of features available on all major terminals and other terminal-like APIs in a minimalistic fashion. Small API means it is easy to implement, test, maintain and learn it, that's what makes the termbox a distinct library in its area.
3
+
4
+### Installation
5
+Install and update this go package with `go get -u github.com/nsf/termbox-go`
6
+
7
+### Examples
8
+For examples of what can be done take a look at demos in the _demos directory. You can try them with go run: `go run _demos/keyboard.go`
9
+
10
+There are also some interesting projects using termbox-go:
11
+ - [godit](https://github.com/nsf/godit) is an emacsish lightweight text editor written using termbox.
12
+ - [gomatrix](https://github.com/GeertJohan/gomatrix) connects to The Matrix and displays its data streams in your terminal.
13
+ - [gotetris](https://github.com/jjinux/gotetris) is an implementation of Tetris.
14
+ - [sokoban-go](https://github.com/rn2dy/sokoban-go) is an implementation of sokoban game.
15
+ - [hecate](https://github.com/evanmiller/hecate) is a hex editor designed by Satan.
16
+ - [httopd](https://github.com/verdverm/httopd) is top for httpd logs.
17
+ - [mop](https://github.com/michaeldv/mop) is stock market tracker for hackers.
18
+ - [termui](https://github.com/gizak/termui) is a terminal dashboard.
19
+ - [termloop](https://github.com/JoelOtter/termloop) is a terminal game engine.
20
+ - [xterm-color-chart](https://github.com/kutuluk/xterm-color-chart) is a XTerm 256 color chart.
21
+ - [gocui](https://github.com/jroimartin/gocui) is a minimalist Go library aimed at creating console user interfaces.
22
+ - [dry](https://github.com/moncho/dry) is an interactive cli to manage Docker containers.
23
+
24
+### API reference
25
+[godoc.org/github.com/nsf/termbox-go](http://godoc.org/github.com/nsf/termbox-go)

+ 459
- 0
vendor/github.com/nsf/termbox-go/api.go View File

@@ -0,0 +1,459 @@
1
+// +build !windows
2
+
3
+package termbox
4
+
5
+import "github.com/mattn/go-runewidth"
6
+import "fmt"
7
+import "os"
8
+import "os/signal"
9
+import "syscall"
10
+import "runtime"
11
+
12
+// public API
13
+
14
+// Initializes termbox library. This function should be called before any other functions.
15
+// After successful initialization, the library must be finalized using 'Close' function.
16
+//
17
+// Example usage:
18
+//      err := termbox.Init()
19
+//      if err != nil {
20
+//              panic(err)
21
+//      }
22
+//      defer termbox.Close()
23
+func Init() error {
24
+	var err error
25
+
26
+	out, err = os.OpenFile("/dev/tty", syscall.O_WRONLY, 0)
27
+	if err != nil {
28
+		return err
29
+	}
30
+	in, err = syscall.Open("/dev/tty", syscall.O_RDONLY, 0)
31
+	if err != nil {
32
+		return err
33
+	}
34
+
35
+	err = setup_term()
36
+	if err != nil {
37
+		return fmt.Errorf("termbox: error while reading terminfo data: %v", err)
38
+	}
39
+
40
+	signal.Notify(sigwinch, syscall.SIGWINCH)
41
+	signal.Notify(sigio, syscall.SIGIO)
42
+
43
+	_, err = fcntl(in, syscall.F_SETFL, syscall.O_ASYNC|syscall.O_NONBLOCK)
44
+	if err != nil {
45
+		return err
46
+	}
47
+	_, err = fcntl(in, syscall.F_SETOWN, syscall.Getpid())
48
+	if runtime.GOOS != "darwin" && err != nil {
49
+		return err
50
+	}
51
+	err = tcgetattr(out.Fd(), &orig_tios)
52
+	if err != nil {
53
+		return err
54
+	}
55
+
56
+	tios := orig_tios
57
+	tios.Iflag &^= syscall_IGNBRK | syscall_BRKINT | syscall_PARMRK |
58
+		syscall_ISTRIP | syscall_INLCR | syscall_IGNCR |
59
+		syscall_ICRNL | syscall_IXON
60
+	tios.Oflag &^= syscall_OPOST
61
+	tios.Lflag &^= syscall_ECHO | syscall_ECHONL | syscall_ICANON |
62
+		syscall_ISIG | syscall_IEXTEN
63
+	tios.Cflag &^= syscall_CSIZE | syscall_PARENB
64
+	tios.Cflag |= syscall_CS8
65
+	tios.Cc[syscall_VMIN] = 1
66
+	tios.Cc[syscall_VTIME] = 0
67
+
68
+	err = tcsetattr(out.Fd(), &tios)
69
+	if err != nil {
70
+		return err
71
+	}
72
+
73
+	out.WriteString(funcs[t_enter_ca])
74
+	out.WriteString(funcs[t_enter_keypad])
75
+	out.WriteString(funcs[t_hide_cursor])
76
+	out.WriteString(funcs[t_clear_screen])
77
+
78
+	termw, termh = get_term_size(out.Fd())
79
+	back_buffer.init(termw, termh)
80
+	front_buffer.init(termw, termh)
81
+	back_buffer.clear()
82
+	front_buffer.clear()
83
+
84
+	go func() {
85
+		buf := make([]byte, 128)
86
+		for {
87
+			select {
88
+			case <-sigio:
89
+				for {
90
+					n, err := syscall.Read(in, buf)
91
+					if err == syscall.EAGAIN || err == syscall.EWOULDBLOCK {
92
+						break
93
+					}
94
+					select {
95
+					case input_comm <- input_event{buf[:n], err}:
96
+						ie := <-input_comm
97
+						buf = ie.data[:128]
98
+					case <-quit:
99
+						return
100
+					}
101
+				}
102
+			case <-quit:
103
+				return
104
+			}
105
+		}
106
+	}()
107
+
108
+	IsInit = true
109
+	return nil
110
+}
111
+
112
+// Interrupt an in-progress call to PollEvent by causing it to return
113
+// EventInterrupt.  Note that this function will block until the PollEvent
114
+// function has successfully been interrupted.
115
+func Interrupt() {
116
+	interrupt_comm <- struct{}{}
117
+}
118
+
119
+// Finalizes termbox library, should be called after successful initialization
120
+// when termbox's functionality isn't required anymore.
121
+func Close() {
122
+	quit <- 1
123
+	out.WriteString(funcs[t_show_cursor])
124
+	out.WriteString(funcs[t_sgr0])
125
+	out.WriteString(funcs[t_clear_screen])
126
+	out.WriteString(funcs[t_exit_ca])
127
+	out.WriteString(funcs[t_exit_keypad])
128
+	out.WriteString(funcs[t_exit_mouse])
129
+	tcsetattr(out.Fd(), &orig_tios)
130
+
131
+	out.Close()
132
+	syscall.Close(in)
133
+
134
+	// reset the state, so that on next Init() it will work again
135
+	termw = 0
136
+	termh = 0
137
+	input_mode = InputEsc
138
+	out = nil
139
+	in = 0
140
+	lastfg = attr_invalid
141
+	lastbg = attr_invalid
142
+	lastx = coord_invalid
143
+	lasty = coord_invalid
144
+	cursor_x = cursor_hidden
145
+	cursor_y = cursor_hidden
146
+	foreground = ColorDefault
147
+	background = ColorDefault
148
+	IsInit = false
149
+}
150
+
151
+// Synchronizes the internal back buffer with the terminal.
152
+func Flush() error {
153
+	// invalidate cursor position
154
+	lastx = coord_invalid
155
+	lasty = coord_invalid
156
+
157
+	update_size_maybe()
158
+
159
+	for y := 0; y < front_buffer.height; y++ {
160
+		line_offset := y * front_buffer.width
161
+		for x := 0; x < front_buffer.width; {
162
+			cell_offset := line_offset + x
163
+			back := &back_buffer.cells[cell_offset]
164
+			front := &front_buffer.cells[cell_offset]
165
+			if back.Ch < ' ' {
166
+				back.Ch = ' '
167
+			}
168
+			w := runewidth.RuneWidth(back.Ch)
169
+			if w == 0 || w == 2 && runewidth.IsAmbiguousWidth(back.Ch) {
170
+				w = 1
171
+			}
172
+			if *back == *front {
173
+				x += w
174
+				continue
175
+			}
176
+			*front = *back
177
+			send_attr(back.Fg, back.Bg)
178
+
179
+			if w == 2 && x == front_buffer.width-1 {
180
+				// there's not enough space for 2-cells rune,
181
+				// let's just put a space in there
182
+				send_char(x, y, ' ')
183
+			} else {
184
+				send_char(x, y, back.Ch)
185
+				if w == 2 {
186
+					next := cell_offset + 1
187
+					front_buffer.cells[next] = Cell{
188
+						Ch: 0,
189
+						Fg: back.Fg,
190
+						Bg: back.Bg,
191
+					}
192
+				}
193
+			}
194
+			x += w
195
+		}
196
+	}
197
+	if !is_cursor_hidden(cursor_x, cursor_y) {
198
+		write_cursor(cursor_x, cursor_y)
199
+	}
200
+	return flush()
201
+}
202
+
203
+// Sets the position of the cursor. See also HideCursor().
204
+func SetCursor(x, y int) {
205
+	if is_cursor_hidden(cursor_x, cursor_y) && !is_cursor_hidden(x, y) {
206
+		outbuf.WriteString(funcs[t_show_cursor])
207
+	}
208
+
209
+	if !is_cursor_hidden(cursor_x, cursor_y) && is_cursor_hidden(x, y) {
210
+		outbuf.WriteString(funcs[t_hide_cursor])
211
+	}
212
+
213
+	cursor_x, cursor_y = x, y
214
+	if !is_cursor_hidden(cursor_x, cursor_y) {
215
+		write_cursor(cursor_x, cursor_y)
216
+	}
217
+}
218
+
219
+// The shortcut for SetCursor(-1, -1).
220
+func HideCursor() {
221
+	SetCursor(cursor_hidden, cursor_hidden)
222
+}
223
+
224
+// Changes cell's parameters in the internal back buffer at the specified
225
+// position.
226
+func SetCell(x, y int, ch rune, fg, bg Attribute) {
227
+	if x < 0 || x >= back_buffer.width {
228
+		return
229
+	}
230
+	if y < 0 || y >= back_buffer.height {
231
+		return
232
+	}
233
+
234
+	back_buffer.cells[y*back_buffer.width+x] = Cell{ch, fg, bg}
235
+}
236
+
237
+// Returns a slice into the termbox's back buffer. You can get its dimensions
238
+// using 'Size' function. The slice remains valid as long as no 'Clear' or
239
+// 'Flush' function calls were made after call to this function.
240
+func CellBuffer() []Cell {
241
+	return back_buffer.cells
242
+}
243
+
244
+// After getting a raw event from PollRawEvent function call, you can parse it
245
+// again into an ordinary one using termbox logic. That is parse an event as
246
+// termbox would do it. Returned event in addition to usual Event struct fields
247
+// sets N field to the amount of bytes used within 'data' slice. If the length
248
+// of 'data' slice is zero or event cannot be parsed for some other reason, the
249
+// function will return a special event type: EventNone.
250
+//
251
+// IMPORTANT: EventNone may contain a non-zero N, which means you should skip
252
+// these bytes, because termbox cannot recognize them.
253
+//
254
+// NOTE: This API is experimental and may change in future.
255
+func ParseEvent(data []byte) Event {
256
+	event := Event{Type: EventKey}
257
+	ok := extract_event(data, &event)
258
+	if !ok {
259
+		return Event{Type: EventNone, N: event.N}
260
+	}
261
+	return event
262
+}
263
+
264
+// Wait for an event and return it. This is a blocking function call. Instead
265
+// of EventKey and EventMouse it returns EventRaw events. Raw event is written
266
+// into `data` slice and Event's N field is set to the amount of bytes written.
267
+// The minimum required length of the 'data' slice is 1. This requirement may
268
+// vary on different platforms.
269
+//
270
+// NOTE: This API is experimental and may change in future.
271
+func PollRawEvent(data []byte) Event {
272
+	if len(data) == 0 {
273
+		panic("len(data) >= 1 is a requirement")
274
+	}
275
+
276
+	var event Event
277
+	if extract_raw_event(data, &event) {
278
+		return event
279
+	}
280
+
281
+	for {
282
+		select {
283
+		case ev := <-input_comm:
284
+			if ev.err != nil {
285
+				return Event{Type: EventError, Err: ev.err}
286
+			}
287
+
288
+			inbuf = append(inbuf, ev.data...)
289
+			input_comm <- ev
290
+			if extract_raw_event(data, &event) {
291
+				return event
292
+			}
293
+		case <-interrupt_comm:
294
+			event.Type = EventInterrupt
295
+			return event
296
+
297
+		case <-sigwinch:
298
+			event.Type = EventResize
299
+			event.Width, event.Height = get_term_size(out.Fd())
300
+			return event
301
+		}
302
+	}
303
+}
304
+
305
+// Wait for an event and return it. This is a blocking function call.
306
+func PollEvent() Event {
307
+	var event Event
308
+
309
+	// try to extract event from input buffer, return on success
310
+	event.Type = EventKey
311
+	ok := extract_event(inbuf, &event)
312
+	if event.N != 0 {
313
+		copy(inbuf, inbuf[event.N:])
314
+		inbuf = inbuf[:len(inbuf)-event.N]
315
+	}
316
+	if ok {
317
+		return event
318
+	}
319
+
320
+	for {
321
+		select {
322
+		case ev := <-input_comm:
323
+			if ev.err != nil {
324
+				return Event{Type: EventError, Err: ev.err}
325
+			}
326
+
327
+			inbuf = append(inbuf, ev.data...)
328
+			input_comm <- ev
329
+			ok := extract_event(inbuf, &event)
330
+			if event.N != 0 {
331
+				copy(inbuf, inbuf[event.N:])
332
+				inbuf = inbuf[:len(inbuf)-event.N]
333
+			}
334
+			if ok {
335
+				return event
336
+			}
337
+		case <-interrupt_comm:
338
+			event.Type = EventInterrupt
339
+			return event
340
+
341
+		case <-sigwinch:
342
+			event.Type = EventResize
343
+			event.Width, event.Height = get_term_size(out.Fd())
344
+			return event
345
+		}
346
+	}
347
+	panic("unreachable")
348
+}
349
+
350
+// Returns the size of the internal back buffer (which is mostly the same as
351
+// terminal's window size in characters). But it doesn't always match the size
352
+// of the terminal window, after the terminal size has changed, the internal
353
+// back buffer will get in sync only after Clear or Flush function calls.
354
+func Size() (width int, height int) {
355
+	return termw, termh
356
+}
357
+
358
+// Clears the internal back buffer.
359
+func Clear(fg, bg Attribute) error {
360
+	foreground, background = fg, bg
361
+	err := update_size_maybe()
362
+	back_buffer.clear()
363
+	return err
364
+}
365
+
366
+// Sets termbox input mode. Termbox has two input modes:
367
+//
368
+// 1. Esc input mode. When ESC sequence is in the buffer and it doesn't match
369
+// any known sequence. ESC means KeyEsc. This is the default input mode.
370
+//
371
+// 2. Alt input mode. When ESC sequence is in the buffer and it doesn't match
372
+// any known sequence. ESC enables ModAlt modifier for the next keyboard event.
373
+//
374
+// Both input modes can be OR'ed with Mouse mode. Setting Mouse mode bit up will
375
+// enable mouse button press/release and drag events.
376
+//
377
+// If 'mode' is InputCurrent, returns the current input mode. See also Input*
378
+// constants.
379
+func SetInputMode(mode InputMode) InputMode {
380
+	if mode == InputCurrent {
381
+		return input_mode
382
+	}
383
+	if mode&(InputEsc|InputAlt) == 0 {
384
+		mode |= InputEsc
385
+	}
386
+	if mode&(InputEsc|InputAlt) == InputEsc|InputAlt {
387
+		mode &^= InputAlt
388
+	}
389
+	if mode&InputMouse != 0 {
390
+		out.WriteString(funcs[t_enter_mouse])
391
+	} else {
392
+		out.WriteString(funcs[t_exit_mouse])
393
+	}
394
+
395
+	input_mode = mode
396
+	return input_mode
397
+}
398
+
399
+// Sets the termbox output mode. Termbox has four output options:
400
+//
401
+// 1. OutputNormal => [1..8]
402
+//    This mode provides 8 different colors:
403
+//        black, red, green, yellow, blue, magenta, cyan, white
404
+//    Shortcut: ColorBlack, ColorRed, ...
405
+//    Attributes: AttrBold, AttrUnderline, AttrReverse
406
+//
407
+//    Example usage:
408
+//        SetCell(x, y, '@', ColorBlack | AttrBold, ColorRed);
409
+//
410
+// 2. Output256 => [1..256]
411
+//    In this mode you can leverage the 256 terminal mode:
412
+//    0x01 - 0x08: the 8 colors as in OutputNormal
413
+//    0x09 - 0x10: Color* | AttrBold
414
+//    0x11 - 0xe8: 216 different colors
415
+//    0xe9 - 0x1ff: 24 different shades of grey
416
+//
417
+//    Example usage:
418
+//        SetCell(x, y, '@', 184, 240);
419
+//        SetCell(x, y, '@', 0xb8, 0xf0);
420
+//
421
+// 3. Output216 => [1..216]
422
+//    This mode supports the 3rd range of the 256 mode only.
423
+//    But you dont need to provide an offset.
424
+//
425
+// 4. OutputGrayscale => [1..26]
426
+//    This mode supports the 4th range of the 256 mode
427
+//    and black and white colors from 3th range of the 256 mode
428
+//    But you dont need to provide an offset.
429
+//
430
+// In all modes, 0x00 represents the default color.
431
+//
432
+// `go run _demos/output.go` to see its impact on your terminal.
433
+//
434
+// If 'mode' is OutputCurrent, it returns the current output mode.
435
+//
436
+// Note that this may return a different OutputMode than the one requested,
437
+// as the requested mode may not be available on the target platform.
438
+func SetOutputMode(mode OutputMode) OutputMode {
439
+	if mode == OutputCurrent {
440
+		return output_mode
441
+	}
442
+
443
+	output_mode = mode
444
+	return output_mode
445
+}
446
+
447
+// Sync comes handy when something causes desync between termbox's understanding
448
+// of a terminal buffer and the reality. Such as a third party process. Sync
449
+// forces a complete resync between the termbox and a terminal, it may not be
450
+// visually pretty though.
451
+func Sync() error {
452
+	front_buffer.clear()
453
+	err := send_clear()
454
+	if err != nil {
455
+		return err
456
+	}
457
+
458
+	return Flush()
459
+}

+ 187
- 0
vendor/github.com/nsf/termbox-go/api_common.go View File

@@ -0,0 +1,187 @@
1
+// termbox is a library for creating cross-platform text-based interfaces
2
+package termbox
3
+
4
+// public API, common OS agnostic part
5
+
6
+type (
7
+	InputMode  int
8
+	OutputMode int
9
+	EventType  uint8
10
+	Modifier   uint8
11
+	Key        uint16
12
+	Attribute  uint16
13
+)
14
+
15
+// This type represents a termbox event. The 'Mod', 'Key' and 'Ch' fields are
16
+// valid if 'Type' is EventKey. The 'Width' and 'Height' fields are valid if
17
+// 'Type' is EventResize. The 'Err' field is valid if 'Type' is EventError.
18
+type Event struct {
19
+	Type   EventType // one of Event* constants
20
+	Mod    Modifier  // one of Mod* constants or 0
21
+	Key    Key       // one of Key* constants, invalid if 'Ch' is not 0
22
+	Ch     rune      // a unicode character
23
+	Width  int       // width of the screen
24
+	Height int       // height of the screen
25
+	Err    error     // error in case if input failed
26
+	MouseX int       // x coord of mouse
27
+	MouseY int       // y coord of mouse
28
+	N      int       // number of bytes written when getting a raw event
29
+}
30
+
31
+// A cell, single conceptual entity on the screen. The screen is basically a 2d
32
+// array of cells. 'Ch' is a unicode character, 'Fg' and 'Bg' are foreground
33
+// and background attributes respectively.
34
+type Cell struct {
35
+	Ch rune
36
+	Fg Attribute
37
+	Bg Attribute
38
+}
39
+
40
+// To know if termbox has been initialized or not
41
+var (
42
+	IsInit bool = false
43
+)
44
+
45
+// Key constants, see Event.Key field.
46
+const (
47
+	KeyF1 Key = 0xFFFF - iota
48
+	KeyF2
49
+	KeyF3
50
+	KeyF4
51
+	KeyF5
52
+	KeyF6
53
+	KeyF7
54
+	KeyF8
55
+	KeyF9
56
+	KeyF10
57
+	KeyF11
58
+	KeyF12
59
+	KeyInsert
60
+	KeyDelete
61
+	KeyHome
62
+	KeyEnd
63
+	KeyPgup
64
+	KeyPgdn
65
+	KeyArrowUp
66
+	KeyArrowDown
67
+	KeyArrowLeft
68
+	KeyArrowRight
69
+	key_min // see terminfo
70
+	MouseLeft
71
+	MouseMiddle
72
+	MouseRight
73
+	MouseRelease
74
+	MouseWheelUp
75
+	MouseWheelDown
76
+)
77
+
78
+const (
79
+	KeyCtrlTilde      Key = 0x00
80
+	KeyCtrl2          Key = 0x00
81
+	KeyCtrlSpace      Key = 0x00
82
+	KeyCtrlA          Key = 0x01
83
+	KeyCtrlB          Key = 0x02
84
+	KeyCtrlC          Key = 0x03
85
+	KeyCtrlD          Key = 0x04
86
+	KeyCtrlE          Key = 0x05
87
+	KeyCtrlF          Key = 0x06
88
+	KeyCtrlG          Key = 0x07
89
+	KeyBackspace      Key = 0x08
90
+	KeyCtrlH          Key = 0x08
91
+	KeyTab            Key = 0x09
92
+	KeyCtrlI          Key = 0x09
93
+	KeyCtrlJ          Key = 0x0A
94
+	KeyCtrlK          Key = 0x0B
95
+	KeyCtrlL          Key = 0x0C
96
+	KeyEnter          Key = 0x0D
97
+	KeyCtrlM          Key = 0x0D
98
+	KeyCtrlN          Key = 0x0E
99
+	KeyCtrlO          Key = 0x0F
100
+	KeyCtrlP          Key = 0x10
101
+	KeyCtrlQ          Key = 0x11
102
+	KeyCtrlR          Key = 0x12
103
+	KeyCtrlS          Key = 0x13
104
+	KeyCtrlT          Key = 0x14
105
+	KeyCtrlU          Key = 0x15
106
+	KeyCtrlV          Key = 0x16
107
+	KeyCtrlW          Key = 0x17
108
+	KeyCtrlX          Key = 0x18
109
+	KeyCtrlY          Key = 0x19
110
+	KeyCtrlZ          Key = 0x1A
111
+	KeyEsc            Key = 0x1B
112
+	KeyCtrlLsqBracket Key = 0x1B
113
+	KeyCtrl3          Key = 0x1B
114
+	KeyCtrl4          Key = 0x1C
115
+	KeyCtrlBackslash  Key = 0x1C
116
+	KeyCtrl5          Key = 0x1D
117
+	KeyCtrlRsqBracket Key = 0x1D
118
+	KeyCtrl6          Key = 0x1E
119
+	KeyCtrl7          Key = 0x1F
120
+	KeyCtrlSlash      Key = 0x1F
121
+	KeyCtrlUnderscore Key = 0x1F
122
+	KeySpace          Key = 0x20
123
+	KeyBackspace2     Key = 0x7F
124
+	KeyCtrl8          Key = 0x7F
125
+)
126
+
127
+// Alt modifier constant, see Event.Mod field and SetInputMode function.
128
+const (
129
+	ModAlt Modifier = 1 << iota
130
+	ModMotion
131
+)
132
+
133
+// Cell colors, you can combine a color with multiple attributes using bitwise
134
+// OR ('|').
135
+const (
136
+	ColorDefault Attribute = iota
137
+	ColorBlack
138
+	ColorRed
139
+	ColorGreen
140
+	ColorYellow
141
+	ColorBlue
142
+	ColorMagenta
143
+	ColorCyan
144
+	ColorWhite
145
+)
146
+
147
+// Cell attributes, it is possible to use multiple attributes by combining them
148
+// using bitwise OR ('|'). Although, colors cannot be combined. But you can
149
+// combine attributes and a single color.
150
+//
151
+// It's worth mentioning that some platforms don't support certain attibutes.
152
+// For example windows console doesn't support AttrUnderline. And on some
153
+// terminals applying AttrBold to background may result in blinking text. Use
154
+// them with caution and test your code on various terminals.
155
+const (
156
+	AttrBold Attribute = 1 << (iota + 9)
157
+	AttrUnderline
158
+	AttrReverse
159
+)
160
+
161
+// Input mode. See SetInputMode function.
162
+const (
163
+	InputEsc InputMode = 1 << iota
164
+	InputAlt
165
+	InputMouse
166
+	InputCurrent InputMode = 0
167
+)
168
+
169
+// Output mode. See SetOutputMode function.
170
+const (
171
+	OutputCurrent OutputMode = iota
172
+	OutputNormal
173
+	Output256
174
+	Output216
175
+	OutputGrayscale
176
+)
177
+
178
+// Event type. See Event.Type field.
179
+const (
180
+	EventKey EventType = iota
181
+	EventResize
182
+	EventMouse
183
+	EventError
184
+	EventInterrupt
185
+	EventRaw
186
+	EventNone
187
+)

+ 239
- 0
vendor/github.com/nsf/termbox-go/api_windows.go View File

@@ -0,0 +1,239 @@
1
+package termbox
2
+
3
+import (
4
+	"syscall"
5
+)
6
+
7
+// public API
8
+
9
+// Initializes termbox library. This function should be called before any other functions.
10
+// After successful initialization, the library must be finalized using 'Close' function.
11
+//
12
+// Example usage:
13
+//      err := termbox.Init()
14
+//      if err != nil {
15
+//              panic(err)
16
+//      }
17
+//      defer termbox.Close()
18
+func Init() error {
19
+	var err error
20
+
21
+	interrupt, err = create_event()
22
+	if err != nil {
23
+		return err
24
+	}
25
+
26
+	in, err = syscall.Open("CONIN$", syscall.O_RDWR, 0)
27
+	if err != nil {
28
+		return err
29
+	}
30
+	out, err = syscall.Open("CONOUT$", syscall.O_RDWR, 0)
31
+	if err != nil {
32
+		return err
33
+	}
34
+
35
+	err = get_console_mode(in, &orig_mode)
36
+	if err != nil {
37
+		return err
38
+	}
39
+
40
+	err = set_console_mode(in, enable_window_input)
41
+	if err != nil {
42
+		return err
43
+	}
44
+
45
+	orig_size = get_term_size(out)
46
+	win_size := get_win_size(out)
47
+
48
+	err = set_console_screen_buffer_size(out, win_size)
49
+	if err != nil {
50
+		return err
51
+	}
52
+
53
+	err = get_console_cursor_info(out, &orig_cursor_info)
54
+	if err != nil {
55
+		return err
56
+	}
57
+
58
+	show_cursor(false)
59
+	term_size = get_term_size(out)
60
+	back_buffer.init(int(term_size.x), int(term_size.y))
61
+	front_buffer.init(int(term_size.x), int(term_size.y))
62
+	back_buffer.clear()
63
+	front_buffer.clear()
64
+	clear()
65
+
66
+	diffbuf = make([]diff_msg, 0, 32)
67
+
68
+	go input_event_producer()
69
+	IsInit = true
70
+	return nil
71
+}
72
+
73
+// Finalizes termbox library, should be called after successful initialization
74
+// when termbox's functionality isn't required anymore.
75
+func Close() {
76
+	// we ignore errors here, because we can't really do anything about them
77
+	Clear(0, 0)
78
+	Flush()
79
+
80
+	// stop event producer
81
+	cancel_comm <- true
82
+	set_event(interrupt)
83
+	select {
84
+	case <-input_comm:
85
+	default:
86
+	}
87
+	<-cancel_done_comm
88
+
89
+	set_console_cursor_info(out, &orig_cursor_info)
90
+	set_console_cursor_position(out, coord{})
91
+	set_console_screen_buffer_size(out, orig_size)
92
+	set_console_mode(in, orig_mode)
93
+	syscall.Close(in)
94
+	syscall.Close(out)
95
+	syscall.Close(interrupt)
96
+	IsInit = false
97
+}
98
+
99
+// Interrupt an in-progress call to PollEvent by causing it to return
100
+// EventInterrupt.  Note that this function will block until the PollEvent
101
+// function has successfully been interrupted.
102
+func Interrupt() {
103
+	interrupt_comm <- struct{}{}
104
+}
105
+
106
+// Synchronizes the internal back buffer with the terminal.
107
+func Flush() error {
108
+	update_size_maybe()
109
+	prepare_diff_messages()
110
+	for _, diff := range diffbuf {
111
+		r := small_rect{
112
+			left:   0,
113
+			top:    diff.pos,
114
+			right:  term_size.x - 1,
115
+			bottom: diff.pos + diff.lines - 1,
116
+		}
117
+		write_console_output(out, diff.chars, r)
118
+	}
119
+	if !is_cursor_hidden(cursor_x, cursor_y) {
120
+		move_cursor(cursor_x, cursor_y)
121
+	}
122
+	return nil
123
+}
124
+
125
+// Sets the position of the cursor. See also HideCursor().
126
+func SetCursor(x, y int) {
127
+	if is_cursor_hidden(cursor_x, cursor_y) && !is_cursor_hidden(x, y) {
128
+		show_cursor(true)
129
+	}
130
+
131
+	if !is_cursor_hidden(cursor_x, cursor_y) && is_cursor_hidden(x, y) {
132
+		show_cursor(false)
133
+	}
134
+
135
+	cursor_x, cursor_y = x, y
136
+	if !is_cursor_hidden(cursor_x, cursor_y) {
137
+		move_cursor(cursor_x, cursor_y)
138
+	}
139
+}
140
+
141
+// The shortcut for SetCursor(-1, -1).
142
+func HideCursor() {
143
+	SetCursor(cursor_hidden, cursor_hidden)
144
+}
145
+
146
+// Changes cell's parameters in the internal back buffer at the specified
147
+// position.
148
+func SetCell(x, y int, ch rune, fg, bg Attribute) {
149
+	if x < 0 || x >= back_buffer.width {
150
+		return
151
+	}
152
+	if y < 0 || y >= back_buffer.height {
153
+		return
154
+	}
155
+
156
+	back_buffer.cells[y*back_buffer.width+x] = Cell{ch, fg, bg}
157
+}
158
+
159
+// Returns a slice into the termbox's back buffer. You can get its dimensions
160
+// using 'Size' function. The slice remains valid as long as no 'Clear' or
161
+// 'Flush' function calls were made after call to this function.
162
+func CellBuffer() []Cell {
163
+	return back_buffer.cells
164
+}
165
+
166
+// Wait for an event and return it. This is a blocking function call.
167
+func PollEvent() Event {
168
+	select {
169
+	case ev := <-input_comm:
170
+		return ev
171
+	case <-interrupt_comm:
172
+		return Event{Type: EventInterrupt}
173
+	}
174
+}
175
+
176
+// Returns the size of the internal back buffer (which is mostly the same as
177
+// console's window size in characters). But it doesn't always match the size
178
+// of the console window, after the console size has changed, the internal back
179
+// buffer will get in sync only after Clear or Flush function calls.
180
+func Size() (int, int) {
181
+	return int(term_size.x), int(term_size.y)
182
+}
183
+
184
+// Clears the internal back buffer.
185
+func Clear(fg, bg Attribute) error {
186
+	foreground, background = fg, bg
187
+	update_size_maybe()
188
+	back_buffer.clear()
189
+	return nil
190
+}
191
+
192
+// Sets termbox input mode. Termbox has two input modes:
193
+//
194
+// 1. Esc input mode. When ESC sequence is in the buffer and it doesn't match
195
+// any known sequence. ESC means KeyEsc. This is the default input mode.
196
+//
197
+// 2. Alt input mode. When ESC sequence is in the buffer and it doesn't match
198
+// any known sequence. ESC enables ModAlt modifier for the next keyboard event.
199
+//
200
+// Both input modes can be OR'ed with Mouse mode. Setting Mouse mode bit up will
201
+// enable mouse button press/release and drag events.
202
+//
203
+// If 'mode' is InputCurrent, returns the current input mode. See also Input*
204
+// constants.
205
+func SetInputMode(mode InputMode) InputMode {
206
+	if mode == InputCurrent {
207
+		return input_mode
208
+	}
209
+	if mode&InputMouse != 0 {
210
+		err := set_console_mode(in, enable_window_input|enable_mouse_input|enable_extended_flags)
211
+		if err != nil {
212
+			panic(err)
213
+		}
214
+	} else {
215
+		err := set_console_mode(in, enable_window_input)
216
+		if err != nil {
217
+			panic(err)
218
+		}
219
+	}
220
+
221
+	input_mode = mode
222
+	return input_mode
223
+}
224
+
225
+// Sets the termbox output mode.
226
+//
227
+// Windows console does not support extra colour modes,
228
+// so this will always set and return OutputNormal.
229
+func SetOutputMode(mode OutputMode) OutputMode {
230
+	return OutputNormal
231
+}
232
+
233
+// Sync comes handy when something causes desync between termbox's understanding
234
+// of a terminal buffer and the reality. Such as a third party process. Sync
235
+// forces a complete resync between the termbox and a terminal, it may not be
236
+// visually pretty though. At the moment on Windows it does nothing.
237
+func Sync() error {
238
+	return nil
239
+}

+ 110
- 0
vendor/github.com/nsf/termbox-go/collect_terminfo.py View File

@@ -0,0 +1,110 @@
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
+		yield (next(iterable), next(iterable))
73
+
74
+def do_term(term, nick):
75
+	w("// %s\n" % term)
76
+	w("var %s_keys = []string{\n\t" % nick)
77
+	for k, v in iter_pairs(keys):
78
+		w('"')
79
+		w(escaped(tput(term, v)))
80
+		w('",')
81
+	w("\n}\n")
82
+	w("var %s_funcs = []string{\n\t" % nick)
83
+	for k,v in iter_pairs(funcs):
84
+		w('"')
85
+		if v == "sgr":
86
+			w("\\033[3%d;4%dm")
87
+		elif v == "cup":
88
+			w("\\033[%d;%dH")
89
+		else:
90
+			w(escaped(tput(term, v)))
91
+		w('", ')
92
+	w("\n}\n\n")
93
+
94
+def do_terms(d):
95
+	w("var terms = []struct {\n")
96
+	w("\tname  string\n")
97
+	w("\tkeys  []string\n")
98
+	w("\tfuncs []string\n")
99
+	w("}{\n")
100
+	for k, v in d.items():
101
+		w('\t{"%s", %s_keys, %s_funcs},\n' % (k, v, v))
102
+	w("}\n\n")
103
+
104
+w("// +build !windows\n\npackage termbox\n\n")
105
+
106
+for k,v in terminals.items():
107
+	do_term(k, v)
108
+
109
+do_terms(terminals)
110
+

+ 39
- 0
vendor/github.com/nsf/termbox-go/syscalls.go View File

@@ -0,0 +1,39 @@
1
+// +build ignore
2
+
3
+package termbox
4
+
5
+/*
6
+#include <termios.h>
7
+#include <sys/ioctl.h>
8
+*/
9
+import "C"
10
+
11
+type syscall_Termios C.struct_termios
12
+
13
+const (
14
+	syscall_IGNBRK = C.IGNBRK
15
+	syscall_BRKINT = C.BRKINT
16
+	syscall_PARMRK = C.PARMRK
17
+	syscall_ISTRIP = C.ISTRIP
18
+	syscall_INLCR  = C.INLCR
19
+	syscall_IGNCR  = C.IGNCR
20
+	syscall_ICRNL  = C.ICRNL
21
+	syscall_IXON   = C.IXON
22
+	syscall_OPOST  = C.OPOST
23
+	syscall_ECHO   = C.ECHO
24
+	syscall_ECHONL = C.ECHONL
25
+	syscall_ICANON = C.ICANON
26
+	syscall_ISIG   = C.ISIG
27
+	syscall_IEXTEN = C.IEXTEN
28
+	syscall_CSIZE  = C.CSIZE
29
+	syscall_PARENB = C.PARENB
30
+	syscall_CS8    = C.CS8
31
+	syscall_VMIN   = C.VMIN
32
+	syscall_VTIME  = C.VTIME
33
+
34
+	// on darwin change these to (on *bsd too?):
35
+	// C.TIOCGETA
36
+	// C.TIOCSETA
37
+	syscall_TCGETS = C.TCGETS
38
+	syscall_TCSETS = C.TCSETS
39
+)

+ 41
- 0
vendor/github.com/nsf/termbox-go/syscalls_darwin.go View File

@@ -0,0 +1,41 @@
1
+// Created by cgo -godefs - DO NOT EDIT
2
+// cgo -godefs syscalls.go
3
+
4
+// +build !amd64
5
+
6
+package termbox
7
+
8
+type syscall_Termios struct {
9
+	Iflag  uint32
10
+	Oflag  uint32
11
+	Cflag  uint32
12
+	Lflag  uint32
13
+	Cc     [20]uint8
14
+	Ispeed uint32
15
+	Ospeed uint32
16
+}
17
+
18
+const (
19
+	syscall_IGNBRK = 0x1
20
+	syscall_BRKINT = 0x2
21
+	syscall_PARMRK = 0x8
22
+	syscall_ISTRIP = 0x20
23
+	syscall_INLCR  = 0x40
24
+	syscall_IGNCR  = 0x80
25
+	syscall_ICRNL  = 0x100
26
+	syscall_IXON   = 0x200
27
+	syscall_OPOST  = 0x1
28
+	syscall_ECHO   = 0x8
29
+	syscall_ECHONL = 0x10
30
+	syscall_ICANON = 0x100
31
+	syscall_ISIG   = 0x80
32
+	syscall_IEXTEN = 0x400
33
+	syscall_CSIZE  = 0x300
34
+	syscall_PARENB = 0x1000
35
+	syscall_CS8    = 0x300
36
+	syscall_VMIN   = 0x10
37
+	syscall_VTIME  = 0x11
38
+
39
+	syscall_TCGETS = 0x402c7413
40
+	syscall_TCSETS = 0x802c7414
41
+)

+ 40
- 0
vendor/github.com/nsf/termbox-go/syscalls_darwin_amd64.go View File

@@ -0,0 +1,40 @@
1
+// Created by cgo -godefs - DO NOT EDIT
2
+// cgo -godefs syscalls.go
3
+
4
+package termbox
5
+
6
+type syscall_Termios struct {
7
+	Iflag     uint64
8
+	Oflag     uint64
9
+	Cflag     uint64
10
+	Lflag     uint64
11
+	Cc        [20]uint8
12
+	Pad_cgo_0 [4]byte
13
+	Ispeed    uint64
14
+	Ospeed    uint64
15
+}
16
+
17
+const (
18
+	syscall_IGNBRK = 0x1
19
+	syscall_BRKINT = 0x2
20
+	syscall_PARMRK = 0x8
21
+	syscall_ISTRIP = 0x20
22
+	syscall_INLCR  = 0x40
23
+	syscall_IGNCR  = 0x80
24
+	syscall_ICRNL  = 0x100
25
+	syscall_IXON   = 0x200
26
+	syscall_OPOST  = 0x1
27
+	syscall_ECHO   = 0x8
28
+	syscall_ECHONL = 0x10
29
+	syscall_ICANON = 0x100
30
+	syscall_ISIG   = 0x80
31
+	syscall_IEXTEN = 0x400
32
+	syscall_CSIZE  = 0x300
33
+	syscall_PARENB = 0x1000
34
+	syscall_CS8    = 0x300
35
+	syscall_VMIN   = 0x10
36
+	syscall_VTIME  = 0x11
37
+
38
+	syscall_TCGETS = 0x40487413
39
+	syscall_TCSETS = 0x80487414
40
+)

+ 39
- 0
vendor/github.com/nsf/termbox-go/syscalls_freebsd.go View File

@@ -0,0 +1,39 @@
1
+// Created by cgo -godefs - DO NOT EDIT
2
+// cgo -godefs syscalls.go
3
+
4
+package termbox
5
+
6
+type syscall_Termios struct {
7
+	Iflag  uint32
8
+	Oflag  uint32
9
+	Cflag  uint32
10
+	Lflag  uint32
11
+	Cc     [20]uint8
12
+	Ispeed uint32
13
+	Ospeed uint32
14
+}
15
+
16
+const (
17
+	syscall_IGNBRK = 0x1
18
+	syscall_BRKINT = 0x2
19
+	syscall_PARMRK = 0x8
20
+	syscall_ISTRIP = 0x20
21
+	syscall_INLCR  = 0x40
22
+	syscall_IGNCR  = 0x80
23
+	syscall_ICRNL  = 0x100
24
+	syscall_IXON   = 0x200
25
+	syscall_OPOST  = 0x1
26
+	syscall_ECHO   = 0x8
27
+	syscall_ECHONL = 0x10
28
+	syscall_ICANON = 0x100
29
+	syscall_ISIG   = 0x80
30
+	syscall_IEXTEN = 0x400
31
+	syscall_CSIZE  = 0x300
32
+	syscall_PARENB = 0x1000
33
+	syscall_CS8    = 0x300
34
+	syscall_VMIN   = 0x10
35
+	syscall_VTIME  = 0x11
36
+
37
+	syscall_TCGETS = 0x402c7413
38
+	syscall_TCSETS = 0x802c7414
39
+)

+ 33
- 0
vendor/github.com/nsf/termbox-go/syscalls_linux.go View File

@@ -0,0 +1,33 @@
1
+// Created by cgo -godefs - DO NOT EDIT
2
+// cgo -godefs syscalls.go
3
+
4
+package termbox
5
+
6
+import "syscall"
7
+
8
+type syscall_Termios syscall.Termios
9
+
10
+const (
11
+	syscall_IGNBRK = syscall.IGNBRK
12
+	syscall_BRKINT = syscall.BRKINT
13
+	syscall_PARMRK = syscall.PARMRK
14
+	syscall_ISTRIP = syscall.ISTRIP
15
+	syscall_INLCR  = syscall.INLCR
16
+	syscall_IGNCR  = syscall.IGNCR
17
+	syscall_ICRNL  = syscall.ICRNL
18
+	syscall_IXON   = syscall.IXON
19
+	syscall_OPOST  = syscall.OPOST
20
+	syscall_ECHO   = syscall.ECHO
21
+	syscall_ECHONL = syscall.ECHONL
22
+	syscall_ICANON = syscall.ICANON
23
+	syscall_ISIG   = syscall.ISIG
24
+	syscall_IEXTEN = syscall.IEXTEN
25
+	syscall_CSIZE  = syscall.CSIZE
26
+	syscall_PARENB = syscall.PARENB
27
+	syscall_CS8    = syscall.CS8
28
+	syscall_VMIN   = syscall.VMIN
29
+	syscall_VTIME  = syscall.VTIME
30
+
31
+	syscall_TCGETS = syscall.TCGETS
32
+	syscall_TCSETS = syscall.TCSETS
33
+)

+ 39
- 0
vendor/github.com/nsf/termbox-go/syscalls_netbsd.go View File

@@ -0,0 +1,39 @@
1
+// Created by cgo -godefs - DO NOT EDIT
2
+// cgo -godefs syscalls.go
3
+
4
+package termbox
5
+
6
+type syscall_Termios struct {
7
+	Iflag  uint32
8
+	Oflag  uint32
9
+	Cflag  uint32
10
+	Lflag  uint32
11
+	Cc     [20]uint8
12
+	Ispeed int32
13
+	Ospeed int32
14
+}
15
+
16
+const (
17
+	syscall_IGNBRK = 0x1
18
+	syscall_BRKINT = 0x2
19
+	syscall_PARMRK = 0x8
20
+	syscall_ISTRIP = 0x20
21
+	syscall_INLCR  = 0x40
22
+	syscall_IGNCR  = 0x80
23
+	syscall_ICRNL  = 0x100
24
+	syscall_IXON   = 0x200
25
+	syscall_OPOST  = 0x1
26
+	syscall_ECHO   = 0x8
27
+	syscall_ECHONL = 0x10
28
+	syscall_ICANON = 0x100
29
+	syscall_ISIG   = 0x80
30
+	syscall_IEXTEN = 0x400
31
+	syscall_CSIZE  = 0x300
32
+	syscall_PARENB = 0x1000
33
+	syscall_CS8    = 0x300
34
+	syscall_VMIN   = 0x10
35
+	syscall_VTIME  = 0x11
36
+
37
+	syscall_TCGETS = 0x402c7413
38
+	syscall_TCSETS = 0x802c7414
39
+)

+ 39
- 0
vendor/github.com/nsf/termbox-go/syscalls_openbsd.go View File

@@ -0,0 +1,39 @@
1
+// Created by cgo -godefs - DO NOT EDIT
2
+// cgo -godefs syscalls.go
3
+
4
+package termbox
5
+
6
+type syscall_Termios struct {
7
+	Iflag  uint32
8
+	Oflag  uint32
9
+	Cflag  uint32
10
+	Lflag  uint32
11
+	Cc     [20]uint8
12
+	Ispeed int32
13
+	Ospeed int32
14
+}
15
+
16
+const (
17
+	syscall_IGNBRK = 0x1
18
+	syscall_BRKINT = 0x2
19
+	syscall_PARMRK = 0x8
20
+	syscall_ISTRIP = 0x20
21
+	syscall_INLCR  = 0x40
22
+	syscall_IGNCR  = 0x80
23
+	syscall_ICRNL  = 0x100
24
+	syscall_IXON   = 0x200
25
+	syscall_OPOST  = 0x1
26
+	syscall_ECHO   = 0x8
27
+	syscall_ECHONL = 0x10
28
+	syscall_ICANON = 0x100
29
+	syscall_ISIG   = 0x80
30
+	syscall_IEXTEN = 0x400
31
+	syscall_CSIZE  = 0x300
32
+	syscall_PARENB = 0x1000
33
+	syscall_CS8    = 0x300
34
+	syscall_VMIN   = 0x10
35
+	syscall_VTIME  = 0x11
36
+
37
+	syscall_TCGETS = 0x402c7413
38
+	syscall_TCSETS = 0x802c7414
39
+)

+ 61
- 0
vendor/github.com/nsf/termbox-go/syscalls_windows.go View File

@@ -0,0 +1,61 @@
1
+// Created by cgo -godefs - DO NOT EDIT
2
+// cgo -godefs -- -DUNICODE syscalls.go
3
+
4
+package termbox
5
+
6
+const (
7
+	foreground_blue          = 0x1
8
+	foreground_green         = 0x2
9
+	foreground_red           = 0x4
10
+	foreground_intensity     = 0x8
11
+	background_blue          = 0x10
12
+	background_green         = 0x20
13
+	background_red           = 0x40
14
+	background_intensity     = 0x80
15
+	std_input_handle         = -0xa
16
+	std_output_handle        = -0xb
17
+	key_event                = 0x1
18
+	mouse_event              = 0x2
19
+	window_buffer_size_event = 0x4
20
+	enable_window_input      = 0x8
21
+	enable_mouse_input       = 0x10
22
+	enable_extended_flags    = 0x80
23
+
24
+	vk_f1          = 0x70
25
+	vk_f2          = 0x71
26
+	vk_f3          = 0x72
27
+	vk_f4          = 0x73
28
+	vk_f5          = 0x74
29
+	vk_f6          = 0x75
30
+	vk_f7          = 0x76
31
+	vk_f8          = 0x77
32
+	vk_f9          = 0x78
33
+	vk_f10         = 0x79
34
+	vk_f11         = 0x7a
35
+	vk_f12         = 0x7b
36
+	vk_insert      = 0x2d
37
+	vk_delete      = 0x2e
38
+	vk_home        = 0x24
39
+	vk_end         = 0x23
40
+	vk_pgup        = 0x21
41
+	vk_pgdn        = 0x22
42
+	vk_arrow_up    = 0x26
43
+	vk_arrow_down  = 0x28
44
+	vk_arrow_left  = 0x25
45
+	vk_arrow_right = 0x27
46
+	vk_backspace   = 0x8
47
+	vk_tab         = 0x9
48
+	vk_enter       = 0xd
49
+	vk_esc         = 0x1b
50
+	vk_space       = 0x20
51
+
52
+	left_alt_pressed   = 0x2
53
+	left_ctrl_pressed  = 0x8
54
+	right_alt_pressed  = 0x1
55
+	right_ctrl_pressed = 0x4
56
+	shift_pressed      = 0x10
57
+
58
+	generic_read            = 0x80000000
59
+	generic_write           = 0x40000000
60
+	console_textmode_buffer = 0x1
61
+)

+ 514
- 0
vendor/github.com/nsf/termbox-go/termbox.go View File

@@ -0,0 +1,514 @@
1
+// +build !windows
2
+
3
+package termbox
4
+
5
+import "unicode/utf8"
6
+import "bytes"
7
+import "syscall"
8
+import "unsafe"
9
+import "strings"
10
+import "strconv"
11
+import "os"
12
+import "io"
13
+
14
+// private API
15
+
16
+const (
17
+	t_enter_ca = iota
18
+	t_exit_ca
19
+	t_show_cursor
20
+	t_hide_cursor
21
+	t_clear_screen
22
+	t_sgr0
23
+	t_underline
24
+	t_bold
25
+	t_blink
26
+	t_reverse
27
+	t_enter_keypad
28
+	t_exit_keypad
29
+	t_enter_mouse
30
+	t_exit_mouse
31
+	t_max_funcs
32
+)
33
+
34
+const (
35
+	coord_invalid = -2
36
+	attr_invalid  = Attribute(0xFFFF)
37
+)
38
+
39
+type input_event struct {
40
+	data []byte
41
+	err  error
42
+}
43
+
44
+var (
45
+	// term specific sequences
46
+	keys  []string
47
+	funcs []string
48
+
49
+	// termbox inner state
50
+	orig_tios      syscall_Termios
51
+	back_buffer    cellbuf
52
+	front_buffer   cellbuf
53
+	termw          int
54
+	termh          int
55
+	input_mode     = InputEsc
56
+	output_mode    = OutputNormal
57
+	out            *os.File
58
+	in             int
59
+	lastfg         = attr_invalid
60
+	lastbg         = attr_invalid
61
+	lastx          = coord_invalid
62
+	lasty          = coord_invalid
63
+	cursor_x       = cursor_hidden
64
+	cursor_y       = cursor_hidden
65
+	foreground     = ColorDefault
66
+	background     = ColorDefault
67
+	inbuf          = make([]byte, 0, 64)
68
+	outbuf         bytes.Buffer
69
+	sigwinch       = make(chan os.Signal, 1)
70
+	sigio          = make(chan os.Signal, 1)
71
+	quit           = make(chan int)
72
+	input_comm     = make(chan input_event)
73
+	interrupt_comm = make(chan struct{})
74
+	intbuf         = make([]byte, 0, 16)
75
+
76
+	// grayscale indexes
77
+	grayscale = []Attribute{
78
+		0, 17, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
79
+		245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 232,
80
+	}
81
+)
82
+
83
+func write_cursor(x, y int) {
84
+	outbuf.WriteString("\033[")
85
+	outbuf.Write(strconv.AppendUint(intbuf, uint64(y+1), 10))
86
+	outbuf.WriteString(";")
87
+	outbuf.Write(strconv.AppendUint(intbuf, uint64(x+1), 10))
88
+	outbuf.WriteString("H")
89
+}
90
+
91
+func write_sgr_fg(a Attribute) {
92
+	switch output_mode {
93
+	case Output256, Output216, OutputGrayscale:
94
+		outbuf.WriteString("\033[38;5;")
95
+		outbuf.Write(strconv.AppendUint(intbuf, uint64(a-1), 10))
96
+		outbuf.WriteString("m")
97
+	default:
98
+		outbuf.WriteString("\033[3")
99
+		outbuf.Write(strconv.AppendUint(intbuf, uint64(a-1), 10))
100
+		outbuf.WriteString("m")
101
+	}
102
+}
103
+
104
+func write_sgr_bg(a Attribute) {
105
+	switch output_mode {
106
+	case Output256, Output216, OutputGrayscale:
107
+		outbuf.WriteString("\033[48;5;")
108
+		outbuf.Write(strconv.AppendUint(intbuf, uint64(a-1), 10))
109
+		outbuf.WriteString("m")
110
+	default:
111
+		outbuf.WriteString("\033[4")
112
+		outbuf.Write(strconv.AppendUint(intbuf, uint64(a-1), 10))
113
+		outbuf.WriteString("m")
114
+	}
115
+}
116
+
117
+func write_sgr(fg, bg Attribute) {
118
+	switch output_mode {
119
+	case Output256, Output216, OutputGrayscale:
120
+		outbuf.WriteString("\033[38;5;")
121
+		outbuf.Write(strconv.AppendUint(intbuf, uint64(fg-1), 10))
122
+		outbuf.WriteString("m")
123
+		outbuf.WriteString("\033[48;5;")
124
+		outbuf.Write(strconv.AppendUint(intbuf, uint64(bg-1), 10))
125
+		outbuf.WriteString("m")
126
+	default:
127
+		outbuf.WriteString("\033[3")
128
+		outbuf.Write(strconv.AppendUint(intbuf, uint64(fg-1), 10))
129
+		outbuf.WriteString(";4")
130
+		outbuf.Write(strconv.AppendUint(intbuf, uint64(bg-1), 10))
131
+		outbuf.WriteString("m")
132
+	}
133
+}
134
+
135
+type winsize struct {
136
+	rows    uint16
137
+	cols    uint16
138
+	xpixels uint16
139
+	ypixels uint16
140
+}
141
+
142
+func get_term_size(fd uintptr) (int, int) {
143
+	var sz winsize
144
+	_, _, _ = syscall.Syscall(syscall.SYS_IOCTL,
145
+		fd, uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&sz)))
146
+	return int(sz.cols), int(sz.rows)
147
+}
148
+
149
+func send_attr(fg, bg Attribute) {
150
+	if fg == lastfg && bg == lastbg {
151
+		return
152
+	}
153
+
154
+	outbuf.WriteString(funcs[t_sgr0])
155
+
156
+	var fgcol, bgcol Attribute
157
+
158
+	switch output_mode {
159
+	case Output256:
160
+		fgcol = fg & 0x1FF
161
+		bgcol = bg & 0x1FF
162
+	case Output216:
163
+		fgcol = fg & 0xFF
164
+		bgcol = bg & 0xFF
165
+		if fgcol > 216 {
166
+			fgcol = ColorDefault
167
+		}
168
+		if bgcol > 216 {
169
+			bgcol = ColorDefault
170
+		}
171
+		if fgcol != ColorDefault {
172
+			fgcol += 0x10
173
+		}
174
+		if bgcol != ColorDefault {
175
+			bgcol += 0x10
176
+		}
177
+	case OutputGrayscale:
178
+		fgcol = fg & 0x1F
179
+		bgcol = bg & 0x1F
180
+		if fgcol > 26 {
181
+			fgcol = ColorDefault
182
+		}
183
+		if bgcol > 26 {
184
+			bgcol = ColorDefault
185
+		}
186
+		if fgcol != ColorDefault {
187
+			fgcol = grayscale[fgcol]
188
+		}
189
+		if bgcol != ColorDefault {
190
+			bgcol = grayscale[bgcol]
191
+		}
192
+	default:
193
+		fgcol = fg & 0x0F
194
+		bgcol = bg & 0x0F
195
+	}
196
+
197
+	if fgcol != ColorDefault {
198
+		if bgcol != ColorDefault {
199
+			write_sgr(fgcol, bgcol)
200
+		} else {
201
+			write_sgr_fg(fgcol)
202
+		}
203
+	} else if bgcol != ColorDefault {
204
+		write_sgr_bg(bgcol)
205
+	}
206
+
207
+	if fg&AttrBold != 0 {
208
+		outbuf.WriteString(funcs[t_bold])
209
+	}
210
+	if bg&AttrBold != 0 {
211
+		outbuf.WriteString(funcs[t_blink])
212
+	}
213
+	if fg&AttrUnderline != 0 {
214
+		outbuf.WriteString(funcs[t_underline])
215
+	}
216
+	if fg&AttrReverse|bg&AttrReverse != 0 {
217
+		outbuf.WriteString(funcs[t_reverse])
218
+	}
219
+
220
+	lastfg, lastbg = fg, bg
221
+}
222
+
223
+func send_char(x, y int, ch rune) {
224
+	var buf [8]byte
225
+	n := utf8.EncodeRune(buf[:], ch)
226
+	if x-1 != lastx || y != lasty {
227
+		write_cursor(x, y)
228
+	}
229
+	lastx, lasty = x, y
230
+	outbuf.Write(buf[:n])
231
+}
232
+
233
+func flush() error {
234
+	_, err := io.Copy(out, &outbuf)
235
+	outbuf.Reset()
236
+	if err != nil {
237
+		return err
238
+	}
239
+	return nil
240
+}
241
+
242
+func send_clear() error {
243
+	send_attr(foreground, background)
244
+	outbuf.WriteString(funcs[t_clear_screen])
245
+	if !is_cursor_hidden(cursor_x, cursor_y) {
246
+		write_cursor(cursor_x, cursor_y)
247
+	}
248
+
249
+	// we need to invalidate cursor position too and these two vars are
250
+	// used only for simple cursor positioning optimization, cursor
251
+	// actually may be in the correct place, but we simply discard
252
+	// optimization once and it gives us simple solution for the case when
253
+	// cursor moved
254
+	lastx = coord_invalid
255
+	lasty = coord_invalid
256
+
257
+	return flush()
258
+}
259
+
260
+func update_size_maybe() error {
261
+	w, h := get_term_size(out.Fd())
262
+	if w != termw || h != termh {
263
+		termw, termh = w, h
264
+		back_buffer.resize(termw, termh)
265
+		front_buffer.resize(termw, termh)
266
+		front_buffer.clear()
267
+		return send_clear()
268
+	}
269
+	return nil
270
+}
271
+
272
+func tcsetattr(fd uintptr, termios *syscall_Termios) error {
273
+	r, _, e := syscall.Syscall(syscall.SYS_IOCTL,
274
+		fd, uintptr(syscall_TCSETS), uintptr(unsafe.Pointer(termios)))
275
+	if r != 0 {
276
+		return os.NewSyscallError("SYS_IOCTL", e)
277
+	}
278
+	return nil
279
+}
280
+
281
+func tcgetattr(fd uintptr, termios *syscall_Termios) error {
282
+	r, _, e := syscall.Syscall(syscall.SYS_IOCTL,
283
+		fd, uintptr(syscall_TCGETS), uintptr(unsafe.Pointer(termios)))
284
+	if r != 0 {
285
+		return os.NewSyscallError("SYS_IOCTL", e)
286
+	}
287
+	return nil
288
+}
289
+
290
+func parse_mouse_event(event *Event, buf string) (int, bool) {
291
+	if strings.HasPrefix(buf, "\033[M") && len(buf) >= 6 {
292
+		// X10 mouse encoding, the simplest one
293
+		// \033 [ M Cb Cx Cy
294
+		b := buf[3] - 32
295
+		switch b & 3 {
296
+		case 0:
297
+			if b&64 != 0 {
298
+				event.Key = MouseWheelUp
299
+			} else {
300
+				event.Key = MouseLeft
301
+			}
302
+		case 1:
303
+			if b&64 != 0 {
304
+				event.Key = MouseWheelDown
305
+			} else {
306
+				event.Key = MouseMiddle
307
+			}
308
+		case 2:
309
+			event.Key = MouseRight
310
+		case 3:
311
+			event.Key = MouseRelease
312
+		default:
313
+			return 6, false
314
+		}
315
+		event.Type = EventMouse // KeyEvent by default
316
+		if b&32 != 0 {
317
+			event.Mod |= ModMotion
318
+		}
319
+
320
+		// the coord is 1,1 for upper left
321
+		event.MouseX = int(buf[4]) - 1 - 32
322
+		event.MouseY = int(buf[5]) - 1 - 32
323
+		return 6, true
324
+	} else if strings.HasPrefix(buf, "\033[<") || strings.HasPrefix(buf, "\033[") {
325
+		// xterm 1006 extended mode or urxvt 1015 extended mode
326
+		// xterm: \033 [ < Cb ; Cx ; Cy (M or m)
327
+		// urxvt: \033 [ Cb ; Cx ; Cy M
328
+
329
+		// find the first M or m, that's where we stop
330
+		mi := strings.IndexAny(buf, "Mm")
331
+		if mi == -1 {
332
+			return 0, false
333
+		}
334
+
335
+		// whether it's a capital M or not
336
+		isM := buf[mi] == 'M'
337
+
338
+		// whether it's urxvt or not
339
+		isU := false
340
+
341
+		// buf[2] is safe here, because having M or m found means we have at
342
+		// least 3 bytes in a string
343
+		if buf[2] == '<' {
344
+			buf = buf[3:mi]
345
+		} else {
346
+			isU = true
347
+			buf = buf[2:mi]
348
+		}
349
+
350
+		s1 := strings.Index(buf, ";")
351
+		s2 := strings.LastIndex(buf, ";")
352
+		// not found or only one ';'
353
+		if s1 == -1 || s2 == -1 || s1 == s2 {
354
+			return 0, false
355
+		}
356
+
357
+		n1, err := strconv.ParseInt(buf[0:s1], 10, 64)
358
+		if err != nil {
359
+			return 0, false
360
+		}
361
+		n2, err := strconv.ParseInt(buf[s1+1:s2], 10, 64)
362
+		if err != nil {
363
+			return 0, false
364
+		}
365
+		n3, err := strconv.ParseInt(buf[s2+1:], 10, 64)
366
+		if err != nil {
367
+			return 0, false
368
+		}
369
+
370
+		// on urxvt, first number is encoded exactly as in X10, but we need to
371
+		// make it zero-based, on xterm it is zero-based already
372
+		if isU {
373
+			n1 -= 32