urwid 2.6.0.post0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of urwid might be problematic. Click here for more details.

Files changed (75) hide show
  1. urwid/__init__.py +333 -0
  2. urwid/canvas.py +1413 -0
  3. urwid/command_map.py +137 -0
  4. urwid/container.py +59 -0
  5. urwid/decoration.py +65 -0
  6. urwid/display/__init__.py +97 -0
  7. urwid/display/_posix_raw_display.py +413 -0
  8. urwid/display/_raw_display_base.py +914 -0
  9. urwid/display/_web.css +12 -0
  10. urwid/display/_web.js +462 -0
  11. urwid/display/_win32.py +171 -0
  12. urwid/display/_win32_raw_display.py +269 -0
  13. urwid/display/common.py +1219 -0
  14. urwid/display/curses.py +690 -0
  15. urwid/display/escape.py +624 -0
  16. urwid/display/html_fragment.py +251 -0
  17. urwid/display/lcd.py +518 -0
  18. urwid/display/raw.py +37 -0
  19. urwid/display/web.py +636 -0
  20. urwid/event_loop/__init__.py +55 -0
  21. urwid/event_loop/abstract_loop.py +175 -0
  22. urwid/event_loop/asyncio_loop.py +231 -0
  23. urwid/event_loop/glib_loop.py +294 -0
  24. urwid/event_loop/main_loop.py +721 -0
  25. urwid/event_loop/select_loop.py +230 -0
  26. urwid/event_loop/tornado_loop.py +206 -0
  27. urwid/event_loop/trio_loop.py +302 -0
  28. urwid/event_loop/twisted_loop.py +269 -0
  29. urwid/event_loop/zmq_loop.py +275 -0
  30. urwid/font.py +695 -0
  31. urwid/graphics.py +96 -0
  32. urwid/highlight.css +19 -0
  33. urwid/listbox.py +1899 -0
  34. urwid/monitored_list.py +522 -0
  35. urwid/numedit.py +376 -0
  36. urwid/signals.py +330 -0
  37. urwid/split_repr.py +130 -0
  38. urwid/str_util.py +358 -0
  39. urwid/text_layout.py +632 -0
  40. urwid/treetools.py +515 -0
  41. urwid/util.py +557 -0
  42. urwid/version.py +16 -0
  43. urwid/vterm.py +1806 -0
  44. urwid/widget/__init__.py +181 -0
  45. urwid/widget/attr_map.py +161 -0
  46. urwid/widget/attr_wrap.py +140 -0
  47. urwid/widget/bar_graph.py +649 -0
  48. urwid/widget/big_text.py +77 -0
  49. urwid/widget/box_adapter.py +126 -0
  50. urwid/widget/columns.py +1145 -0
  51. urwid/widget/constants.py +574 -0
  52. urwid/widget/container.py +227 -0
  53. urwid/widget/divider.py +110 -0
  54. urwid/widget/edit.py +718 -0
  55. urwid/widget/filler.py +403 -0
  56. urwid/widget/frame.py +539 -0
  57. urwid/widget/grid_flow.py +539 -0
  58. urwid/widget/line_box.py +194 -0
  59. urwid/widget/overlay.py +829 -0
  60. urwid/widget/padding.py +597 -0
  61. urwid/widget/pile.py +971 -0
  62. urwid/widget/popup.py +170 -0
  63. urwid/widget/progress_bar.py +141 -0
  64. urwid/widget/scrollable.py +597 -0
  65. urwid/widget/solid_fill.py +44 -0
  66. urwid/widget/text.py +354 -0
  67. urwid/widget/widget.py +852 -0
  68. urwid/widget/widget_decoration.py +166 -0
  69. urwid/widget/wimp.py +792 -0
  70. urwid/wimp.py +23 -0
  71. urwid-2.6.0.post0.dist-info/COPYING +504 -0
  72. urwid-2.6.0.post0.dist-info/METADATA +332 -0
  73. urwid-2.6.0.post0.dist-info/RECORD +75 -0
  74. urwid-2.6.0.post0.dist-info/WHEEL +5 -0
  75. urwid-2.6.0.post0.dist-info/top_level.txt +1 -0
urwid/display/_web.css ADDED
@@ -0,0 +1,12 @@
1
+ body { margin: 8px 8px 8px 8px; border: 0;
2
+ color: black; background-color: silver;
3
+ font-family: fixed; overflow: hidden; }
4
+
5
+ form { margin: 0 0 8px 0; }
6
+
7
+ #text { position: relative;
8
+ background-color: silver;
9
+ width: 100%; height: 100%;
10
+ margin: 3px 0 0 0; border: 1px solid #999; }
11
+
12
+ #page { position: relative; width: 100%;height: 100%;}
urwid/display/_web.js ADDED
@@ -0,0 +1,462 @@
1
+ // Urwid web (CGI/Asynchronous Javascript) display module
2
+ // Copyright (C) 2004-2005 Ian Ward
3
+ //
4
+ // This library is free software; you can redistribute it and/or
5
+ // modify it under the terms of the GNU Lesser General Public
6
+ // License as published by the Free Software Foundation; either
7
+ // version 2.1 of the License, or (at your option) any later version.
8
+ //
9
+ // This library is distributed in the hope that it will be useful,
10
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ // Lesser General Public License for more details.
13
+ //
14
+ // You should have received a copy of the GNU Lesser General Public
15
+ // License along with this library; if not, write to the Free Software
16
+ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+ //
18
+ // Urwid web site: https://urwid.org/
19
+
20
+ colours = new Object();
21
+ colours = {
22
+ '0': "black",
23
+ '1': "#c00000",
24
+ '2': "green",
25
+ '3': "#804000",
26
+ '4': "#0000c0",
27
+ '5': "#c000c0",
28
+ '6': "teal",
29
+ '7': "silver",
30
+ '8': "gray",
31
+ '9': "#ff6060",
32
+ 'A': "lime",
33
+ 'B': "yellow",
34
+ 'C': "#8080ff",
35
+ 'D': "#ff40ff",
36
+ 'E': "aqua",
37
+ 'F': "white"
38
+ };
39
+
40
+ keycodes = new Object();
41
+ keycodes = {
42
+ 8: "backspace", 9: "tab", 13: "enter", 27: "esc",
43
+ 33: "page up", 34: "page down", 35: "end", 36: "home",
44
+ 37: "left", 38: "up", 39: "right", 40: "down",
45
+ 45: "insert", 46: "delete",
46
+ 112: "f1", 113: "f2", 114: "f3", 115: "f4",
47
+ 116: "f5", 117: "f6", 118: "f7", 119: "f8",
48
+ 120: "f9", 121: "f10", 122: "f11", 123: "f12"
49
+ };
50
+
51
+ var conn = null;
52
+ var char_width = null;
53
+ var char_height = null;
54
+ var screen_x = null;
55
+ var screen_y = null;
56
+
57
+ var urwid_id = null;
58
+ var send_conn = null;
59
+ var send_queue_max = 32;
60
+ var send_queue = new Array(send_queue_max);
61
+ var send_queue_in = 0;
62
+ var send_queue_out = 0;
63
+
64
+ var check_font_delay = 1000;
65
+ var send_more_delay = 100;
66
+ var poll_again_delay = 500;
67
+
68
+ var document_location = null;
69
+
70
+ var update_method = "multipart";
71
+
72
+ var sending = false;
73
+ var lastkeydown = null;
74
+
75
+ function setup_connection() {
76
+ if (window.XMLHttpRequest) {
77
+ conn = new XMLHttpRequest();
78
+ } else if (window.ActiveXObject) {
79
+ conn = new ActiveXObject("Microsoft.XMLHTTP");
80
+ }
81
+
82
+ if (conn == null) {
83
+ set_status("Connection Failed");
84
+ alert( "Can't figure out how to send request." );
85
+ return;
86
+ }
87
+ try{
88
+ conn.multipart = true;
89
+ }catch(e){
90
+ update_method = "polling";
91
+ }
92
+ conn.onreadystatechange = handle_recv;
93
+ conn.open("POST", document_location, true);
94
+ conn.setRequestHeader("X-Urwid-Method",update_method);
95
+ conn.setRequestHeader("Content-type","text/plain");
96
+ conn.send("window resize " +screen_x+" "+screen_y+"\n");
97
+ }
98
+
99
+ function do_poll() {
100
+ if (urwid_id == null){
101
+ alert("that's unpossible!");
102
+ return;
103
+ }
104
+ if (window.XMLHttpRequest) {
105
+ conn = new XMLHttpRequest();
106
+ } else if (window.ActiveXObject) {
107
+ conn = new ActiveXObject("Microsoft.XMLHTTP");
108
+ }
109
+ conn.onreadystatechange = handle_recv;
110
+ conn.open("POST", document_location, true);
111
+ conn.setRequestHeader("X-Urwid-Method","polling");
112
+ conn.setRequestHeader("X-Urwid-ID",urwid_id);
113
+ conn.setRequestHeader("Content-type","text/plain");
114
+ conn.send("eh?");
115
+ }
116
+
117
+ function handle_recv() {
118
+ if( ! conn ){ return;}
119
+ if( conn.readyState != 4) {
120
+ return;
121
+ }
122
+ if( conn.status == 404 && urwid_id != null) {
123
+ set_status("Connection Closed");
124
+ return;
125
+ }
126
+ if( conn.status == 403 && update_method == "polling" ) {
127
+ set_status("Server Refused Connection");
128
+ alert("This server does not allow polling clients.\n\n" +
129
+ "Please use a web browser with multipart support " +
130
+ "such as Mozilla Firefox");
131
+ return;
132
+ }
133
+ if( conn.status == 503 ) {
134
+ set_status("Connection Failed");
135
+ alert("The server has reached its maximum number of "+
136
+ "connections.\n\nPlease try again later.");
137
+ return;
138
+ }
139
+ if( conn.status != 200) {
140
+ set_status("Connection Failed");
141
+ alert("Error from server: "+conn.statusText);
142
+ return;
143
+ }
144
+ if( urwid_id == null ){
145
+ urwid_id = conn.getResponseHeader("X-Urwid-ID");
146
+ if( send_queue_in != send_queue_out ){
147
+ // keys waiting
148
+ do_send();
149
+ }
150
+ if(update_method=="polling"){
151
+ set_status("Polling");
152
+ }else if(update_method=="multipart"){
153
+ set_status("Connected");
154
+ }
155
+
156
+ }
157
+
158
+ if( conn.responseText == "" ){
159
+ if(update_method=="polling"){
160
+ poll_again();
161
+ }
162
+ return; // keepalive
163
+ }
164
+ if( conn.responseText == "Z" ){
165
+ set_status("Connection Closed");
166
+ update_method = null;
167
+ return;
168
+ }
169
+
170
+ var text = document.getElementById('text');
171
+
172
+ var last_screen = Array(text.childNodes.length);
173
+ for( var i=0; i<text.childNodes.length; i++ ){
174
+ last_screen[i] = text.childNodes[i];
175
+ }
176
+
177
+ var frags = conn.responseText.split("\n");
178
+ var ln = document.createElement('span');
179
+ var k = 0;
180
+ for( var i=0; i<frags.length; i++ ){
181
+ var f = frags[i];
182
+ if( f == "" ){
183
+ var br = document.getElementById('br').cloneNode(true);
184
+ ln.appendChild( br );
185
+ if( text.childNodes.length > k ){
186
+ text.replaceChild(ln, text.childNodes[k]);
187
+ }else{
188
+ text.appendChild(ln);
189
+ }
190
+ k = k+1;
191
+ ln = document.createElement('span');
192
+ }else if( f.charAt(0) == "<" ){
193
+ line_number = parseInt(f.substr(1));
194
+ if( line_number == k ){
195
+ k = k +1;
196
+ continue;
197
+ }
198
+ var clone = last_screen[line_number].cloneNode(true);
199
+ if( text.childNodes.length > k ){
200
+ text.replaceChild(clone, text.childNodes[k]);
201
+ }else{
202
+ text.appendChild(clone);
203
+ }
204
+ k = k+1;
205
+ }else{
206
+ var span=make_span(f.substr(2),f.charAt(0),f.charAt(1));
207
+ ln.appendChild( span );
208
+ }
209
+ }
210
+ for( var i=k; i < text.childNodes.length; i++ ){
211
+ text.removeChild(last_screen[i]);
212
+ }
213
+
214
+ if(update_method=="polling"){
215
+ poll_again();
216
+ }
217
+ }
218
+
219
+ function poll_again(){
220
+ if(conn.status == 200){
221
+ setTimeout("do_poll();",poll_again_delay);
222
+ }
223
+ }
224
+
225
+
226
+ function load_web_display(){
227
+ if( document.documentURI ){
228
+ document_location = document.documentURI;
229
+ }else{
230
+ document_location = document.location;
231
+ }
232
+
233
+ document.onkeypress = body_keypress;
234
+ document.onkeydown = body_keydown;
235
+ document.onresize = body_resize;
236
+
237
+ body_resize();
238
+ send_queue_out = send_queue_in; // don't queue the first resize
239
+
240
+ set_status("Connecting");
241
+ setup_connection();
242
+
243
+ setTimeout("check_fontsize();",check_font_delay);
244
+ }
245
+
246
+ function set_status( status ){
247
+ var s = document.getElementById('status');
248
+ var t = document.createTextNode(status);
249
+ s.replaceChild(t, s.firstChild);
250
+ }
251
+
252
+ function make_span(s, fg, bg){
253
+ d = document.createElement('span');
254
+ d.style.backgroundColor = colours[bg];
255
+ d.style.color = colours[fg];
256
+ d.appendChild(document.createTextNode(s));
257
+
258
+ return d;
259
+ }
260
+
261
+ function body_keydown(e){
262
+ if (conn == null){
263
+ return;
264
+ }
265
+ if (!e) var e = window.event;
266
+ if (e.keyCode) code = e.keyCode;
267
+ else if (e.which) code = e.which;
268
+
269
+ var mod = "";
270
+ var key;
271
+
272
+ if( e.ctrlKey ){ mod = "ctrl " + mod; }
273
+ if( e.altKey || e.metaKey ){ mod = "meta " + mod; }
274
+ if( e.shiftKey && e.charCode == 0 ){ mod = "shift " + mod; }
275
+
276
+ key = keycodes[code];
277
+
278
+ if( key != undefined ){
279
+ lastkeydown = key;
280
+ send_key( mod + key );
281
+ stop_key_event(e);
282
+ return false;
283
+ }
284
+ }
285
+
286
+ function body_keypress(e){
287
+ if (conn == null){
288
+ return;
289
+ }
290
+
291
+ if (!e) var e = window.event;
292
+ if (e.keyCode) code = e.keyCode;
293
+ else if (e.which) code = e.which;
294
+
295
+ var mod = "";
296
+ var key;
297
+
298
+ if( e.ctrlKey ){ mod = "ctrl " + mod; }
299
+ if( e.altKey || e.metaKey ){ mod = "meta " + mod; }
300
+ if( e.shiftKey && e.charCode == 0 ){ mod = "shift " + mod; }
301
+
302
+ if( e.charCode != null && e.charCode != 0 ){
303
+ key = String.fromCharCode(e.charCode);
304
+ }else if( e.charCode == null ){
305
+ key = String.fromCharCode(code);
306
+ }else{
307
+ key = keycodes[code];
308
+ if( key == undefined || lastkeydown == key ){
309
+ lastkeydown = null;
310
+ stop_key_event(e);
311
+ return false;
312
+ }
313
+ }
314
+
315
+ send_key( mod + key );
316
+ stop_key_event(e);
317
+ return false;
318
+ }
319
+
320
+ function stop_key_event(e){
321
+ e.cancelBubble = true;
322
+ if( e.stopPropagation ){
323
+ e.stopPropagation();
324
+ }
325
+ if( e.preventDefault ){
326
+ e.preventDefault();
327
+ }
328
+ }
329
+
330
+ function send_key( key ){
331
+ if( (send_queue_in+1)%send_queue_max == send_queue_out ){
332
+ // buffer overrun
333
+ return;
334
+ }
335
+ send_queue[send_queue_in] = key;
336
+ send_queue_in = (send_queue_in+1)%send_queue_max;
337
+
338
+ if( urwid_id != null ){
339
+ if (send_conn == undefined || send_conn.ready_state != 4 ){
340
+ send_more();
341
+ return;
342
+ }
343
+ do_send();
344
+ }
345
+ }
346
+
347
+ function do_send() {
348
+ if( ! urwid_id ){ return; }
349
+ if( ! update_method ){ return; } // connection closed
350
+ if( send_queue_in == send_queue_out ){ return; }
351
+ if( sending ){
352
+ //var queue_delta = send_queue_in - send_queue_out;
353
+ //if( queue_delta < 0 ){ queue_delta += send_queue_max; }
354
+ //set_status("Sending (queued "+queue_delta+")");
355
+ return;
356
+ }
357
+ try{
358
+ sending = true;
359
+ //set_status("starting send");
360
+ if( send_conn == null ){
361
+ if (window.XMLHttpRequest) {
362
+ send_conn = new XMLHttpRequest();
363
+ } else if (window.ActiveXObject) {
364
+ send_conn = new ActiveXObject("Microsoft.XMLHTTP");
365
+ }
366
+ }else if( send_conn.status != 200) {
367
+ alert("Error from server: "+send_conn.statusText);
368
+ return;
369
+ }else if(send_conn.readyState != 4 ){
370
+ alert("not ready on send connection");
371
+ return;
372
+ }
373
+ } catch(e) {
374
+ alert(e);
375
+ sending = false;
376
+ return;
377
+ }
378
+ send_conn.open("POST", document_location, true);
379
+ send_conn.onreadystatechange = send_handle_recv;
380
+ send_conn.setRequestHeader("Content-type","text/plain");
381
+ send_conn.setRequestHeader("X-Urwid-ID",urwid_id);
382
+ var tmp_send_queue_in = send_queue_in;
383
+ var out = null;
384
+ if( send_queue_out > tmp_send_queue_in ){
385
+ out = send_queue.slice(send_queue_out).join("\n")
386
+ if( tmp_send_queue_in > 0 ){
387
+ out += "\n" + send_queue.slice(0,tmp_send_queue_in).join("\n");
388
+ }
389
+ }else{
390
+ out = send_queue.slice(send_queue_out,
391
+ tmp_send_queue_in).join("\n");
392
+ }
393
+ send_queue_out = tmp_send_queue_in;
394
+ //set_status("Sending");
395
+ send_conn.send( out +"\n" );
396
+ }
397
+
398
+ function send_handle_recv() {
399
+ if( send_conn.readyState != 4) {
400
+ return;
401
+ }
402
+ if( send_conn.status == 404) {
403
+ set_status("Connection Closed");
404
+ update_method = null;
405
+ return;
406
+ }
407
+ if( send_conn.status != 200) {
408
+ alert("Error from server: "+send_conn.statusText);
409
+ return;
410
+ }
411
+
412
+ sending = false;
413
+
414
+ if( send_queue_out != send_queue_in ){
415
+ send_more();
416
+ }
417
+ }
418
+
419
+ function send_more(){
420
+ setTimeout("do_send();",send_more_delay);
421
+ }
422
+
423
+ function check_fontsize(){
424
+ body_resize()
425
+ setTimeout("check_fontsize();",check_font_delay);
426
+ }
427
+
428
+ function body_resize(){
429
+ var t = document.getElementById('testchar');
430
+ var t2 = document.getElementById('testchar2');
431
+ var text = document.getElementById('text');
432
+
433
+ var window_width;
434
+ var window_height;
435
+ if (window.innerHeight) {
436
+ window_width = window.innerWidth;
437
+ window_height = window.innerHeight;
438
+ }else{
439
+ window_width = document.documentElement.clientWidth;
440
+ window_height = document.documentElement.clientHeight;
441
+ //var z = "CI:"; for(var i in bod){z = z + " " + i;} alert(z);
442
+ }
443
+
444
+ char_width = t.offsetLeft / 44;
445
+ var avail_width = window_width-18;
446
+ var avail_width_mod = avail_width % char_width;
447
+ var x_size = (avail_width - avail_width_mod)/char_width;
448
+
449
+ char_height = t2.offsetTop - t.offsetTop;
450
+ var avail_height = window_height-text.offsetTop-10;
451
+ var avail_height_mod = avail_height % char_height;
452
+ var y_size = (avail_height - avail_height_mod)/char_height;
453
+
454
+ text.style.width = x_size*char_width+"px";
455
+ text.style.height = y_size*char_height+"px";
456
+
457
+ if( screen_x != x_size || screen_y != y_size ){
458
+ send_key("window resize "+x_size+" "+y_size);
459
+ }
460
+ screen_x = x_size;
461
+ screen_y = y_size;
462
+ }
@@ -0,0 +1,171 @@
1
+ from __future__ import annotations
2
+
3
+ import enum
4
+ import typing
5
+ from ctypes import POINTER, Structure, Union, windll
6
+ from ctypes.wintypes import BOOL, CHAR, DWORD, HANDLE, LPDWORD, SHORT, UINT, WCHAR, WORD
7
+
8
+ # https://docs.microsoft.com/de-de/windows/console/getstdhandle
9
+ STD_INPUT_HANDLE = -10
10
+ STD_OUTPUT_HANDLE = -11
11
+
12
+ # https://docs.microsoft.com/de-de/windows/console/setconsolemode
13
+ ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004
14
+ DISABLE_NEWLINE_AUTO_RETURN = 0x0008
15
+ ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200
16
+ ENABLE_WINDOW_INPUT = 0x0008
17
+
18
+
19
+ class COORD(Structure):
20
+ """https://docs.microsoft.com/en-us/windows/console/coord-str"""
21
+
22
+ _fields_: typing.ClassVar[list[tuple[str, type]]] = [
23
+ ("X", SHORT),
24
+ ("Y", SHORT),
25
+ ]
26
+
27
+
28
+ class SMALL_RECT(Structure):
29
+ """https://docs.microsoft.com/en-us/windows/console/small-rect-str"""
30
+
31
+ _fields_: typing.ClassVar[list[tuple[str, type]]] = [
32
+ ("Left", SHORT),
33
+ ("Top", SHORT),
34
+ ("Right", SHORT),
35
+ ("Bottom", SHORT),
36
+ ]
37
+
38
+
39
+ class CONSOLE_SCREEN_BUFFER_INFO(Structure):
40
+ """https://docs.microsoft.com/en-us/windows/console/console-screen-buffer-info-str"""
41
+
42
+ _fields_: typing.ClassVar[list[tuple[str, type]]] = [
43
+ ("dwSize", COORD),
44
+ ("dwCursorPosition", COORD),
45
+ ("wAttributes", WORD),
46
+ ("srWindow", SMALL_RECT),
47
+ ("dwMaximumWindowSize", COORD),
48
+ ]
49
+
50
+
51
+ class uChar(Union):
52
+ """https://docs.microsoft.com/en-us/windows/console/key-event-record-str"""
53
+
54
+ _fields_: typing.ClassVar[list[tuple[str, type]]] = [
55
+ ("AsciiChar", CHAR),
56
+ ("UnicodeChar", WCHAR),
57
+ ]
58
+
59
+
60
+ class KEY_EVENT_RECORD(Structure):
61
+ """https://docs.microsoft.com/en-us/windows/console/key-event-record-str"""
62
+
63
+ _fields_: typing.ClassVar[list[tuple[str, type]]] = [
64
+ ("bKeyDown", BOOL),
65
+ ("wRepeatCount", WORD),
66
+ ("wVirtualKeyCode", WORD),
67
+ ("wVirtualScanCode", WORD),
68
+ ("uChar", uChar),
69
+ ("dwControlKeyState", DWORD),
70
+ ]
71
+
72
+
73
+ class MOUSE_EVENT_RECORD(Structure):
74
+ """https://docs.microsoft.com/en-us/windows/console/mouse-event-record-str"""
75
+
76
+ _fields_: typing.ClassVar[list[tuple[str, type]]] = [
77
+ ("dwMousePosition", COORD),
78
+ ("dwButtonState", DWORD),
79
+ ("dwControlKeyState", DWORD),
80
+ ("dwEventFlags", DWORD),
81
+ ]
82
+
83
+
84
+ class MouseButtonState(enum.IntFlag):
85
+ """https://learn.microsoft.com/en-us/windows/console/mouse-event-record-str"""
86
+
87
+ FROM_LEFT_1ST_BUTTON_PRESSED = 0x0001
88
+ RIGHTMOST_BUTTON_PRESSED = 0x0002
89
+ FROM_LEFT_2ND_BUTTON_PRESSED = 0x0004
90
+ FROM_LEFT_3RD_BUTTON_PRESSED = 0x0008
91
+ FROM_LEFT_4TH_BUTTON_PRESSED = 0x0010
92
+
93
+
94
+ class MouseEventFlags(enum.IntFlag):
95
+ """https://learn.microsoft.com/en-us/windows/console/mouse-event-record-str"""
96
+
97
+ BUTTON_PRESSED = 0x0000 # Default action, used in examples, but not in official enum
98
+ MOUSE_MOVED = 0x0001
99
+ DOUBLE_CLICK = 0x0002
100
+ MOUSE_WHEELED = 0x0004
101
+ MOUSE_HWHEELED = 0x0008
102
+
103
+
104
+ class WINDOW_BUFFER_SIZE_RECORD(Structure):
105
+ """https://docs.microsoft.com/en-us/windows/console/window-buffer-size-record-str"""
106
+
107
+ _fields_: typing.ClassVar[list[tuple[str, type]]] = [("dwSize", COORD)]
108
+
109
+
110
+ class MENU_EVENT_RECORD(Structure):
111
+ """https://docs.microsoft.com/en-us/windows/console/menu-event-record-str"""
112
+
113
+ _fields_: typing.ClassVar[list[tuple[str, type]]] = [("dwCommandId", UINT)]
114
+
115
+
116
+ class FOCUS_EVENT_RECORD(Structure):
117
+ """https://docs.microsoft.com/en-us/windows/console/focus-event-record-str"""
118
+
119
+ _fields_: typing.ClassVar[list[tuple[str, type]]] = [("bSetFocus", BOOL)]
120
+
121
+
122
+ class Event(Union):
123
+ """https://docs.microsoft.com/en-us/windows/console/input-record-str"""
124
+
125
+ _fields_: typing.ClassVar[list[tuple[str, type]]] = [
126
+ ("KeyEvent", KEY_EVENT_RECORD),
127
+ ("MouseEvent", MOUSE_EVENT_RECORD),
128
+ ("WindowBufferSizeEvent", WINDOW_BUFFER_SIZE_RECORD),
129
+ ("MenuEvent", MENU_EVENT_RECORD),
130
+ ("FocusEvent", FOCUS_EVENT_RECORD),
131
+ ]
132
+
133
+
134
+ class INPUT_RECORD(Structure):
135
+ """https://docs.microsoft.com/en-us/windows/console/input-record-str"""
136
+
137
+ _fields_: typing.ClassVar[list[tuple[str, type]]] = [("EventType", WORD), ("Event", Event)]
138
+
139
+
140
+ class EventType(enum.IntFlag):
141
+ KEY_EVENT = 0x0001
142
+ MOUSE_EVENT = 0x0002
143
+ WINDOW_BUFFER_SIZE_EVENT = 0x0004
144
+ MENU_EVENT = 0x0008
145
+ FOCUS_EVENT = 0x0010
146
+
147
+
148
+ # https://docs.microsoft.com/de-de/windows/console/getstdhandle
149
+ GetStdHandle = windll.kernel32.GetStdHandle
150
+ GetStdHandle.argtypes = [DWORD]
151
+ GetStdHandle.restype = HANDLE
152
+
153
+ # https://docs.microsoft.com/de-de/windows/console/getconsolemode
154
+ GetConsoleMode = windll.kernel32.GetConsoleMode
155
+ GetConsoleMode.argtypes = [HANDLE, LPDWORD]
156
+ GetConsoleMode.restype = BOOL
157
+
158
+ # https://docs.microsoft.com/de-de/windows/console/setconsolemode
159
+ SetConsoleMode = windll.kernel32.SetConsoleMode
160
+ SetConsoleMode.argtypes = [HANDLE, DWORD]
161
+ SetConsoleMode.restype = BOOL
162
+
163
+ # https://docs.microsoft.com/de-de/windows/console/readconsoleinput
164
+ ReadConsoleInputW = windll.kernel32.ReadConsoleInputW
165
+ # ReadConsoleInputW.argtypes = [HANDLE, POINTER(INPUT_RECORD), DWORD, LPDWORD]
166
+ ReadConsoleInputW.restype = BOOL
167
+
168
+ # https://docs.microsoft.com/en-us/windows/console/getconsolescreenbufferinfo
169
+ GetConsoleScreenBufferInfo = windll.kernel32.GetConsoleScreenBufferInfo
170
+ GetConsoleScreenBufferInfo.argtypes = [HANDLE, POINTER(CONSOLE_SCREEN_BUFFER_INFO)]
171
+ GetConsoleScreenBufferInfo.restype = BOOL