Rev 2726 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2726 | vana | 1 | /*++ |
2 | |||
3 | Copyright (c) 1998 Intel Corporation |
||
4 | |||
5 | Module Name: |
||
6 | |||
7 | console.c |
||
8 | |||
9 | Abstract: |
||
10 | |||
11 | |||
12 | |||
13 | |||
14 | Revision History |
||
15 | |||
16 | --*/ |
||
17 | |||
18 | #include "lib.h" |
||
19 | |||
20 | |||
21 | |||
22 | VOID |
||
23 | Output ( |
||
24 | IN CHAR16 *Str |
||
25 | ) |
||
26 | // Write a string to the console at the current cursor location |
||
27 | { |
||
28 | ST->ConOut->OutputString (ST->ConOut, Str); |
||
29 | } |
||
30 | |||
31 | |||
32 | VOID |
||
33 | Input ( |
||
34 | IN CHAR16 *Prompt OPTIONAL, |
||
35 | OUT CHAR16 *InStr, |
||
36 | IN UINTN StrLen |
||
37 | ) |
||
38 | // Input a string at the current cursor location, for StrLen |
||
39 | { |
||
40 | IInput ( |
||
41 | ST->ConOut, |
||
42 | ST->ConIn, |
||
43 | Prompt, |
||
44 | InStr, |
||
45 | StrLen |
||
46 | ); |
||
47 | } |
||
48 | |||
49 | VOID |
||
50 | IInput ( |
||
51 | IN SIMPLE_TEXT_OUTPUT_INTERFACE *ConOut, |
||
52 | IN SIMPLE_INPUT_INTERFACE *ConIn, |
||
53 | IN CHAR16 *Prompt OPTIONAL, |
||
54 | OUT CHAR16 *InStr, |
||
55 | IN UINTN StrLen |
||
56 | ) |
||
57 | // Input a string at the current cursor location, for StrLen |
||
58 | { |
||
59 | EFI_INPUT_KEY Key; |
||
60 | EFI_STATUS Status; |
||
61 | UINTN Len; |
||
62 | |||
63 | if (Prompt) { |
||
64 | ConOut->OutputString (ConOut, Prompt); |
||
65 | } |
||
66 | |||
67 | Len = 0; |
||
68 | for (; ;) { |
||
69 | WaitForSingleEvent (ConIn->WaitForKey, 0); |
||
70 | |||
71 | Status = ConIn->ReadKeyStroke(ConIn, &Key); |
||
72 | if (EFI_ERROR(Status)) { |
||
73 | DEBUG((D_ERROR, "Input: error return from ReadKey %x\n", Status)); |
||
74 | break; |
||
75 | } |
||
76 | |||
77 | if (Key.UnicodeChar == '\n' || |
||
78 | Key.UnicodeChar == '\r') { |
||
79 | break; |
||
80 | } |
||
81 | |||
82 | if (Key.UnicodeChar == '\b') { |
||
83 | if (Len) { |
||
84 | ConOut->OutputString(ConOut, L"\b \b"); |
||
85 | Len -= 1; |
||
86 | } |
||
87 | continue; |
||
88 | } |
||
89 | |||
90 | if (Key.UnicodeChar >= ' ') { |
||
91 | if (Len < StrLen-1) { |
||
92 | InStr[Len] = Key.UnicodeChar; |
||
93 | |||
94 | InStr[Len+1] = 0; |
||
95 | ConOut->OutputString(ConOut, &InStr[Len]); |
||
96 | |||
97 | Len += 1; |
||
98 | } |
||
99 | continue; |
||
100 | } |
||
101 | } |
||
102 | |||
103 | InStr[Len] = 0; |
||
104 | } |