2 Implements inputbar interface functions.
4 Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "EditInputBar.h"
16 #include "UefiShellDebug1CommandsLib.h"
18 CHAR16
*mPrompt
; // Input bar mPrompt string.
19 CHAR16
*mReturnString
; // The returned string.
20 UINTN StringSize
; // Size of mReturnString space size.
23 Initialize the input bar.
37 Cleanup function for input bar.
46 // free input bar's prompt and input string
48 SHELL_FREE_NON_NULL (mPrompt
);
49 SHELL_FREE_NON_NULL (mReturnString
);
56 Do the requesting of input.
58 @param[in] LastColumn The last printable column.
59 @param[in] LastRow The last printable row.
74 mPromptLen
= StrLen (mPrompt
);
75 Limit
= LastColumn
- mPromptLen
- 1;
76 Size
= StrLen (mReturnString
);
79 // check whether the mPrompt length and input length will
83 Buffer
= mReturnString
;
85 Buffer
= mReturnString
+ Size
- Limit
;
88 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
90 ShellPrintEx (((INT32
)mPromptLen
), ((INT32
)LastRow
) - 1, L
"%s", Buffer
);
91 Size
= StrLen (Buffer
);
94 // print " " after mPrompt
96 for (Index
= Size
; Index
< Limit
; Index
++) {
97 ShellPrintEx ((INT32
)(mPromptLen
+ Size
), ((INT32
)LastRow
) - 1, L
" ");
100 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
101 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, Size
+ mPromptLen
, LastRow
- 1);
105 UINT32 Foreground
: 4;
106 UINT32 Background
: 4;
107 } INPUT_BAR_COLOR_ATTRIBUTES
;
110 INPUT_BAR_COLOR_ATTRIBUTES Colors
;
112 } INPUT_BAR_COLOR_UNION
;
116 The refresh function for InputBar, it will wait for user input
118 @param[in] LastRow The last printable row.
119 @param[in] LastColumn The last printable column.
121 @retval EFI_SUCCESS The operation was successful.
130 INPUT_BAR_COLOR_UNION Orig
;
131 INPUT_BAR_COLOR_UNION New
;
143 // variable initialization
146 Status
= EFI_SUCCESS
;
149 // back up the old screen attributes
151 CursorCol
= gST
->ConOut
->Mode
->CursorColumn
;
152 CursorRow
= gST
->ConOut
->Mode
->CursorRow
;
153 Orig
.Data
= gST
->ConOut
->Mode
->Attribute
;
154 New
.Colors
.Foreground
= Orig
.Colors
.Background
;
155 New
.Colors
.Background
= Orig
.Colors
.Foreground
;
157 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
);
162 EditorClearLine (LastRow
, LastColumn
, LastRow
);
164 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, LastRow
- 1);
165 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_EDIT_LIBINPUTBAR_MAININPUTBAR
), gShellDebug1HiiHandle
, mPrompt
);
168 // that's the maximum input length that can be displayed on screen
170 mPromptLen
= StrLen (mPrompt
);
171 Limit
= LastColumn
- mPromptLen
;
174 // this is a selection mPrompt, cursor will stay in edit area
175 // actually this is for search , search/replace
177 if (StrStr (mPrompt
, L
"Yes/No")) {
179 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, CursorCol
, CursorRow
);
180 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
185 // wait for user input
188 gBS
->WaitForEvent (1, &gST
->ConIn
->WaitForKey
, &EventIndex
);
189 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
190 if (EFI_ERROR (Status
)) {
196 if (Key
.ScanCode
== SCAN_ESC
) {
198 Status
= EFI_NOT_READY
;
204 if (Key
.UnicodeChar
== CHAR_LINEFEED
|| Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
206 } else if (Key
.UnicodeChar
== CHAR_BACKSPACE
) {
212 mReturnString
[Size
] = CHAR_NULL
;
215 InputBarPrintInput (LastColumn
, LastRow
);
219 } else if (Key
.UnicodeChar
<= 127 && Key
.UnicodeChar
>= 32) {
221 // VALID ASCII char pressed
223 mReturnString
[Size
] = Key
.UnicodeChar
;
226 // should be less than specified length
228 if (Size
>= StringSize
) {
234 mReturnString
[Size
] = CHAR_NULL
;
238 InputBarPrintInput (LastColumn
, LastRow
);
242 // if just choose yes/no
250 mReturnString
[Size
] = CHAR_NULL
;
254 // restore screen attributes
256 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, CursorCol
, CursorRow
);
257 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
263 SetPrompt and wait for input.
265 @param[in] Str The prompt string.
267 @retval EFI_SUCCESS The operation was successful.
268 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
277 // FREE the old mPrompt string
279 SHELL_FREE_NON_NULL (mPrompt
);
281 mPrompt
= CatSPrint (NULL
, L
"%s ", Str
);
282 if (mPrompt
== NULL
) {
283 return EFI_OUT_OF_RESOURCES
;
290 Set the size of the string in characters.
292 @param[in] Size The max number of characters to accept.
294 @retval EFI_SUCCESS The operation was successful.
295 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
299 InputBarSetStringSize (
304 // free the old ReturnStirng
306 SHELL_FREE_NON_NULL (mReturnString
);
309 mReturnString
= AllocateZeroPool ((StringSize
+ 1) * sizeof(mReturnString
[0]));
310 if (mReturnString
== NULL
) {
311 return EFI_OUT_OF_RESOURCES
;
318 Function to retrieve the input from the user.
320 @retval NULL No input has been received.
321 @return The string that was input.
329 return (mReturnString
);