]>
Commit | Line | Data |
---|---|---|
2442e62a | 1 | /** @file\r |
2 | Implements inputbar interface functions.\r | |
3 | \r | |
4 | Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "EditInputBar.h"\r | |
16 | #include "UefiShellDebug1CommandsLib.h"\r | |
17 | \r | |
18 | CHAR16 *mPrompt; // Input bar mPrompt string.\r | |
19 | CHAR16 *mReturnString; // The returned string.\r | |
20 | UINTN StringSize; // Size of mReturnString space size.\r | |
21 | \r | |
22 | /**\r | |
23 | Initialize the input bar.\r | |
24 | **/\r | |
25 | VOID\r | |
26 | EFIAPI\r | |
27 | InputBarInit (\r | |
28 | VOID\r | |
29 | )\r | |
30 | {\r | |
31 | mPrompt = NULL;\r | |
32 | mReturnString = NULL;\r | |
33 | StringSize = 0;\r | |
34 | }\r | |
35 | \r | |
36 | /**\r | |
37 | Cleanup function for input bar.\r | |
38 | **/\r | |
39 | VOID\r | |
40 | EFIAPI\r | |
41 | InputBarCleanup (\r | |
42 | VOID\r | |
43 | )\r | |
44 | {\r | |
45 | //\r | |
46 | // free input bar's prompt and input string\r | |
47 | //\r | |
48 | SHELL_FREE_NON_NULL (mPrompt);\r | |
49 | SHELL_FREE_NON_NULL (mReturnString);\r | |
50 | mPrompt = NULL;\r | |
51 | mReturnString = NULL;\r | |
52 | }\r | |
53 | \r | |
54 | /**\r | |
55 | Display the prompt.\r | |
56 | Do the requesting of input.\r | |
57 | \r | |
58 | @param[in] LastColumn The last printable column.\r | |
59 | @param[in] LastRow The last printable row.\r | |
60 | **/\r | |
61 | VOID\r | |
62 | EFIAPI\r | |
63 | InputBarPrintInput (\r | |
64 | IN UINTN LastColumn,\r | |
65 | IN UINTN LastRow\r | |
66 | )\r | |
67 | {\r | |
68 | UINTN Limit;\r | |
69 | UINTN Size;\r | |
70 | CHAR16 *Buffer;\r | |
71 | UINTN Index;\r | |
72 | UINTN mPromptLen;\r | |
73 | \r | |
74 | mPromptLen = StrLen (mPrompt);\r | |
75 | Limit = LastColumn - mPromptLen - 1;\r | |
76 | Size = StrLen (mReturnString);\r | |
77 | \r | |
78 | //\r | |
79 | // check whether the mPrompt length and input length will\r | |
80 | // exceed limit\r | |
81 | //\r | |
82 | if (Size <= Limit) {\r | |
83 | Buffer = mReturnString;\r | |
84 | } else {\r | |
85 | Buffer = mReturnString + Size - Limit;\r | |
86 | }\r | |
87 | \r | |
88 | gST->ConOut->EnableCursor (gST->ConOut, FALSE);\r | |
89 | \r | |
90 | ShellPrintEx (((INT32)mPromptLen), ((INT32)LastRow) - 4, L"%s", Buffer);\r | |
91 | Size = StrLen (Buffer);\r | |
92 | \r | |
93 | //\r | |
94 | // print " " after mPrompt\r | |
95 | //\r | |
96 | for (Index = Size; Index < Limit; Index++) {\r | |
97 | ShellPrintEx ((INT32)(mPromptLen + Size), ((INT32)LastRow) - 4, L" ");\r | |
98 | }\r | |
99 | \r | |
100 | gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r | |
101 | gST->ConOut->SetCursorPosition (gST->ConOut, Size + mPromptLen, LastRow - 4);\r | |
102 | }\r | |
103 | \r | |
104 | typedef struct {\r | |
105 | UINT32 Foreground : 4;\r | |
106 | UINT32 Background : 4;\r | |
107 | } INPUT_BAR_COLOR_ATTRIBUTES;\r | |
108 | \r | |
109 | typedef union {\r | |
110 | INPUT_BAR_COLOR_ATTRIBUTES Colors;\r | |
111 | UINTN Data;\r | |
112 | } INPUT_BAR_COLOR_UNION;\r | |
113 | \r | |
114 | \r | |
115 | /**\r | |
116 | The refresh function for InputBar, it will wait for user input\r | |
117 | \r | |
118 | @param[in] LastRow The last printable row.\r | |
119 | @param[in] LastColumn The last printable column.\r | |
120 | \r | |
121 | @retval EFI_SUCCESS The operation was successful.\r | |
122 | **/\r | |
123 | EFI_STATUS\r | |
124 | EFIAPI\r | |
125 | InputBarRefresh (\r | |
126 | UINTN LastRow,\r | |
127 | UINTN LastColumn\r | |
128 | )\r | |
129 | {\r | |
130 | INPUT_BAR_COLOR_UNION Orig;\r | |
131 | INPUT_BAR_COLOR_UNION New;\r | |
132 | EFI_INPUT_KEY Key;\r | |
133 | UINTN Size;\r | |
134 | EFI_STATUS Status;\r | |
135 | BOOLEAN NoDisplay;\r | |
136 | UINTN Limit;\r | |
137 | UINTN mPromptLen;\r | |
138 | UINTN EventIndex;\r | |
139 | UINTN CursorRow;\r | |
140 | UINTN CursorCol;\r | |
141 | \r | |
142 | //\r | |
143 | // variable initialization\r | |
144 | //\r | |
145 | Size = 0;\r | |
146 | Status = EFI_SUCCESS;\r | |
147 | \r | |
148 | //\r | |
149 | // back up the old screen attributes\r | |
150 | //\r | |
151 | CursorCol = gST->ConOut->Mode->CursorColumn;\r | |
152 | CursorRow = gST->ConOut->Mode->CursorRow;\r | |
153 | Orig.Data = gST->ConOut->Mode->Attribute;\r | |
154 | New.Colors.Foreground = Orig.Colors.Background;\r | |
155 | New.Colors.Background = Orig.Colors.Foreground;\r | |
156 | \r | |
157 | gST->ConOut->SetAttribute (gST->ConOut, New.Data);\r | |
158 | \r | |
159 | //\r | |
160 | // clear input bar\r | |
161 | //\r | |
162 | EditorClearLine (LastRow - 3, LastColumn, LastRow);\r | |
163 | \r | |
164 | gST->ConOut->SetCursorPosition (gST->ConOut, 0, LastRow - 4);\r | |
165 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_LIBINPUTBAR_MAININPUTBAR), gShellDebug1HiiHandle, mPrompt);\r | |
166 | \r | |
167 | //\r | |
168 | // that's the maximum input length that can be displayed on screen\r | |
169 | //\r | |
170 | mPromptLen = StrLen (mPrompt);\r | |
171 | Limit = LastColumn - mPromptLen;\r | |
172 | \r | |
173 | //\r | |
174 | // this is a selection mPrompt, cursor will stay in edit area\r | |
175 | // actually this is for search , search/replace\r | |
176 | //\r | |
177 | if (StrStr (mPrompt, L"Yes/No")) {\r | |
178 | NoDisplay = TRUE;\r | |
179 | gST->ConOut->SetCursorPosition (gST->ConOut, CursorCol, CursorRow);\r | |
180 | gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r | |
181 | } else {\r | |
182 | NoDisplay = FALSE;\r | |
183 | }\r | |
184 | //\r | |
185 | // wait for user input\r | |
186 | //\r | |
187 | for (;;) {\r | |
188 | gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r | |
189 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r | |
190 | if (EFI_ERROR (Status)) {\r | |
191 | continue;\r | |
192 | }\r | |
193 | //\r | |
194 | // pressed ESC\r | |
195 | //\r | |
196 | if (Key.ScanCode == SCAN_ESC) {\r | |
197 | Size = 0;\r | |
198 | Status = EFI_NOT_READY;\r | |
199 | break;\r | |
200 | }\r | |
201 | //\r | |
202 | // return pressed\r | |
203 | //\r | |
204 | if (Key.UnicodeChar == CHAR_LINEFEED || Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r | |
205 | break;\r | |
206 | } else if (Key.UnicodeChar == CHAR_BACKSPACE) {\r | |
207 | //\r | |
208 | // backspace\r | |
209 | //\r | |
210 | if (Size > 0) {\r | |
211 | Size--;\r | |
212 | mReturnString[Size] = CHAR_NULL;\r | |
213 | if (!NoDisplay) {\r | |
214 | \r | |
215 | InputBarPrintInput (LastColumn, LastRow);\r | |
216 | \r | |
217 | }\r | |
218 | }\r | |
219 | } else if (Key.UnicodeChar <= 127 && Key.UnicodeChar >= 32) {\r | |
220 | //\r | |
221 | // VALID ASCII char pressed\r | |
222 | //\r | |
223 | mReturnString[Size] = Key.UnicodeChar;\r | |
224 | \r | |
225 | //\r | |
226 | // should be less than specified length\r | |
227 | //\r | |
228 | if (Size >= StringSize) {\r | |
229 | continue;\r | |
230 | }\r | |
231 | \r | |
232 | Size++;\r | |
233 | \r | |
234 | mReturnString[Size] = CHAR_NULL;\r | |
235 | \r | |
236 | if (!NoDisplay) {\r | |
237 | \r | |
238 | InputBarPrintInput (LastColumn, LastRow);\r | |
239 | \r | |
240 | } else {\r | |
241 | //\r | |
242 | // if just choose yes/no\r | |
243 | //\r | |
244 | break;\r | |
245 | }\r | |
246 | \r | |
247 | }\r | |
248 | }\r | |
249 | \r | |
250 | mReturnString[Size] = CHAR_NULL;\r | |
251 | \r | |
252 | \r | |
253 | //\r | |
254 | // restore screen attributes\r | |
255 | //\r | |
256 | gST->ConOut->SetCursorPosition (gST->ConOut, CursorCol, CursorRow);\r | |
257 | gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r | |
258 | \r | |
259 | return Status;\r | |
260 | }\r | |
261 | \r | |
262 | /**\r | |
263 | SetPrompt and wait for input.\r | |
264 | \r | |
265 | @param[in] Str The prompt string.\r | |
266 | \r | |
267 | @retval EFI_SUCCESS The operation was successful.\r | |
268 | @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r | |
269 | **/\r | |
270 | EFI_STATUS\r | |
271 | EFIAPI\r | |
272 | InputBarSetPrompt (\r | |
273 | IN CONST CHAR16 *Str\r | |
274 | )\r | |
275 | {\r | |
276 | //\r | |
277 | // FREE the old mPrompt string\r | |
278 | //\r | |
279 | SHELL_FREE_NON_NULL (mPrompt);\r | |
280 | \r | |
281 | mPrompt = CatSPrint (NULL, L"%s ", Str);\r | |
282 | if (mPrompt == NULL) {\r | |
283 | return EFI_OUT_OF_RESOURCES;\r | |
284 | }\r | |
285 | \r | |
286 | return EFI_SUCCESS;\r | |
287 | }\r | |
288 | \r | |
289 | /**\r | |
290 | Set the size of the string in characters.\r | |
291 | \r | |
292 | @param[in] Size The max number of characters to accept.\r | |
293 | \r | |
294 | @retval EFI_SUCCESS The operation was successful.\r | |
295 | @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r | |
296 | **/\r | |
297 | EFI_STATUS\r | |
298 | EFIAPI\r | |
299 | InputBarSetStringSize (\r | |
300 | UINTN Size\r | |
301 | )\r | |
302 | {\r | |
303 | //\r | |
304 | // free the old ReturnStirng\r | |
305 | //\r | |
306 | SHELL_FREE_NON_NULL (mReturnString);\r | |
307 | \r | |
308 | StringSize = Size;\r | |
309 | mReturnString = AllocateZeroPool ((StringSize + 1) * sizeof(mReturnString[0]));\r | |
310 | if (mReturnString == NULL) {\r | |
311 | return EFI_OUT_OF_RESOURCES;\r | |
312 | }\r | |
313 | \r | |
314 | return EFI_SUCCESS;\r | |
315 | }\r | |
316 | \r | |
317 | /**\r | |
318 | Function to retrieve the input from the user.\r | |
319 | \r | |
320 | @retval NULL No input has been received.\r | |
321 | @return The string that was input.\r | |
322 | **/\r | |
323 | CONST CHAR16*\r | |
324 | EFIAPI\r | |
325 | InputBarGetString (\r | |
326 | VOID\r | |
327 | )\r | |
328 | {\r | |
329 | return (mReturnString);\r | |
330 | }\r |