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
;
141 // variable initialization
144 Status
= EFI_SUCCESS
;
147 // back up the old screen attributes
149 CursorCol
= gST
->ConOut
->Mode
->CursorColumn
;
150 CursorRow
= gST
->ConOut
->Mode
->CursorRow
;
151 Orig
.Data
= gST
->ConOut
->Mode
->Attribute
;
152 New
.Colors
.Foreground
= Orig
.Colors
.Background
;
153 New
.Colors
.Background
= Orig
.Colors
.Foreground
;
155 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
);
160 EditorClearLine (LastRow
, LastColumn
, LastRow
);
162 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, LastRow
- 1);
163 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_EDIT_LIBINPUTBAR_MAININPUTBAR
), gShellDebug1HiiHandle
, mPrompt
);
166 // this is a selection mPrompt, cursor will stay in edit area
167 // actually this is for search , search/replace
169 if (StrStr (mPrompt
, L
"Yes/No")) {
171 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, CursorCol
, CursorRow
);
172 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
177 // wait for user input
180 gBS
->WaitForEvent (1, &gST
->ConIn
->WaitForKey
, &EventIndex
);
181 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
182 if (EFI_ERROR (Status
)) {
188 if (Key
.ScanCode
== SCAN_ESC
) {
190 Status
= EFI_NOT_READY
;
196 if (Key
.UnicodeChar
== CHAR_LINEFEED
|| Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
198 } else if (Key
.UnicodeChar
== CHAR_BACKSPACE
) {
204 mReturnString
[Size
] = CHAR_NULL
;
207 InputBarPrintInput (LastColumn
, LastRow
);
211 } else if (Key
.UnicodeChar
<= 127 && Key
.UnicodeChar
>= 32) {
213 // VALID ASCII char pressed
215 mReturnString
[Size
] = Key
.UnicodeChar
;
218 // should be less than specified length
220 if (Size
>= StringSize
) {
226 mReturnString
[Size
] = CHAR_NULL
;
230 InputBarPrintInput (LastColumn
, LastRow
);
234 // if just choose yes/no
242 mReturnString
[Size
] = CHAR_NULL
;
246 // restore screen attributes
248 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, CursorCol
, CursorRow
);
249 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
255 SetPrompt and wait for input.
257 @param[in] Str The prompt string.
259 @retval EFI_SUCCESS The operation was successful.
260 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
269 // FREE the old mPrompt string
271 SHELL_FREE_NON_NULL (mPrompt
);
273 mPrompt
= CatSPrint (NULL
, L
"%s ", Str
);
274 if (mPrompt
== NULL
) {
275 return EFI_OUT_OF_RESOURCES
;
282 Set the size of the string in characters.
284 @param[in] Size The max number of characters to accept.
286 @retval EFI_SUCCESS The operation was successful.
287 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
291 InputBarSetStringSize (
296 // free the old ReturnStirng
298 SHELL_FREE_NON_NULL (mReturnString
);
301 mReturnString
= AllocateZeroPool ((StringSize
+ 1) * sizeof(mReturnString
[0]));
302 if (mReturnString
== NULL
) {
303 return EFI_OUT_OF_RESOURCES
;
310 Function to retrieve the input from the user.
312 @retval NULL No input has been received.
313 @return The string that was input.
321 return (mReturnString
);