]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiLib/Console.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / UefiLib / Console.c
CommitLineData
e386b444 1/** @file\r
9edc73ad 2 This module provide help function for displaying unicode string.\r
e386b444 3\r
9095d37b 4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9344f092 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
e386b444 6\r
e386b444 7**/\r
8\r
9\r
10\r
1efcc4ae 11\r
f734a10a 12#include "UefiLibInternal.h"\r
e386b444 13\r
14typedef struct {\r
15 CHAR16 WChar;\r
16 UINT32 Width;\r
17} UNICODE_WIDTH_ENTRY;\r
18\r
33026ccf
ED
19#define NARROW_CHAR 0xFFF0\r
20#define WIDE_CHAR 0xFFF1\r
21\r
f80b0830 22GLOBAL_REMOVE_IF_UNREFERENCED CONST UNICODE_WIDTH_ENTRY mUnicodeWidthTable[] = {\r
e386b444 23 //\r
24 // General script area\r
25 //\r
26 {(CHAR16)0x1FFF, 1},\r
27 /*\r
9095d37b 28 * Merge the blocks and replace them with the above entry as they fall to\r
e386b444 29 * the same category and they are all narrow glyph. This will reduce search\r
30 * time and table size. The merge will omit the reserved code.\r
31 *\r
32 * Remove the above item if below is un-commented.\r
33 *\r
34 {(CHAR16)0x007F, 1}, // C0 controls and basic Latin. 0x0000-0x007F\r
35 {(CHAR16)0x00FF, 1}, // C1 controls and Latin-1 support. 0x0080-0x00FF\r
36 {(CHAR16)0x017F, 1}, // Latin extended-A. 0x0100-0x017F\r
37 {(CHAR16)0x024F, 1}, // Latin extended-B. 0x0180-0x024F\r
38 {(CHAR16)0x02AF, 1}, // IPA extensions. 0x0250-0x02AF\r
39 {(CHAR16)0x02FF, 1}, // Spacing modifier letters. 0x02B0-0x02FF\r
40 {(CHAR16)0x036F, 1}, // Combining diacritical marks. 0x0300-0x036F\r
41 {(CHAR16)0x03FF, 1}, // Greek. 0x0370-0x03FF\r
42 {(CHAR16)0x04FF, 1}, // Cyrillic. 0x0400-0x04FF\r
43 {(CHAR16)0x052F, 0}, // Unassigned. As Armenian in ver3.0. 0x0500-0x052F\r
44 {(CHAR16)0x058F, 1}, // Armenian. 0x0530-0x058F\r
45 {(CHAR16)0x05FF, 1}, // Hebrew. 0x0590-0x05FF\r
46 {(CHAR16)0x06FF, 1}, // Arabic. 0x0600-0x06FF\r
47 {(CHAR16)0x08FF, 0}, // Unassigned. 0x0700-0x08FF\r
48 {(CHAR16)0x097F, 1}, // Devanagari. 0x0900-0x097F\r
49 {(CHAR16)0x09FF, 1}, // Bengali. 0x0980-0x09FF\r
50 {(CHAR16)0x0A7F, 1}, // Gurmukhi. 0x0A00-0x0A7F\r
51 {(CHAR16)0x0AFF, 1}, // Gujarati. 0x0A80-0x0AFF\r
52 {(CHAR16)0x0B7F, 1}, // Oriya. 0x0B00-0x0B7F\r
53 {(CHAR16)0x0BFF, 1}, // Tamil. (See page 7-92). 0x0B80-0x0BFF\r
54 {(CHAR16)0x0C7F, 1}, // Telugu. 0x0C00-0x0C7F\r
55 {(CHAR16)0x0CFF, 1}, // Kannada. (See page 7-100). 0x0C80-0x0CFF\r
56 {(CHAR16)0x0D7F, 1}, // Malayalam (See page 7-104). 0x0D00-0x0D7F\r
57 {(CHAR16)0x0DFF, 0}, // Unassigned. 0x0D80-0x0DFF\r
58 {(CHAR16)0x0E7F, 1}, // Thai. 0x0E00-0x0E7F\r
59 {(CHAR16)0x0EFF, 1}, // Lao. 0x0E80-0x0EFF\r
60 {(CHAR16)0x0FBF, 1}, // Tibetan. 0x0F00-0x0FBF\r
61 {(CHAR16)0x109F, 0}, // Unassigned. 0x0FC0-0x109F\r
62 {(CHAR16)0x10FF, 1}, // Georgian. 0x10A0-0x10FF\r
63 {(CHAR16)0x11FF, 1}, // Hangul Jamo. 0x1100-0x11FF\r
64 {(CHAR16)0x1DFF, 0}, // Unassigned. 0x1200-0x1DFF\r
65 {(CHAR16)0x1EFF, 1}, // Latin extended additional. 0x1E00-0x1EFF\r
66 {(CHAR16)0x1FFF, 1}, // Greek extended. 0x1F00-0x1FFF\r
67 *\r
68 */\r
69\r
70 //\r
71 // Symbol area\r
72 //\r
73 {(CHAR16)0x2FFF, 1},\r
74 /*\r
9095d37b 75 * Merge the blocks and replace them with the above entry as they fall to\r
e386b444 76 * the same category and they are all narrow glyph. This will reduce search\r
77 * time and table size. The merge will omit the reserved code.\r
78 *\r
79 * Remove the above item if below is un-commented.\r
80 *\r
81 {(CHAR16)0x206F, 1}, // General punctuation. (See page7-154). 0x200-0x206F\r
82 {(CHAR16)0x209F, 1}, // Superscripts and subscripts. 0x2070-0x209F\r
83 {(CHAR16)0x20CF, 1}, // Currency symbols. 0x20A0-0x20CF\r
84 {(CHAR16)0x20FF, 1}, // Combining diacritical marks for symbols. 0x20D0-0x20FF\r
85 {(CHAR16)0x214F, 1}, // Letterlike sympbols. 0x2100-0x214F\r
86 {(CHAR16)0x218F, 1}, // Number forms. 0x2150-0x218F\r
87 {(CHAR16)0x21FF, 1}, // Arrows. 0x2190-0x21FF\r
88 {(CHAR16)0x22FF, 1}, // Mathematical operators. 0x2200-0x22FF\r
89 {(CHAR16)0x23FF, 1}, // Miscellaneous technical. 0x2300-0x23FF\r
90 {(CHAR16)0x243F, 1}, // Control pictures. 0x2400-0x243F\r
91 {(CHAR16)0x245F, 1}, // Optical character recognition. 0x2440-0x245F\r
92 {(CHAR16)0x24FF, 1}, // Enclosed alphanumerics. 0x2460-0x24FF\r
93 {(CHAR16)0x257F, 1}, // Box drawing. 0x2500-0x257F\r
94 {(CHAR16)0x259F, 1}, // Block elements. 0x2580-0x259F\r
95 {(CHAR16)0x25FF, 1}, // Geometric shapes. 0x25A0-0x25FF\r
96 {(CHAR16)0x26FF, 1}, // Miscellaneous symbols. 0x2600-0x26FF\r
97 {(CHAR16)0x27BF, 1}, // Dingbats. 0x2700-0x27BF\r
98 {(CHAR16)0x2FFF, 0}, // Reserved. 0x27C0-0x2FFF\r
99 *\r
100 */\r
101\r
102 //\r
103 // CJK phonetics and symbol area\r
104 //\r
105 {(CHAR16)0x33FF, 2},\r
106 /*\r
9095d37b 107 * Merge the blocks and replace them with the above entry as they fall to\r
e386b444 108 * the same category and they are all wide glyph. This will reduce search\r
109 * time and table size. The merge will omit the reserved code.\r
110 *\r
111 * Remove the above item if below is un-commented.\r
112 *\r
113 {(CHAR16)0x303F, 2}, // CJK symbols and punctuation. 0x3000-0x303F\r
114 {(CHAR16)0x309F, 2}, // Hiragana. 0x3040-0x309F\r
115 {(CHAR16)0x30FF, 2}, // Katakana. 0x30A0-0x30FF\r
116 {(CHAR16)0x312F, 2}, // Bopomofo. 0x3100-0x312F\r
117 {(CHAR16)0x318F, 2}, // Hangul compatibility jamo. 0x3130-0x318F\r
118 {(CHAR16)0x319F, 2}, // Kanbun. 0x3190-0x319F\r
119 {(CHAR16)0x31FF, 0}, // Reserved. As Bopomofo extended in ver3.0. 0x31A0-0x31FF\r
120 {(CHAR16)0x32FF, 2}, // Enclosed CJK letters and months. 0x3200-0x32FF\r
121 {(CHAR16)0x33FF, 2}, // CJK compatibility. 0x3300-0x33FF\r
122 *\r
123 */\r
124\r
125 //\r
126 // CJK ideograph area\r
127 //\r
128 {(CHAR16)0x9FFF, 2},\r
129 /*\r
9095d37b 130 * Merge the blocks and replace them with the above entry as they fall to\r
e386b444 131 * the same category and they are all wide glyph. This will reduce search\r
132 * time and table size. The merge will omit the reserved code.\r
133 *\r
134 * Remove the above item if below is un-commented.\r
135 *\r
9095d37b 136 {(CHAR16)0x4DFF, 0}, // Reserved. 0x3400-0x4DBF as CJK unified ideographs\r
e386b444 137 // extension A in ver3.0. 0x3400-0x4DFF\r
138 {(CHAR16)0x9FFF, 2}, // CJK unified ideographs. 0x4E00-0x9FFF\r
139 *\r
140 */\r
141\r
142 //\r
143 // Reserved\r
144 //\r
145 {(CHAR16)0xABFF, 0}, // Reserved. 0xA000-0xA490 as Yi syllables. 0xA490-0xA4D0\r
146 // as Yi radicals in ver3.0. 0xA000-0xABFF\r
147 //\r
148 // Hangul syllables\r
149 //\r
150 {(CHAR16)0xD7FF, 2},\r
151 /*\r
9095d37b 152 * Merge the blocks and replace them with the above entry as they fall to\r
e386b444 153 * the same category and they are all wide glyph. This will reduce search\r
154 * time and table size. The merge will omit the reserved code.\r
155 *\r
156 * Remove the above item if below is un-commented.\r
157 *\r
158 {(CHAR16)0xD7A3, 2}, // Hangul syllables. 0xAC00-0xD7A3\r
159 {(CHAR16)0xD7FF, 0}, // Reserved. 0xD7A3-0xD7FF\r
160 *\r
161 */\r
162\r
163 //\r
164 // Surrogates area\r
165 //\r
166 {(CHAR16)0xDFFF, 0}, // Surrogates, not used now. 0xD800-0xDFFF\r
167\r
168 //\r
169 // Private use area\r
170 //\r
171 {(CHAR16)0xF8FF, 0}, // Private use area. 0xE000-0xF8FF\r
172\r
173 //\r
174 // Compatibility area and specials\r
175 //\r
176 {(CHAR16)0xFAFF, 2}, // CJK compatibility ideographs. 0xF900-0xFAFF\r
177 {(CHAR16)0xFB4F, 1}, // Alphabetic presentation forms. 0xFB00-0xFB4F\r
178 {(CHAR16)0xFDFF, 1}, // Arabic presentation forms-A. 0xFB50-0xFDFF\r
179 {(CHAR16)0xFE1F, 0}, // Reserved. As variation selectors in ver3.0. 0xFE00-0xFE1F\r
180 {(CHAR16)0xFE2F, 1}, // Combining half marks. 0xFE20-0xFE2F\r
181 {(CHAR16)0xFE4F, 2}, // CJK compatibility forms. 0xFE30-0xFE4F\r
182 {(CHAR16)0xFE6F, 1}, // Small Form Variants. 0xFE50-0xFE6F\r
183 {(CHAR16)0xFEFF, 1}, // Arabic presentation forms-B. 0xFE70-0xFEFF\r
184 {(CHAR16)0xFFEF, 1}, // Half width and full width forms. 0xFF00-0xFFEF\r
185 {(CHAR16)0xFFFF, 0}, // Speicials. 0xFFF0-0xFFFF\r
186};\r
187\r
188/**\r
cf8ae2f6 189 Retrieves the width of a Unicode character.\r
190\r
191 This function computes and returns the width of the Unicode character specified\r
192 by UnicodeChar.\r
e386b444 193\r
194 @param UnicodeChar A Unicode character.\r
195\r
196 @retval 0 The width if UnicodeChar could not be determined.\r
197 @retval 1 UnicodeChar is a narrow glyph.\r
198 @retval 2 UnicodeChar is a wide glyph.\r
199\r
200**/\r
201UINTN\r
202EFIAPI\r
203GetGlyphWidth (\r
204 IN CHAR16 UnicodeChar\r
205 )\r
206{\r
1654531a 207 UINTN Index;\r
208 UINTN Low;\r
209 UINTN High;\r
210 CONST UNICODE_WIDTH_ENTRY *Item;\r
e386b444 211\r
212 Item = NULL;\r
213 Low = 0;\r
214 High = (sizeof (mUnicodeWidthTable)) / (sizeof (UNICODE_WIDTH_ENTRY)) - 1;\r
215 while (Low <= High) {\r
216 Index = (Low + High) >> 1;\r
217 Item = &(mUnicodeWidthTable[Index]);\r
218 if (Index == 0) {\r
219 if (UnicodeChar <= Item->WChar) {\r
220 break;\r
221 }\r
222\r
223 return 0;\r
224 }\r
225\r
226 if (UnicodeChar > Item->WChar) {\r
227 Low = Index + 1;\r
228 } else if (UnicodeChar <= mUnicodeWidthTable[Index - 1].WChar) {\r
229 High = Index - 1;\r
230 } else {\r
231 //\r
232 // Index - 1 < UnicodeChar <= Index. Found\r
233 //\r
234 break;\r
235 }\r
236 }\r
237\r
238 if (Low <= High) {\r
239 return Item->Width;\r
240 }\r
241\r
242 return 0;\r
243}\r
244\r
245/**\r
1d37ab9f 246 Computes the display length of a Null-terminated Unicode String.\r
247\r
9095d37b
LG
248 This function computes and returns the display length of the Null-terminated\r
249 Unicode string specified by String. If String is NULL then 0 is returned. If\r
250 any of the widths of the Unicode characters in String can not be determined,\r
251 then 0 is returned. The display width of String can be computed by summing the\r
252 display widths of each Unicode character in String. Unicode characters that\r
253 are narrow glyphs have a width of 1, and Unicode characters that are width glyphs\r
58380e9c 254 have a width of 2. If String is not aligned on a 16-bit boundary, then ASSERT().\r
e386b444 255\r
256 @param String A pointer to a Null-terminated Unicode string.\r
257\r
258 @return The display length of the Null-terminated Unicode string specified by String.\r
9095d37b 259\r
e386b444 260**/\r
261UINTN\r
262EFIAPI\r
263UnicodeStringDisplayLength (\r
264 IN CONST CHAR16 *String\r
265 )\r
266{\r
267 UINTN Length;\r
268 UINTN Width;\r
269\r
270 if (String == NULL) {\r
271 return 0;\r
272 }\r
273\r
274 Length = 0;\r
275 while (*String != 0) {\r
276 Width = GetGlyphWidth (*String);\r
277 if (Width == 0) {\r
278 return 0;\r
279 }\r
280\r
281 Length += Width;\r
282 String++;\r
283 }\r
284\r
285 return Length;\r
286}\r
db2ef756 287\r
33026ccf 288/**\r
9095d37b 289 Count the storage space of a Unicode string.\r
33026ccf
ED
290\r
291 This function handles the Unicode string with NARROW_CHAR\r
292 and WIDE_CHAR control characters. NARROW_HCAR and WIDE_CHAR\r
293 does not count in the resultant output. If a WIDE_CHAR is\r
294 hit, then 2 Unicode character will consume an output storage\r
295 space with size of CHAR16 till a NARROW_CHAR is hit.\r
296\r
297 @param String The input string to be counted.\r
298 @param LimitLen Whether need to limit the string length.\r
299 @param MaxWidth The max length this function supported.\r
9095d37b 300 @param Offset The max index of the string can be show out.\r
33026ccf
ED
301\r
302 @return Storage space for the input string.\r
303\r
304**/\r
305UINTN\r
306UefiLibGetStringWidth (\r
307 IN CHAR16 *String,\r
308 IN BOOLEAN LimitLen,\r
309 IN UINTN MaxWidth,\r
310 OUT UINTN *Offset\r
311 )\r
312{\r
313 UINTN Index;\r
314 UINTN Count;\r
315 UINTN IncrementValue;\r
316\r
317 if (String == NULL) {\r
318 return 0;\r
319 }\r
320\r
321 Index = 0;\r
322 Count = 0;\r
323 IncrementValue = 1;\r
324\r
325 do {\r
326 //\r
327 // Advance to the null-terminator or to the first width directive\r
328 //\r
8b5b3d42
ED
329 for (;(String[Index] != NARROW_CHAR) && (String[Index] != WIDE_CHAR) && (String[Index] != 0); Index++) {\r
330 Count = Count + IncrementValue;\r
331\r
33026ccf
ED
332 if (LimitLen && Count > MaxWidth) {\r
333 break;\r
334 }\r
335 }\r
336\r
337 //\r
338 // We hit the null-terminator, we now have a count\r
339 //\r
340 if (String[Index] == 0) {\r
341 break;\r
342 }\r
343\r
344 if (LimitLen && Count > MaxWidth) {\r
8b5b3d42 345 *Offset = Index;\r
33026ccf
ED
346 break;\r
347 }\r
348\r
349 //\r
350 // We encountered a narrow directive - strip it from the size calculation since it doesn't get printed\r
351 // and also set the flag that determines what we increment by.(if narrow, increment by 1, if wide increment by 2)\r
352 //\r
353 if (String[Index] == NARROW_CHAR) {\r
354 //\r
355 // Skip to the next character\r
356 //\r
357 Index++;\r
358 IncrementValue = 1;\r
359 } else {\r
360 //\r
361 // Skip to the next character\r
362 //\r
363 Index++;\r
364 IncrementValue = 2;\r
365 }\r
366 } while (String[Index] != 0);\r
367\r
33026ccf
ED
368 return Count * sizeof (CHAR16);\r
369}\r
370\r
db2ef756 371/**\r
9095d37b 372 Draws a dialog box to the console output device specified by\r
db2ef756 373 ConOut defined in the EFI_SYSTEM_TABLE and waits for a keystroke\r
9095d37b 374 from the console input device specified by ConIn defined in the\r
db2ef756
LG
375 EFI_SYSTEM_TABLE.\r
376\r
377 If there are no strings in the variable argument list, then ASSERT().\r
378 If all the strings in the variable argument list are empty, then ASSERT().\r
379\r
380 @param[in] Attribute Specifies the foreground and background color of the popup.\r
9095d37b 381 @param[out] Key A pointer to the EFI_KEY value of the key that was\r
db2ef756
LG
382 pressed. This is an optional parameter that may be NULL.\r
383 If it is NULL then no wait for a keypress will be performed.\r
384 @param[in] ... The variable argument list that contains pointers to Null-\r
9095d37b 385 terminated Unicode strings to display in the dialog box.\r
db2ef756
LG
386 The variable argument list is terminated by a NULL.\r
387\r
388**/\r
389VOID\r
390EFIAPI\r
391CreatePopUp (\r
9095d37b 392 IN UINTN Attribute,\r
db2ef756
LG
393 OUT EFI_INPUT_KEY *Key, OPTIONAL\r
394 ...\r
395 )\r
396{\r
f04544be 397 EFI_STATUS Status;\r
db2ef756
LG
398 VA_LIST Args;\r
399 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;\r
400 EFI_SIMPLE_TEXT_OUTPUT_MODE SavedConsoleMode;\r
401 UINTN Columns;\r
402 UINTN Rows;\r
403 UINTN Column;\r
404 UINTN Row;\r
405 UINTN NumberOfLines;\r
406 UINTN MaxLength;\r
407 CHAR16 *String;\r
408 UINTN Length;\r
409 CHAR16 *Line;\r
410 UINTN EventIndex;\r
8b5b3d42 411 CHAR16 *TmpString;\r
db2ef756
LG
412\r
413 //\r
9095d37b 414 // Determine the length of the longest line in the popup and the the total\r
db2ef756
LG
415 // number of lines in the popup\r
416 //\r
417 VA_START (Args, Key);\r
418 MaxLength = 0;\r
419 NumberOfLines = 0;\r
420 while ((String = VA_ARG (Args, CHAR16 *)) != NULL) {\r
33026ccf 421 MaxLength = MAX (MaxLength, UefiLibGetStringWidth (String, FALSE, 0, NULL) / 2);\r
db2ef756
LG
422 NumberOfLines++;\r
423 }\r
424 VA_END (Args);\r
425\r
426 //\r
427 // If the total number of lines in the popup is zero, then ASSERT()\r
428 //\r
429 ASSERT (NumberOfLines != 0);\r
430\r
431 //\r
432 // If the maximum length of all the strings is zero, then ASSERT()\r
433 //\r
434 ASSERT (MaxLength != 0);\r
435\r
436 //\r
437 // Cache a pointer to the Simple Text Output Protocol in the EFI System Table\r
438 //\r
439 ConOut = gST->ConOut;\r
9095d37b 440\r
db2ef756
LG
441 //\r
442 // Save the current console cursor position and attributes\r
443 //\r
444 CopyMem (&SavedConsoleMode, ConOut->Mode, sizeof (SavedConsoleMode));\r
445\r
446 //\r
447 // Retrieve the number of columns and rows in the current console mode\r
448 //\r
449 ConOut->QueryMode (ConOut, SavedConsoleMode.Mode, &Columns, &Rows);\r
450\r
451 //\r
452 // Disable cursor and set the foreground and background colors specified by Attribute\r
453 //\r
454 ConOut->EnableCursor (ConOut, FALSE);\r
455 ConOut->SetAttribute (ConOut, Attribute);\r
456\r
457 //\r
458 // Limit NumberOfLines to height of the screen minus 3 rows for the box itself\r
459 //\r
460 NumberOfLines = MIN (NumberOfLines, Rows - 3);\r
461\r
462 //\r
463 // Limit MaxLength to width of the screen minus 2 columns for the box itself\r
464 //\r
465 MaxLength = MIN (MaxLength, Columns - 2);\r
466\r
467 //\r
468 // Compute the starting row and starting column for the popup\r
469 //\r
470 Row = (Rows - (NumberOfLines + 3)) / 2;\r
471 Column = (Columns - (MaxLength + 2)) / 2;\r
472\r
473 //\r
474 // Allocate a buffer for a single line of the popup with borders and a Null-terminator\r
475 //\r
476 Line = AllocateZeroPool ((MaxLength + 3) * sizeof (CHAR16));\r
11171f03 477 ASSERT (Line != NULL);\r
db2ef756
LG
478\r
479 //\r
9095d37b 480 // Draw top of popup box\r
db2ef756
LG
481 //\r
482 SetMem16 (Line, (MaxLength + 2) * 2, BOXDRAW_HORIZONTAL);\r
483 Line[0] = BOXDRAW_DOWN_RIGHT;\r
484 Line[MaxLength + 1] = BOXDRAW_DOWN_LEFT;\r
485 Line[MaxLength + 2] = L'\0';\r
486 ConOut->SetCursorPosition (ConOut, Column, Row++);\r
487 ConOut->OutputString (ConOut, Line);\r
488\r
489 //\r
490 // Draw middle of the popup with strings\r
491 //\r
492 VA_START (Args, Key);\r
493 while ((String = VA_ARG (Args, CHAR16 *)) != NULL && NumberOfLines > 0) {\r
db2ef756 494 SetMem16 (Line, (MaxLength + 2) * 2, L' ');\r
33026ccf
ED
495 Line[0] = BOXDRAW_VERTICAL;\r
496 Line[MaxLength + 1] = BOXDRAW_VERTICAL;\r
497 Line[MaxLength + 2] = L'\0';\r
498 ConOut->SetCursorPosition (ConOut, Column, Row);\r
499 ConOut->OutputString (ConOut, Line);\r
500 Length = UefiLibGetStringWidth (String, FALSE, 0, NULL) / 2;\r
db2ef756
LG
501 if (Length <= MaxLength) {\r
502 //\r
503 // Length <= MaxLength\r
504 //\r
33026ccf
ED
505 ConOut->SetCursorPosition (ConOut, Column + 1 + (MaxLength - Length) / 2, Row++);\r
506 ConOut->OutputString (ConOut, String);\r
db2ef756
LG
507 } else {\r
508 //\r
509 // Length > MaxLength\r
510 //\r
33026ccf 511 UefiLibGetStringWidth (String, TRUE, MaxLength, &Length);\r
8b5b3d42
ED
512 TmpString = AllocateZeroPool ((Length + 1) * sizeof (CHAR16));\r
513 ASSERT (TmpString != NULL);\r
df1e74f5
HW
514 StrnCpyS (TmpString, Length + 1, String, Length - 3);\r
515 StrCatS (TmpString, Length + 1, L"...");\r
33026ccf
ED
516\r
517 ConOut->SetCursorPosition (ConOut, Column + 1, Row++);\r
8b5b3d42
ED
518 ConOut->OutputString (ConOut, TmpString);\r
519 FreePool (TmpString);\r
db2ef756 520 }\r
db2ef756
LG
521 NumberOfLines--;\r
522 }\r
523 VA_END (Args);\r
524\r
525 //\r
526 // Draw bottom of popup box\r
527 //\r
528 SetMem16 (Line, (MaxLength + 2) * 2, BOXDRAW_HORIZONTAL);\r
529 Line[0] = BOXDRAW_UP_RIGHT;\r
530 Line[MaxLength + 1] = BOXDRAW_UP_LEFT;\r
531 Line[MaxLength + 2] = L'\0';\r
532 ConOut->SetCursorPosition (ConOut, Column, Row++);\r
533 ConOut->OutputString (ConOut, Line);\r
534\r
535 //\r
536 // Free the allocated line buffer\r
537 //\r
538 FreePool (Line);\r
539\r
540 //\r
541 // Restore the cursor visibility, position, and attributes\r
542 //\r
543 ConOut->EnableCursor (ConOut, SavedConsoleMode.CursorVisible);\r
544 ConOut->SetCursorPosition (ConOut, SavedConsoleMode.CursorColumn, SavedConsoleMode.CursorRow);\r
545 ConOut->SetAttribute (ConOut, SavedConsoleMode.Attribute);\r
546\r
547 //\r
548 // Wait for a keystroke\r
549 //\r
550 if (Key != NULL) {\r
f04544be
RN
551 while (TRUE) {\r
552 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, Key);\r
553 if (!EFI_ERROR (Status)) {\r
554 break;\r
555 }\r
556\r
557 //\r
558 // If we encounter error, continue to read another key in.\r
559 //\r
560 if (Status != EFI_NOT_READY) {\r
561 continue;\r
562 }\r
563 gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
564 }\r
db2ef756
LG
565 }\r
566}\r