]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.c
ShellPkg: Fix ARM build errors.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / EditInputBar.c
CommitLineData
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
18CHAR16 *mPrompt; // Input bar mPrompt string.\r
19CHAR16 *mReturnString; // The returned string.\r
20UINTN StringSize; // Size of mReturnString space size.\r
21\r
22/**\r
23 Initialize the input bar.\r
24**/\r
25VOID\r
26EFIAPI\r
27InputBarInit (\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
39VOID\r
40EFIAPI\r
41InputBarCleanup (\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
61VOID\r
62EFIAPI\r
63InputBarPrintInput (\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
5a2beb74 90 ShellPrintEx (((INT32)mPromptLen), ((INT32)LastRow) - 1, L"%s", Buffer);\r
2442e62a 91 Size = StrLen (Buffer);\r
92\r
93 //\r
94 // print " " after mPrompt\r
95 //\r
96 for (Index = Size; Index < Limit; Index++) {\r
5a2beb74 97 ShellPrintEx ((INT32)(mPromptLen + Size), ((INT32)LastRow) - 1, L" ");\r
2442e62a 98 }\r
99\r
100 gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
5a2beb74 101 gST->ConOut->SetCursorPosition (gST->ConOut, Size + mPromptLen, LastRow - 1);\r
2442e62a 102}\r
103\r
104typedef struct {\r
105 UINT32 Foreground : 4;\r
106 UINT32 Background : 4;\r
107} INPUT_BAR_COLOR_ATTRIBUTES;\r
108\r
109typedef 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
123EFI_STATUS\r
124EFIAPI\r
125InputBarRefresh (\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
2442e62a 136 UINTN EventIndex;\r
137 UINTN CursorRow;\r
138 UINTN CursorCol;\r
139\r
140 //\r
141 // variable initialization\r
142 //\r
143 Size = 0;\r
144 Status = EFI_SUCCESS;\r
145\r
146 //\r
147 // back up the old screen attributes\r
148 //\r
149 CursorCol = gST->ConOut->Mode->CursorColumn;\r
150 CursorRow = gST->ConOut->Mode->CursorRow;\r
151 Orig.Data = gST->ConOut->Mode->Attribute;\r
28981267 152 New.Data = 0;\r
2442e62a 153 New.Colors.Foreground = Orig.Colors.Background;\r
154 New.Colors.Background = Orig.Colors.Foreground;\r
155\r
156 gST->ConOut->SetAttribute (gST->ConOut, New.Data);\r
157\r
158 //\r
159 // clear input bar\r
160 //\r
5a2beb74 161 EditorClearLine (LastRow , LastColumn, LastRow);\r
2442e62a 162\r
5a2beb74 163 gST->ConOut->SetCursorPosition (gST->ConOut, 0, LastRow - 1);\r
2442e62a 164 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_LIBINPUTBAR_MAININPUTBAR), gShellDebug1HiiHandle, mPrompt);\r
165\r
2442e62a 166 //\r
167 // this is a selection mPrompt, cursor will stay in edit area\r
168 // actually this is for search , search/replace\r
169 //\r
170 if (StrStr (mPrompt, L"Yes/No")) {\r
171 NoDisplay = TRUE;\r
172 gST->ConOut->SetCursorPosition (gST->ConOut, CursorCol, CursorRow);\r
173 gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
174 } else {\r
175 NoDisplay = FALSE;\r
176 }\r
177 //\r
178 // wait for user input\r
179 //\r
180 for (;;) {\r
181 gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
182 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
183 if (EFI_ERROR (Status)) {\r
184 continue;\r
185 }\r
186 //\r
187 // pressed ESC\r
188 //\r
189 if (Key.ScanCode == SCAN_ESC) {\r
190 Size = 0;\r
191 Status = EFI_NOT_READY;\r
192 break;\r
193 }\r
194 //\r
195 // return pressed\r
196 //\r
197 if (Key.UnicodeChar == CHAR_LINEFEED || Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
198 break;\r
199 } else if (Key.UnicodeChar == CHAR_BACKSPACE) {\r
200 //\r
201 // backspace\r
202 //\r
203 if (Size > 0) {\r
204 Size--;\r
205 mReturnString[Size] = CHAR_NULL;\r
206 if (!NoDisplay) {\r
207\r
208 InputBarPrintInput (LastColumn, LastRow);\r
209\r
210 }\r
211 }\r
212 } else if (Key.UnicodeChar <= 127 && Key.UnicodeChar >= 32) {\r
213 //\r
214 // VALID ASCII char pressed\r
215 //\r
216 mReturnString[Size] = Key.UnicodeChar;\r
217\r
218 //\r
219 // should be less than specified length\r
220 //\r
221 if (Size >= StringSize) {\r
222 continue;\r
223 }\r
224\r
225 Size++;\r
226\r
227 mReturnString[Size] = CHAR_NULL;\r
228\r
229 if (!NoDisplay) {\r
230\r
231 InputBarPrintInput (LastColumn, LastRow);\r
232\r
233 } else {\r
234 //\r
235 // if just choose yes/no\r
236 //\r
237 break;\r
238 }\r
239\r
240 }\r
241 }\r
242\r
243 mReturnString[Size] = CHAR_NULL;\r
244 \r
245\r
246 //\r
247 // restore screen attributes\r
248 //\r
249 gST->ConOut->SetCursorPosition (gST->ConOut, CursorCol, CursorRow);\r
250 gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
251\r
252 return Status;\r
253}\r
254\r
255/**\r
256 SetPrompt and wait for input.\r
257\r
258 @param[in] Str The prompt string.\r
259\r
260 @retval EFI_SUCCESS The operation was successful.\r
261 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
262**/\r
263EFI_STATUS\r
264EFIAPI\r
265InputBarSetPrompt (\r
266 IN CONST CHAR16 *Str\r
267 )\r
268{\r
269 //\r
270 // FREE the old mPrompt string\r
271 //\r
272 SHELL_FREE_NON_NULL (mPrompt);\r
273\r
274 mPrompt = CatSPrint (NULL, L"%s ", Str);\r
275 if (mPrompt == NULL) {\r
276 return EFI_OUT_OF_RESOURCES;\r
277 }\r
278\r
279 return EFI_SUCCESS;\r
280}\r
281\r
282/**\r
283 Set the size of the string in characters.\r
284\r
285 @param[in] Size The max number of characters to accept.\r
286\r
287 @retval EFI_SUCCESS The operation was successful.\r
288 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
289**/\r
290EFI_STATUS\r
291EFIAPI\r
292InputBarSetStringSize (\r
293 UINTN Size\r
294 )\r
295{\r
296 //\r
297 // free the old ReturnStirng\r
298 //\r
299 SHELL_FREE_NON_NULL (mReturnString);\r
300\r
301 StringSize = Size;\r
302 mReturnString = AllocateZeroPool ((StringSize + 1) * sizeof(mReturnString[0]));\r
303 if (mReturnString == NULL) {\r
304 return EFI_OUT_OF_RESOURCES;\r
305 }\r
306\r
307 return EFI_SUCCESS;\r
308}\r
309\r
310/**\r
311 Function to retrieve the input from the user.\r
312\r
313 @retval NULL No input has been received.\r
314 @return The string that was input.\r
315**/\r
316CONST CHAR16*\r
317EFIAPI\r
318InputBarGetString (\r
319 VOID\r
320 )\r
321{\r
322 return (mReturnString);\r
323}\r