2 Implements inputbar interface functions.
4 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "EditInputBar.h"
10 #include "UefiShellDebug1CommandsLib.h"
12 CHAR16
*mPrompt
; // Input bar mPrompt string.
13 CHAR16
*mReturnString
; // The returned string.
14 UINTN StringSize
; // Size of mReturnString space size.
15 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*mTextInEx
;
18 Initialize the input bar.
20 @param[in] TextInEx Pointer to SimpleTextInEx instance in System Table.
24 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*TextInEx
34 Cleanup function for input bar.
42 // free input bar's prompt and input string
44 SHELL_FREE_NON_NULL (mPrompt
);
45 SHELL_FREE_NON_NULL (mReturnString
);
52 Do the requesting of input.
54 @param[in] LastColumn The last printable column.
55 @param[in] LastRow The last printable row.
69 mPromptLen
= StrLen (mPrompt
);
70 Limit
= LastColumn
- mPromptLen
- 1;
71 Size
= StrLen (mReturnString
);
74 // check whether the mPrompt length and input length will
78 Buffer
= mReturnString
;
80 Buffer
= mReturnString
+ Size
- Limit
;
83 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
85 ShellPrintEx (((INT32
)mPromptLen
), ((INT32
)LastRow
) - 1, L
"%s", Buffer
);
86 Size
= StrLen (Buffer
);
89 // print " " after mPrompt
91 for (Index
= Size
; Index
< Limit
; Index
++) {
92 ShellPrintEx ((INT32
)(mPromptLen
+ Size
), ((INT32
)LastRow
) - 1, L
" ");
95 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
96 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, Size
+ mPromptLen
, LastRow
- 1);
100 UINT32 Foreground
: 4;
101 UINT32 Background
: 3;
102 } INPUT_BAR_COLOR_ATTRIBUTES
;
105 INPUT_BAR_COLOR_ATTRIBUTES Colors
;
107 } INPUT_BAR_COLOR_UNION
;
110 The refresh function for InputBar, it will wait for user input
112 @param[in] LastRow The last printable row.
113 @param[in] LastColumn The last printable column.
115 @retval EFI_SUCCESS The operation was successful.
123 INPUT_BAR_COLOR_UNION Orig
;
124 INPUT_BAR_COLOR_UNION New
;
125 EFI_KEY_DATA KeyData
;
134 // variable initialization
137 Status
= EFI_SUCCESS
;
140 // back up the old screen attributes
142 CursorCol
= gST
->ConOut
->Mode
->CursorColumn
;
143 CursorRow
= gST
->ConOut
->Mode
->CursorRow
;
144 Orig
.Data
= gST
->ConOut
->Mode
->Attribute
;
146 New
.Colors
.Foreground
= Orig
.Colors
.Background
& 0xF;
147 New
.Colors
.Background
= Orig
.Colors
.Foreground
& 0x7;
149 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
& 0x7F);
154 EditorClearLine (LastRow
, LastColumn
, LastRow
);
156 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, LastRow
- 1);
157 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_EDIT_LIBINPUTBAR_MAININPUTBAR
), gShellDebug1HiiHandle
, mPrompt
);
160 // this is a selection mPrompt, cursor will stay in edit area
161 // actually this is for search , search/replace
163 if (StrStr (mPrompt
, L
"Yes/No")) {
165 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, CursorCol
, CursorRow
);
166 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
172 // wait for user input
175 Status
= gBS
->WaitForEvent (1, &mTextInEx
->WaitForKeyEx
, &EventIndex
);
176 if (EFI_ERROR (Status
) || (EventIndex
!= 0)) {
180 Status
= mTextInEx
->ReadKeyStrokeEx (mTextInEx
, &KeyData
);
181 if (EFI_ERROR (Status
)) {
185 if (((KeyData
.KeyState
.KeyShiftState
& EFI_SHIFT_STATE_VALID
) != 0) &&
186 (KeyData
.KeyState
.KeyShiftState
!= EFI_SHIFT_STATE_VALID
))
189 // Shift key pressed.
197 if (KeyData
.Key
.ScanCode
== SCAN_ESC
) {
199 Status
= EFI_NOT_READY
;
206 if ((KeyData
.Key
.UnicodeChar
== CHAR_LINEFEED
) || (KeyData
.Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
)) {
208 } else if (KeyData
.Key
.UnicodeChar
== CHAR_BACKSPACE
) {
214 mReturnString
[Size
] = CHAR_NULL
;
216 InputBarPrintInput (LastColumn
, LastRow
);
219 } else if ((KeyData
.Key
.UnicodeChar
<= 127) && (KeyData
.Key
.UnicodeChar
>= 32)) {
221 // VALID ASCII char pressed
223 mReturnString
[Size
] = KeyData
.Key
.UnicodeChar
;
226 // should be less than specified length
228 if (Size
>= StringSize
) {
234 mReturnString
[Size
] = CHAR_NULL
;
237 InputBarPrintInput (LastColumn
, LastRow
);
240 // if just choose yes/no
247 mReturnString
[Size
] = CHAR_NULL
;
250 // restore screen attributes
252 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, CursorCol
, CursorRow
);
253 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
259 SetPrompt and wait for input.
261 @param[in] Str The prompt string.
263 @retval EFI_SUCCESS The operation was successful.
264 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
272 // FREE the old mPrompt string
274 SHELL_FREE_NON_NULL (mPrompt
);
276 mPrompt
= CatSPrint (NULL
, L
"%s ", Str
);
277 if (mPrompt
== NULL
) {
278 return EFI_OUT_OF_RESOURCES
;
285 Set the size of the string in characters.
287 @param[in] Size The max number of characters to accept.
289 @retval EFI_SUCCESS The operation was successful.
290 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
293 InputBarSetStringSize (
298 // free the old ReturnStirng
300 SHELL_FREE_NON_NULL (mReturnString
);
303 mReturnString
= AllocateZeroPool ((StringSize
+ 1) * sizeof (mReturnString
[0]));
304 if (mReturnString
== NULL
) {
305 return EFI_OUT_OF_RESOURCES
;
312 Function to retrieve the input from the user.
314 @retval NULL No input has been received.
315 @return The string that was input.
322 return (mReturnString
);