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
;
111 The refresh function for InputBar, it will wait for user input
113 @param[in] LastRow The last printable row.
114 @param[in] LastColumn The last printable column.
116 @retval EFI_SUCCESS The operation was successful.
124 INPUT_BAR_COLOR_UNION Orig
;
125 INPUT_BAR_COLOR_UNION New
;
126 EFI_KEY_DATA KeyData
;
135 // variable initialization
138 Status
= EFI_SUCCESS
;
141 // back up the old screen attributes
143 CursorCol
= gST
->ConOut
->Mode
->CursorColumn
;
144 CursorRow
= gST
->ConOut
->Mode
->CursorRow
;
145 Orig
.Data
= gST
->ConOut
->Mode
->Attribute
;
147 New
.Colors
.Foreground
= Orig
.Colors
.Background
& 0xF;
148 New
.Colors
.Background
= Orig
.Colors
.Foreground
& 0x7;
150 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
& 0x7F);
155 EditorClearLine (LastRow
, LastColumn
, LastRow
);
157 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, LastRow
- 1);
158 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_EDIT_LIBINPUTBAR_MAININPUTBAR
), gShellDebug1HiiHandle
, mPrompt
);
161 // this is a selection mPrompt, cursor will stay in edit area
162 // actually this is for search , search/replace
164 if (StrStr (mPrompt
, L
"Yes/No")) {
166 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, CursorCol
, CursorRow
);
167 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)) {
179 Status
= mTextInEx
->ReadKeyStrokeEx (mTextInEx
, &KeyData
);
180 if (EFI_ERROR (Status
)) {
183 if (((KeyData
.KeyState
.KeyShiftState
& EFI_SHIFT_STATE_VALID
) != 0) &&
184 (KeyData
.KeyState
.KeyShiftState
!= EFI_SHIFT_STATE_VALID
)) {
186 // Shift key pressed.
193 if (KeyData
.Key
.ScanCode
== SCAN_ESC
) {
195 Status
= EFI_NOT_READY
;
201 if (KeyData
.Key
.UnicodeChar
== CHAR_LINEFEED
|| KeyData
.Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
203 } else if (KeyData
.Key
.UnicodeChar
== CHAR_BACKSPACE
) {
209 mReturnString
[Size
] = CHAR_NULL
;
212 InputBarPrintInput (LastColumn
, LastRow
);
216 } else if (KeyData
.Key
.UnicodeChar
<= 127 && KeyData
.Key
.UnicodeChar
>= 32) {
218 // VALID ASCII char pressed
220 mReturnString
[Size
] = KeyData
.Key
.UnicodeChar
;
223 // should be less than specified length
225 if (Size
>= StringSize
) {
231 mReturnString
[Size
] = CHAR_NULL
;
235 InputBarPrintInput (LastColumn
, LastRow
);
239 // if just choose yes/no
247 mReturnString
[Size
] = CHAR_NULL
;
251 // restore screen attributes
253 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, CursorCol
, CursorRow
);
254 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
260 SetPrompt and wait for input.
262 @param[in] Str The prompt string.
264 @retval EFI_SUCCESS The operation was successful.
265 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
273 // FREE the old mPrompt string
275 SHELL_FREE_NON_NULL (mPrompt
);
277 mPrompt
= CatSPrint (NULL
, L
"%s ", Str
);
278 if (mPrompt
== NULL
) {
279 return EFI_OUT_OF_RESOURCES
;
286 Set the size of the string in characters.
288 @param[in] Size The max number of characters to accept.
290 @retval EFI_SUCCESS The operation was successful.
291 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
294 InputBarSetStringSize (
299 // free the old ReturnStirng
301 SHELL_FREE_NON_NULL (mReturnString
);
304 mReturnString
= AllocateZeroPool ((StringSize
+ 1) * sizeof(mReturnString
[0]));
305 if (mReturnString
== NULL
) {
306 return EFI_OUT_OF_RESOURCES
;
313 Function to retrieve the input from the user.
315 @retval NULL No input has been received.
316 @return The string that was input.
323 return (mReturnString
);