2 Implements inputbar interface functions.
4 Copyright (c) 2005 - 2018, 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.
21 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*mTextInEx
;
24 Initialize the input bar.
26 @param[in] TextInEx Pointer to SimpleTextInEx instance in System Table.
30 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*TextInEx
40 Cleanup function for input bar.
48 // free input bar's prompt and input string
50 SHELL_FREE_NON_NULL (mPrompt
);
51 SHELL_FREE_NON_NULL (mReturnString
);
58 Do the requesting of input.
60 @param[in] LastColumn The last printable column.
61 @param[in] LastRow The last printable row.
75 mPromptLen
= StrLen (mPrompt
);
76 Limit
= LastColumn
- mPromptLen
- 1;
77 Size
= StrLen (mReturnString
);
80 // check whether the mPrompt length and input length will
84 Buffer
= mReturnString
;
86 Buffer
= mReturnString
+ Size
- Limit
;
89 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
91 ShellPrintEx (((INT32
)mPromptLen
), ((INT32
)LastRow
) - 1, L
"%s", Buffer
);
92 Size
= StrLen (Buffer
);
95 // print " " after mPrompt
97 for (Index
= Size
; Index
< Limit
; Index
++) {
98 ShellPrintEx ((INT32
)(mPromptLen
+ Size
), ((INT32
)LastRow
) - 1, L
" ");
101 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
102 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, Size
+ mPromptLen
, LastRow
- 1);
106 UINT32 Foreground
: 4;
107 UINT32 Background
: 3;
108 } INPUT_BAR_COLOR_ATTRIBUTES
;
111 INPUT_BAR_COLOR_ATTRIBUTES Colors
;
113 } INPUT_BAR_COLOR_UNION
;
117 The refresh function for InputBar, it will wait for user input
119 @param[in] LastRow The last printable row.
120 @param[in] LastColumn The last printable column.
122 @retval EFI_SUCCESS The operation was successful.
130 INPUT_BAR_COLOR_UNION Orig
;
131 INPUT_BAR_COLOR_UNION New
;
132 EFI_KEY_DATA KeyData
;
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
;
153 New
.Colors
.Foreground
= Orig
.Colors
.Background
& 0xF;
154 New
.Colors
.Background
= Orig
.Colors
.Foreground
& 0x7;
156 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
& 0x7F);
161 EditorClearLine (LastRow
, LastColumn
, LastRow
);
163 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, LastRow
- 1);
164 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_EDIT_LIBINPUTBAR_MAININPUTBAR
), gShellDebug1HiiHandle
, mPrompt
);
167 // this is a selection mPrompt, cursor will stay in edit area
168 // actually this is for search , search/replace
170 if (StrStr (mPrompt
, L
"Yes/No")) {
172 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, CursorCol
, CursorRow
);
173 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
178 // wait for user input
181 Status
= gBS
->WaitForEvent (1, &mTextInEx
->WaitForKeyEx
, &EventIndex
);
182 if (EFI_ERROR (Status
) || (EventIndex
!= 0)) {
185 Status
= mTextInEx
->ReadKeyStrokeEx (mTextInEx
, &KeyData
);
186 if (EFI_ERROR (Status
)) {
189 if (((KeyData
.KeyState
.KeyShiftState
& EFI_SHIFT_STATE_VALID
) != 0) &&
190 (KeyData
.KeyState
.KeyShiftState
!= EFI_SHIFT_STATE_VALID
)) {
192 // Shift key pressed.
199 if (KeyData
.Key
.ScanCode
== SCAN_ESC
) {
201 Status
= EFI_NOT_READY
;
207 if (KeyData
.Key
.UnicodeChar
== CHAR_LINEFEED
|| KeyData
.Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
209 } else if (KeyData
.Key
.UnicodeChar
== CHAR_BACKSPACE
) {
215 mReturnString
[Size
] = CHAR_NULL
;
218 InputBarPrintInput (LastColumn
, LastRow
);
222 } else if (KeyData
.Key
.UnicodeChar
<= 127 && KeyData
.Key
.UnicodeChar
>= 32) {
224 // VALID ASCII char pressed
226 mReturnString
[Size
] = KeyData
.Key
.UnicodeChar
;
229 // should be less than specified length
231 if (Size
>= StringSize
) {
237 mReturnString
[Size
] = CHAR_NULL
;
241 InputBarPrintInput (LastColumn
, LastRow
);
245 // if just choose yes/no
253 mReturnString
[Size
] = CHAR_NULL
;
257 // restore screen attributes
259 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, CursorCol
, CursorRow
);
260 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
266 SetPrompt and wait for input.
268 @param[in] Str The prompt string.
270 @retval EFI_SUCCESS The operation was successful.
271 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
279 // FREE the old mPrompt string
281 SHELL_FREE_NON_NULL (mPrompt
);
283 mPrompt
= CatSPrint (NULL
, L
"%s ", Str
);
284 if (mPrompt
== NULL
) {
285 return EFI_OUT_OF_RESOURCES
;
292 Set the size of the string in characters.
294 @param[in] Size The max number of characters to accept.
296 @retval EFI_SUCCESS The operation was successful.
297 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
300 InputBarSetStringSize (
305 // free the old ReturnStirng
307 SHELL_FREE_NON_NULL (mReturnString
);
310 mReturnString
= AllocateZeroPool ((StringSize
+ 1) * sizeof(mReturnString
[0]));
311 if (mReturnString
== NULL
) {
312 return EFI_OUT_OF_RESOURCES
;
319 Function to retrieve the input from the user.
321 @retval NULL No input has been received.
322 @return The string that was input.
329 return (mReturnString
);