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