2 * line edition function for Win32 console
4 * Copyright 2001 Eric Pouech
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/unicode.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(console
);
34 extern int CONSOLE_GetHistory(int idx
, WCHAR
* buf
, int buf_len
);
35 extern BOOL
CONSOLE_AppendHistory(const WCHAR
*p
);
36 extern unsigned int CONSOLE_GetNumHistoryEntries(void);
42 WCHAR val
; /* vk or unicode char */
43 void (*func
)(struct WCEL_Context
* ctx
);
48 DWORD keyState
; /* keyState (from INPUT_RECORD) to match */
49 BOOL chkChar
; /* check vk or char */
50 KeyEntry
* entries
; /* array of entries */
53 typedef struct WCEL_Context
{
54 WCHAR
* line
; /* the line being edited */
55 size_t alloc
; /* number of WCHAR in line */
56 unsigned len
; /* number of chars in line */
57 unsigned ofs
; /* offset for cursor in current line */
58 WCHAR
* yanked
; /* yanked line */
59 unsigned mark
; /* marked point (emacs mode only) */
60 CONSOLE_SCREEN_BUFFER_INFO csbi
; /* current state (initial cursor, window size, attribute) */
63 unsigned done
: 1, /* to 1 when we're done with editing */
64 error
: 1; /* to 1 when an error occurred in the editing */
71 static void WCEL_Dump(WCEL_Context
* ctx
, const char* pfx
)
73 MESSAGE("%s: [line=%s[alloc=%u] ofs=%u len=%u start=(%d,%d) mask=%c%c\n"
74 "\t\thist=(size=%u pos=%u curr=%s)\n",
75 pfx
, debugstr_w(ctx
->line
), ctx
->alloc
, ctx
->ofs
, ctx
->len
,
76 ctx
->csbi
.dwCursorPosition
.X
, ctx
->csbi
.dwCursorPosition
.Y
,
77 ctx
->done
? 'D' : 'd', ctx
->error
? 'E' : 'e',
78 ctx
->histSize
, ctx
->histPos
, debugstr_w(ctx
->histCurr
));
82 /* ====================================================================
84 * Console helper functions
86 * ====================================================================*/
88 static BOOL
WCEL_Get(WCEL_Context
* ctx
, INPUT_RECORD
* ir
)
94 /* data available ? */
95 if (ReadConsoleInputW(ctx
->hConIn
, ir
, 1, &retv
) && retv
== 1)
98 switch (WaitForSingleObject(ctx
->hConIn
, INFINITE
))
103 /* we have checked that hConIn was a console handle (could be sb) */
104 ERR("Shouldn't happen\n");
109 ERR("hmm bad situation\n");
115 static inline void WCEL_Beep(WCEL_Context
* ctx
)
120 static inline COORD
WCEL_GetCoord(WCEL_Context
* ctx
, int ofs
)
123 c
.X
= ctx
->csbi
.dwCursorPosition
.X
+ ofs
;
124 c
.Y
= ctx
->csbi
.dwCursorPosition
.Y
;
128 static inline void WCEL_GetRect(WCEL_Context
* ctx
, LPSMALL_RECT sr
, int beg
, int end
)
130 sr
->Left
= ctx
->csbi
.dwCursorPosition
.X
+ beg
;
131 sr
->Top
= ctx
->csbi
.dwCursorPosition
.Y
;
132 sr
->Right
= ctx
->csbi
.dwCursorPosition
.X
+ end
;
133 sr
->Bottom
= ctx
->csbi
.dwCursorPosition
.Y
;
136 /* ====================================================================
138 * context manipulation functions
140 * ====================================================================*/
142 static BOOL
WCEL_Grow(WCEL_Context
* ctx
, size_t len
)
144 if (ctx
->csbi
.dwCursorPosition
.X
+ ctx
->ofs
+ len
>= ctx
->csbi
.dwSize
.X
)
146 FIXME("Current implementation doesn't allow edition to spray across several lines\n");
150 if (ctx
->len
+ len
>= ctx
->alloc
)
153 newline
= HeapReAlloc(GetProcessHeap(), 0, ctx
->line
, sizeof(WCHAR
) * (ctx
->alloc
+ 32));
154 if (!newline
) return FALSE
;
161 static void WCEL_DeleteString(WCEL_Context
* ctx
, int beg
, int end
)
167 memmove(&ctx
->line
[beg
], &ctx
->line
[end
], (ctx
->len
- end
) * sizeof(WCHAR
));
168 /* make the source rect bigger than the actual rect to that the part outside the clip
169 * rect (before the scroll) will get redrawn after the scroll
171 WCEL_GetRect(ctx
, &scl
, end
, ctx
->len
+ end
- beg
);
172 WCEL_GetRect(ctx
, &clp
, beg
, ctx
->len
);
174 ci
.Char
.UnicodeChar
= ' ';
175 ci
.Attributes
= ctx
->csbi
.wAttributes
;
176 ScrollConsoleScreenBufferW(ctx
->hConOut
, &scl
, &clp
, WCEL_GetCoord(ctx
, beg
), &ci
);
178 ctx
->len
-= end
- beg
;
179 ctx
->line
[ctx
->len
] = 0;
182 static void WCEL_InsertString(WCEL_Context
* ctx
, const WCHAR
* str
)
184 size_t len
= lstrlenW(str
);
186 if (!len
|| !WCEL_Grow(ctx
, len
)) return;
187 if (ctx
->len
> ctx
->ofs
)
188 memmove(&ctx
->line
[ctx
->ofs
+ len
], &ctx
->line
[ctx
->ofs
], (ctx
->len
- ctx
->ofs
) * sizeof(WCHAR
));
189 memcpy(&ctx
->line
[ctx
->ofs
], str
, len
* sizeof(WCHAR
));
191 ctx
->line
[ctx
->len
] = 0;
192 SetConsoleCursorPosition(ctx
->hConOut
, WCEL_GetCoord(ctx
, ctx
->ofs
));
193 WriteConsoleW(ctx
->hConOut
, &ctx
->line
[ctx
->ofs
], ctx
->len
- ctx
->ofs
, NULL
, NULL
);
197 static void WCEL_InsertChar(WCEL_Context
* ctx
, WCHAR c
)
201 /* do not insert 0..31 control characters */
204 if (c
!= '\t') return;
208 WCEL_InsertString(ctx
, buffer
);
211 static void WCEL_SaveYank(WCEL_Context
* ctx
, int beg
, int end
)
214 ctx
->yanked
= HeapReAlloc(GetProcessHeap(), 0, ctx
->yanked
, (len
+ 1) * sizeof(WCHAR
));
215 if (!ctx
->yanked
) return;
216 memcpy(ctx
->yanked
, &ctx
->line
[beg
], len
* sizeof(WCHAR
));
217 ctx
->yanked
[len
] = 0;
220 /* FIXME NTDLL doesn't export iswalnum, and I don't want to link in msvcrt when most
221 * of the data lay in unicode lib
223 static inline BOOL
WCEL_iswalnum(WCHAR wc
)
225 return get_char_typeW(wc
) & (C1_ALPHA
|C1_DIGIT
|C1_LOWER
|C1_UPPER
);
228 static int WCEL_GetLeftWordTransition(WCEL_Context
* ctx
, int ofs
)
231 while (ofs
>= 0 && !WCEL_iswalnum(ctx
->line
[ofs
])) ofs
--;
232 while (ofs
>= 0 && WCEL_iswalnum(ctx
->line
[ofs
])) ofs
--;
237 static int WCEL_GetRightWordTransition(WCEL_Context
* ctx
, int ofs
)
240 while (ofs
<= ctx
->len
&& !WCEL_iswalnum(ctx
->line
[ofs
])) ofs
++;
241 while (ofs
<= ctx
->len
&& WCEL_iswalnum(ctx
->line
[ofs
])) ofs
++;
242 return min(ofs
, ctx
->len
);
245 static WCHAR
* WCEL_GetHistory(WCEL_Context
* ctx
, int idx
)
249 if (idx
== ctx
->histSize
- 1)
251 ptr
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(ctx
->histCurr
) + 1) * sizeof(WCHAR
));
252 lstrcpyW(ptr
, ctx
->histCurr
);
256 int len
= CONSOLE_GetHistory(idx
, NULL
, 0);
258 if ((ptr
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
260 CONSOLE_GetHistory(idx
, ptr
, len
);
266 static void WCEL_HistoryInit(WCEL_Context
* ctx
)
268 ctx
->histPos
= CONSOLE_GetNumHistoryEntries();
269 ctx
->histSize
= ctx
->histPos
+ 1;
270 ctx
->histCurr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WCHAR
));
273 static void WCEL_MoveToHist(WCEL_Context
* ctx
, int idx
)
275 WCHAR
* data
= WCEL_GetHistory(ctx
, idx
);
276 int len
= lstrlenW(data
) + 1;
278 /* save current line edition for recall when needed (FIXME seems broken to me) */
279 if (ctx
->histPos
== ctx
->histSize
- 1)
281 if (ctx
->histCurr
) HeapFree(GetProcessHeap(), 0, ctx
->histCurr
);
282 ctx
->histCurr
= HeapAlloc(GetProcessHeap(), 0, (ctx
->len
+ 1) * sizeof(WCHAR
));
283 memcpy(ctx
->histCurr
, ctx
->line
, (ctx
->len
+ 1) * sizeof(WCHAR
));
285 /* need to clean also the screen if new string is shorter than old one */
286 WCEL_DeleteString(ctx
, 0, ctx
->len
);
288 /* insert new string */
289 if (WCEL_Grow(ctx
, len
))
291 WCEL_InsertString(ctx
, data
);
292 HeapFree(GetProcessHeap(), 0, data
);
297 /* ====================================================================
299 * basic edition functions
301 * ====================================================================*/
303 static void WCEL_Done(WCEL_Context
* ctx
)
305 if (!WCEL_Grow(ctx
, 1)) return;
306 ctx
->line
[ctx
->len
++] = '\n';
307 ctx
->line
[ctx
->len
] = 0;
308 WriteConsoleA(ctx
->hConOut
, "\n", 1, NULL
, NULL
);
312 static void WCEL_MoveLeft(WCEL_Context
* ctx
)
314 if (ctx
->ofs
> 0) ctx
->ofs
--;
317 static void WCEL_MoveRight(WCEL_Context
* ctx
)
319 if (ctx
->ofs
< ctx
->len
) ctx
->ofs
++;
322 static void WCEL_MoveToLeftWord(WCEL_Context
* ctx
)
324 int new_ofs
= WCEL_GetLeftWordTransition(ctx
, ctx
->ofs
);
325 if (new_ofs
!= ctx
->ofs
) ctx
->ofs
= new_ofs
;
328 static void WCEL_MoveToRightWord(WCEL_Context
* ctx
)
330 int new_ofs
= WCEL_GetRightWordTransition(ctx
, ctx
->ofs
);
331 if (new_ofs
!= ctx
->ofs
) ctx
->ofs
= new_ofs
;
334 static void WCEL_MoveToBeg(WCEL_Context
* ctx
)
339 static void WCEL_MoveToEnd(WCEL_Context
* ctx
)
344 static void WCEL_SetMark(WCEL_Context
* ctx
)
346 ctx
->mark
= ctx
->ofs
;
349 static void WCEL_ExchangeMark(WCEL_Context
* ctx
)
353 if (ctx
->mark
> ctx
->len
) return;
355 ctx
->ofs
= ctx
->mark
;
359 static void WCEL_CopyMarkedZone(WCEL_Context
* ctx
)
363 if (ctx
->mark
> ctx
->len
|| ctx
->mark
== ctx
->ofs
) return;
364 if (ctx
->mark
> ctx
->ofs
)
366 beg
= ctx
->ofs
; end
= ctx
->mark
;
370 beg
= ctx
->mark
; end
= ctx
->ofs
;
372 WCEL_SaveYank(ctx
, beg
, end
);
375 static void WCEL_TransposeChar(WCEL_Context
* ctx
)
379 if (!ctx
->ofs
|| ctx
->ofs
== ctx
->len
) return;
381 c
= ctx
->line
[ctx
->ofs
];
382 ctx
->line
[ctx
->ofs
] = ctx
->line
[ctx
->ofs
- 1];
383 ctx
->line
[ctx
->ofs
- 1] = c
;
385 WriteConsoleOutputCharacterW(ctx
->hConOut
, &ctx
->line
[ctx
->ofs
- 1], 2, WCEL_GetCoord(ctx
, ctx
->ofs
- 1), NULL
);
389 static void WCEL_TransposeWords(WCEL_Context
* ctx
)
394 static void WCEL_LowerCaseWord(WCEL_Context
* ctx
)
396 int new_ofs
= WCEL_GetRightWordTransition(ctx
, ctx
->ofs
);
397 if (new_ofs
!= ctx
->ofs
)
400 for (i
= ctx
->ofs
; i
<= new_ofs
; i
++)
401 ctx
->line
[i
] = tolowerW(ctx
->line
[i
]);
402 WriteConsoleOutputCharacterW(ctx
->hConOut
, &ctx
->line
[ctx
->ofs
], new_ofs
- ctx
->ofs
+ 1,
403 WCEL_GetCoord(ctx
, ctx
->ofs
), NULL
);
408 static void WCEL_UpperCaseWord(WCEL_Context
* ctx
)
410 int new_ofs
= WCEL_GetRightWordTransition(ctx
, ctx
->ofs
);
411 if (new_ofs
!= ctx
->ofs
)
414 for (i
= ctx
->ofs
; i
<= new_ofs
; i
++)
415 ctx
->line
[i
] = toupperW(ctx
->line
[i
]);
416 WriteConsoleOutputCharacterW(ctx
->hConOut
, &ctx
->line
[ctx
->ofs
], new_ofs
- ctx
->ofs
+ 1,
417 WCEL_GetCoord(ctx
, ctx
->ofs
), NULL
);
422 static void WCEL_CapitalizeWord(WCEL_Context
* ctx
)
424 int new_ofs
= WCEL_GetRightWordTransition(ctx
, ctx
->ofs
);
425 if (new_ofs
!= ctx
->ofs
)
429 ctx
->line
[ctx
->ofs
] = toupperW(ctx
->line
[ctx
->ofs
]);
430 for (i
= ctx
->ofs
+ 1; i
<= new_ofs
; i
++)
431 ctx
->line
[i
] = tolowerW(ctx
->line
[i
]);
432 WriteConsoleOutputCharacterW(ctx
->hConOut
, &ctx
->line
[ctx
->ofs
], new_ofs
- ctx
->ofs
+ 1,
433 WCEL_GetCoord(ctx
, ctx
->ofs
), NULL
);
438 static void WCEL_Yank(WCEL_Context
* ctx
)
440 WCEL_InsertString(ctx
, ctx
->yanked
);
441 HeapFree(GetProcessHeap(), 0, ctx
->yanked
);
445 static void WCEL_KillToEndOfLine(WCEL_Context
* ctx
)
447 WCEL_SaveYank(ctx
, ctx
->ofs
, ctx
->len
);
448 WCEL_DeleteString(ctx
, ctx
->ofs
, ctx
->len
);
451 static void WCEL_KillMarkedZone(WCEL_Context
* ctx
)
455 if (ctx
->mark
> ctx
->len
|| ctx
->mark
== ctx
->ofs
) return;
456 if (ctx
->mark
> ctx
->ofs
)
458 beg
= ctx
->ofs
; end
= ctx
->mark
;
462 beg
= ctx
->mark
; end
= ctx
->ofs
;
464 WCEL_SaveYank(ctx
, beg
, end
);
465 WCEL_DeleteString(ctx
, beg
, end
);
469 static void WCEL_DeletePrevChar(WCEL_Context
* ctx
)
473 WCEL_DeleteString(ctx
, ctx
->ofs
- 1, ctx
->ofs
);
478 static void WCEL_DeleteCurrChar(WCEL_Context
* ctx
)
480 if (ctx
->ofs
< ctx
->len
)
481 WCEL_DeleteString(ctx
, ctx
->ofs
, ctx
->ofs
+ 1);
484 static void WCEL_DeleteLeftWord(WCEL_Context
* ctx
)
486 int new_ofs
= WCEL_GetLeftWordTransition(ctx
, ctx
->ofs
);
487 if (new_ofs
!= ctx
->ofs
)
489 WCEL_DeleteString(ctx
, new_ofs
, ctx
->ofs
);
494 static void WCEL_DeleteRightWord(WCEL_Context
* ctx
)
496 int new_ofs
= WCEL_GetRightWordTransition(ctx
, ctx
->ofs
);
497 if (new_ofs
!= ctx
->ofs
)
499 WCEL_DeleteString(ctx
, ctx
->ofs
, new_ofs
);
503 static void WCEL_MoveToPrevHist(WCEL_Context
* ctx
)
505 if (ctx
->histPos
) WCEL_MoveToHist(ctx
, ctx
->histPos
- 1);
508 static void WCEL_MoveToNextHist(WCEL_Context
* ctx
)
510 if (ctx
->histPos
< ctx
->histSize
- 1) WCEL_MoveToHist(ctx
, ctx
->histPos
+ 1);
513 static void WCEL_MoveToFirstHist(WCEL_Context
* ctx
)
515 if (ctx
->histPos
!= 0) WCEL_MoveToHist(ctx
, 0);
518 static void WCEL_MoveToLastHist(WCEL_Context
* ctx
)
520 if (ctx
->histPos
!= ctx
->histSize
- 1) WCEL_MoveToHist(ctx
, ctx
->histSize
- 1);
523 /* ====================================================================
527 * ====================================================================*/
529 #define CTRL(x) ((x) - '@')
530 static KeyEntry StdKeyMap
[] =
532 {/*BACK*/0x08, WCEL_DeletePrevChar
},
533 {/*RETURN*/0x0d, WCEL_Done
},
534 {/*DEL*/127, WCEL_DeleteCurrChar
},
538 static KeyEntry EmacsKeyMapCtrl
[] =
540 { CTRL('@'), WCEL_SetMark
},
541 { CTRL('A'), WCEL_MoveToBeg
},
542 { CTRL('B'), WCEL_MoveLeft
},
544 { CTRL('D'), WCEL_DeleteCurrChar
},
545 { CTRL('E'), WCEL_MoveToEnd
},
546 { CTRL('F'), WCEL_MoveRight
},
547 { CTRL('G'), WCEL_Beep
},
548 { CTRL('H'), WCEL_DeletePrevChar
},
549 /* I: meaningless (or tab ???) */
550 { CTRL('J'), WCEL_Done
},
551 { CTRL('K'), WCEL_KillToEndOfLine
},
552 /* L: [NIY] redraw the whole stuff */
553 { CTRL('M'), WCEL_Done
},
554 { CTRL('N'), WCEL_MoveToNextHist
},
555 /* O; insert line... meaningless */
556 { CTRL('P'), WCEL_MoveToPrevHist
},
557 /* Q: [NIY] quoting... */
558 /* R: [NIY] search backwards... */
559 /* S: [NIY] search forwards... */
560 { CTRL('T'), WCEL_TransposeChar
},
561 /* U: [NIY] set repeat count... */
562 /* V: paragraph down... meaningless */
563 { CTRL('W'), WCEL_KillMarkedZone
},
564 { CTRL('X'), WCEL_ExchangeMark
},
565 { CTRL('Y'), WCEL_Yank
},
570 static KeyEntry EmacsKeyMapAlt
[] =
572 {/*DEL*/127, WCEL_DeleteLeftWord
},
573 { '<', WCEL_MoveToFirstHist
},
574 { '>', WCEL_MoveToLastHist
},
576 { 'b', WCEL_MoveToLeftWord
},
577 { 'c', WCEL_CapitalizeWord
},
578 { 'd', WCEL_DeleteRightWord
},
579 { 'f', WCEL_MoveToRightWord
},
580 { 'l', WCEL_LowerCaseWord
},
581 { 't', WCEL_TransposeWords
},
582 { 'u', WCEL_UpperCaseWord
},
583 { 'w', WCEL_CopyMarkedZone
},
587 static KeyEntry EmacsKeyMapExtended
[] =
589 {/*RETURN*/ 0x0d, WCEL_Done
},
590 {/*VK_PRIOR*/0x21, WCEL_MoveToPrevHist
},
591 {/*VK_NEXT*/0x22, WCEL_MoveToNextHist
},
592 {/*VK_END*/ 0x23, WCEL_MoveToEnd
},
593 {/*VK_HOME*/ 0x24, WCEL_MoveToBeg
},
594 {/*VK_RIGHT*/0x27, WCEL_MoveRight
},
595 {/*VK_LEFT*/0x25, WCEL_MoveLeft
},
599 static KeyMap EmacsKeyMap
[] =
601 {0x00000000, 1, StdKeyMap
},
602 {0x00000001, 1, EmacsKeyMapAlt
}, /* left alt */
603 {0x00000002, 1, EmacsKeyMapAlt
}, /* right alt */
604 {0x00000004, 1, EmacsKeyMapCtrl
}, /* left ctrl */
605 {0x00000008, 1, EmacsKeyMapCtrl
}, /* right ctrl */
606 {0x00000100, 0, EmacsKeyMapExtended
},
610 static KeyEntry Win32KeyMapExtended
[] =
612 {/*VK_LEFT*/ 0x25, WCEL_MoveLeft
},
613 {/*VK_RIGHT*/0x27, WCEL_MoveRight
},
614 {/*VK_HOME*/ 0x24, WCEL_MoveToBeg
},
615 {/*VK_END*/ 0x23, WCEL_MoveToEnd
},
616 {/*VK_UP*/ 0x26, WCEL_MoveToPrevHist
},
617 {/*VK_DOWN*/ 0x28, WCEL_MoveToNextHist
},
621 static KeyEntry Win32KeyMapCtrlExtended
[] =
623 {/*VK_LEFT*/ 0x25, WCEL_MoveToLeftWord
},
624 {/*VK_RIGHT*/0x27, WCEL_MoveToRightWord
},
628 KeyMap Win32KeyMap
[] =
630 {0x00000000, 1, StdKeyMap
},
631 {0x00000100, 0, Win32KeyMapExtended
},
632 {0x00000104, 0, Win32KeyMapCtrlExtended
},
633 {0x00000108, 0, Win32KeyMapCtrlExtended
},
638 /* ====================================================================
640 * Read line master function
642 * ====================================================================*/
644 WCHAR
* CONSOLE_Readline(HANDLE hConsoleIn
, int use_emacs
)
651 void (*func
)(struct WCEL_Context
* ctx
);
654 memset(&ctx
, 0, sizeof(ctx
));
655 ctx
.hConIn
= hConsoleIn
;
656 WCEL_HistoryInit(&ctx
);
657 if ((ctx
.hConOut
= CreateFileA("CONOUT$", GENERIC_READ
|GENERIC_WRITE
, 0, NULL
,
658 OPEN_EXISTING
, 0, 0 )) == INVALID_HANDLE_VALUE
||
659 !GetConsoleScreenBufferInfo(ctx
.hConOut
, &ctx
.csbi
))
661 if (!WCEL_Grow(&ctx
, 1))
663 CloseHandle(ctx
.hConOut
);
668 /* EPP WCEL_Dump(&ctx, "init"); */
670 while (!ctx
.done
&& !ctx
.error
&& WCEL_Get(&ctx
, &ir
))
672 if (ir
.EventType
!= KEY_EVENT
|| !ir
.Event
.KeyEvent
.bKeyDown
) continue;
673 TRACE("key%s repeatCount=%u, keyCode=%02x scanCode=%02x char=%02x keyState=%08lx\n",
674 ir
.Event
.KeyEvent
.bKeyDown
? "Down" : "Up ", ir
.Event
.KeyEvent
.wRepeatCount
,
675 ir
.Event
.KeyEvent
.wVirtualKeyCode
, ir
.Event
.KeyEvent
.wVirtualScanCode
,
676 ir
.Event
.KeyEvent
.uChar
.UnicodeChar
, ir
.Event
.KeyEvent
.dwControlKeyState
);
678 /* EPP WCEL_Dump(&ctx, "before func"); */
680 /* mask out some bits which don't interest us */
681 ks
= ir
.Event
.KeyEvent
.dwControlKeyState
& ~(NUMLOCK_ON
|SCROLLLOCK_ON
|CAPSLOCK_ON
);
684 for (km
= (use_emacs
) ? EmacsKeyMap
: Win32KeyMap
; km
->entries
!= NULL
; km
++)
686 if (km
->keyState
!= ks
)
690 for (ke
= &km
->entries
[0]; ke
->func
!= 0; ke
++)
691 if (ke
->val
== ir
.Event
.KeyEvent
.uChar
.UnicodeChar
) break;
695 for (ke
= &km
->entries
[0]; ke
->func
!= 0; ke
++)
696 if (ke
->val
== ir
.Event
.KeyEvent
.wVirtualKeyCode
) break;
708 else if (!(ir
.Event
.KeyEvent
.dwControlKeyState
& (ENHANCED_KEY
|LEFT_ALT_PRESSED
)))
709 WCEL_InsertChar(&ctx
, ir
.Event
.KeyEvent
.uChar
.UnicodeChar
);
710 else TRACE("Dropped event\n");
712 /* EPP WCEL_Dump(&ctx, "after func"); */
714 SetConsoleCursorPosition(ctx
.hConOut
, WCEL_GetCoord(&ctx
, ctx
.ofs
));
718 HeapFree(GetProcessHeap(), 0, ctx
.line
);
722 CONSOLE_AppendHistory(ctx
.line
);
724 CloseHandle(ctx
.hConOut
);
725 if (ctx
.histCurr
) HeapFree(GetProcessHeap(), 0, ctx
.histCurr
);