2 Implements inputbar interface functions.
4 Copyright (c) 2005 - 2014, 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.
36 Cleanup function for input bar.
44 // free input bar's prompt and input string
46 SHELL_FREE_NON_NULL (mPrompt
);
47 SHELL_FREE_NON_NULL (mReturnString
);
54 Do the requesting of input.
56 @param[in] LastColumn The last printable column.
57 @param[in] LastRow The last printable row.
71 mPromptLen
= StrLen (mPrompt
);
72 Limit
= LastColumn
- mPromptLen
- 1;
73 Size
= StrLen (mReturnString
);
76 // check whether the mPrompt length and input length will
80 Buffer
= mReturnString
;
82 Buffer
= mReturnString
+ Size
- Limit
;
85 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
87 ShellPrintEx (((INT32
)mPromptLen
), ((INT32
)LastRow
) - 1, L
"%s", Buffer
);
88 Size
= StrLen (Buffer
);
91 // print " " after mPrompt
93 for (Index
= Size
; Index
< Limit
; Index
++) {
94 ShellPrintEx ((INT32
)(mPromptLen
+ Size
), ((INT32
)LastRow
) - 1, L
" ");
97 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
98 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, Size
+ mPromptLen
, LastRow
- 1);
102 UINT32 Foreground
: 4;
103 UINT32 Background
: 3;
104 } INPUT_BAR_COLOR_ATTRIBUTES
;
107 INPUT_BAR_COLOR_ATTRIBUTES Colors
;
109 } INPUT_BAR_COLOR_UNION
;
113 The refresh function for InputBar, it will wait for user input
115 @param[in] LastRow The last printable row.
116 @param[in] LastColumn The last printable column.
118 @retval EFI_SUCCESS The operation was successful.
126 INPUT_BAR_COLOR_UNION Orig
;
127 INPUT_BAR_COLOR_UNION New
;
137 // variable initialization
140 Status
= EFI_SUCCESS
;
143 // back up the old screen attributes
145 CursorCol
= gST
->ConOut
->Mode
->CursorColumn
;
146 CursorRow
= gST
->ConOut
->Mode
->CursorRow
;
147 Orig
.Data
= gST
->ConOut
->Mode
->Attribute
;
149 New
.Colors
.Foreground
= Orig
.Colors
.Background
& 0xF;
150 New
.Colors
.Background
= Orig
.Colors
.Foreground
& 0x7;
152 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
& 0x7F);
157 EditorClearLine (LastRow
, LastColumn
, LastRow
);
159 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, LastRow
- 1);
160 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_EDIT_LIBINPUTBAR_MAININPUTBAR
), gShellDebug1HiiHandle
, mPrompt
);
163 // this is a selection mPrompt, cursor will stay in edit area
164 // actually this is for search , search/replace
166 if (StrStr (mPrompt
, L
"Yes/No")) {
168 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, CursorCol
, CursorRow
);
169 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
174 // wait for user input
177 gBS
->WaitForEvent (1, &gST
->ConIn
->WaitForKey
, &EventIndex
);
178 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
179 if (EFI_ERROR (Status
)) {
185 if (Key
.ScanCode
== SCAN_ESC
) {
187 Status
= EFI_NOT_READY
;
193 if (Key
.UnicodeChar
== CHAR_LINEFEED
|| Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
195 } else if (Key
.UnicodeChar
== CHAR_BACKSPACE
) {
201 mReturnString
[Size
] = CHAR_NULL
;
204 InputBarPrintInput (LastColumn
, LastRow
);
208 } else if (Key
.UnicodeChar
<= 127 && Key
.UnicodeChar
>= 32) {
210 // VALID ASCII char pressed
212 mReturnString
[Size
] = Key
.UnicodeChar
;
215 // should be less than specified length
217 if (Size
>= StringSize
) {
223 mReturnString
[Size
] = CHAR_NULL
;
227 InputBarPrintInput (LastColumn
, LastRow
);
231 // if just choose yes/no
239 mReturnString
[Size
] = CHAR_NULL
;
243 // restore screen attributes
245 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, CursorCol
, CursorRow
);
246 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
252 SetPrompt and wait for input.
254 @param[in] Str The prompt string.
256 @retval EFI_SUCCESS The operation was successful.
257 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
265 // FREE the old mPrompt string
267 SHELL_FREE_NON_NULL (mPrompt
);
269 mPrompt
= CatSPrint (NULL
, L
"%s ", Str
);
270 if (mPrompt
== NULL
) {
271 return EFI_OUT_OF_RESOURCES
;
278 Set the size of the string in characters.
280 @param[in] Size The max number of characters to accept.
282 @retval EFI_SUCCESS The operation was successful.
283 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
286 InputBarSetStringSize (
291 // free the old ReturnStirng
293 SHELL_FREE_NON_NULL (mReturnString
);
296 mReturnString
= AllocateZeroPool ((StringSize
+ 1) * sizeof(mReturnString
[0]));
297 if (mReturnString
== NULL
) {
298 return EFI_OUT_OF_RESOURCES
;
305 Function to retrieve the input from the user.
307 @retval NULL No input has been received.
308 @return The string that was input.
315 return (mReturnString
);