TianoCore EDK2 master
Loading...
Searching...
No Matches
EditInputBar.c
Go to the documentation of this file.
1
9#include "EditInputBar.h"
11
12CHAR16 *mPrompt; // Input bar mPrompt string.
13CHAR16 *mReturnString; // The returned string.
14UINTN StringSize; // Size of mReturnString space size.
16
22VOID
25 )
26{
27 mPrompt = NULL;
28 mReturnString = NULL;
29 StringSize = 0;
30 mTextInEx = TextInEx;
31}
32
36VOID
38 VOID
39 )
40{
41 //
42 // free input bar's prompt and input string
43 //
44 SHELL_FREE_NON_NULL (mPrompt);
45 SHELL_FREE_NON_NULL (mReturnString);
46 mPrompt = NULL;
47 mReturnString = NULL;
48}
49
57VOID
59 IN UINTN LastColumn,
60 IN UINTN LastRow
61 )
62{
63 UINTN Limit;
64 UINTN Size;
65 CHAR16 *Buffer;
66 UINTN Index;
67 UINTN mPromptLen;
68
69 mPromptLen = StrLen (mPrompt);
70 Limit = LastColumn - mPromptLen - 1;
71 Size = StrLen (mReturnString);
72
73 //
74 // check whether the mPrompt length and input length will
75 // exceed limit
76 //
77 if (Size <= Limit) {
78 Buffer = mReturnString;
79 } else {
80 Buffer = mReturnString + Size - Limit;
81 }
82
83 gST->ConOut->EnableCursor (gST->ConOut, FALSE);
84
85 ShellPrintEx (((INT32)mPromptLen), ((INT32)LastRow) - 1, L"%s", Buffer);
86 Size = StrLen (Buffer);
87
88 //
89 // print " " after mPrompt
90 //
91 for (Index = Size; Index < Limit; Index++) {
92 ShellPrintEx ((INT32)(mPromptLen + Size), ((INT32)LastRow) - 1, L" ");
93 }
94
95 gST->ConOut->EnableCursor (gST->ConOut, TRUE);
96 gST->ConOut->SetCursorPosition (gST->ConOut, Size + mPromptLen, LastRow - 1);
97}
98
99typedef struct {
100 UINT32 Foreground : 4;
101 UINT32 Background : 3;
103
104typedef union {
106 UINTN Data;
108
119 UINTN LastRow,
120 UINTN LastColumn
121 )
122{
125 EFI_KEY_DATA KeyData;
126 UINTN Size;
127 EFI_STATUS Status;
128 BOOLEAN NoDisplay;
129 UINTN EventIndex;
130 UINTN CursorRow;
131 UINTN CursorCol;
132
133 //
134 // variable initialization
135 //
136 Size = 0;
137 Status = EFI_SUCCESS;
138
139 //
140 // back up the old screen attributes
141 //
142 CursorCol = gST->ConOut->Mode->CursorColumn;
143 CursorRow = gST->ConOut->Mode->CursorRow;
144 Orig.Data = gST->ConOut->Mode->Attribute;
145 New.Data = 0;
146 New.Colors.Foreground = Orig.Colors.Background & 0xF;
147 New.Colors.Background = Orig.Colors.Foreground & 0x7;
148
149 gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);
150
151 //
152 // clear input bar
153 //
154 EditorClearLine (LastRow, LastColumn, LastRow);
155
156 gST->ConOut->SetCursorPosition (gST->ConOut, 0, LastRow - 1);
157 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_EDIT_LIBINPUTBAR_MAININPUTBAR), gShellDebug1HiiHandle, mPrompt);
158
159 //
160 // this is a selection mPrompt, cursor will stay in edit area
161 // actually this is for search , search/replace
162 //
163 if (StrStr (mPrompt, L"Yes/No")) {
164 NoDisplay = TRUE;
165 gST->ConOut->SetCursorPosition (gST->ConOut, CursorCol, CursorRow);
166 gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);
167 } else {
168 NoDisplay = FALSE;
169 }
170
171 //
172 // wait for user input
173 //
174 for ( ; ;) {
175 Status = gBS->WaitForEvent (1, &mTextInEx->WaitForKeyEx, &EventIndex);
176 if (EFI_ERROR (Status) || (EventIndex != 0)) {
177 continue;
178 }
179
180 Status = mTextInEx->ReadKeyStrokeEx (mTextInEx, &KeyData);
181 if (EFI_ERROR (Status)) {
182 continue;
183 }
184
185 if (((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != 0) &&
186 (KeyData.KeyState.KeyShiftState != EFI_SHIFT_STATE_VALID))
187 {
188 //
189 // Shift key pressed.
190 //
191 continue;
192 }
193
194 //
195 // pressed ESC
196 //
197 if (KeyData.Key.ScanCode == SCAN_ESC) {
198 Size = 0;
199 Status = EFI_NOT_READY;
200 break;
201 }
202
203 //
204 // return pressed
205 //
206 if ((KeyData.Key.UnicodeChar == CHAR_LINEFEED) || (KeyData.Key.UnicodeChar == CHAR_CARRIAGE_RETURN)) {
207 break;
208 } else if (KeyData.Key.UnicodeChar == CHAR_BACKSPACE) {
209 //
210 // backspace
211 //
212 if (Size > 0) {
213 Size--;
214 mReturnString[Size] = CHAR_NULL;
215 if (!NoDisplay) {
216 InputBarPrintInput (LastColumn, LastRow);
217 }
218 }
219 } else if ((KeyData.Key.UnicodeChar <= 127) && (KeyData.Key.UnicodeChar >= 32)) {
220 //
221 // VALID ASCII char pressed
222 //
223 mReturnString[Size] = KeyData.Key.UnicodeChar;
224
225 //
226 // should be less than specified length
227 //
228 if (Size >= StringSize) {
229 continue;
230 }
231
232 Size++;
233
234 mReturnString[Size] = CHAR_NULL;
235
236 if (!NoDisplay) {
237 InputBarPrintInput (LastColumn, LastRow);
238 } else {
239 //
240 // if just choose yes/no
241 //
242 break;
243 }
244 }
245 }
246
247 mReturnString[Size] = CHAR_NULL;
248
249 //
250 // restore screen attributes
251 //
252 gST->ConOut->SetCursorPosition (gST->ConOut, CursorCol, CursorRow);
253 gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);
254
255 return Status;
256}
257
268 IN CONST CHAR16 *Str
269 )
270{
271 //
272 // FREE the old mPrompt string
273 //
274 SHELL_FREE_NON_NULL (mPrompt);
275
276 mPrompt = CatSPrint (NULL, L"%s ", Str);
277 if (mPrompt == NULL) {
278 return EFI_OUT_OF_RESOURCES;
279 }
280
281 return EFI_SUCCESS;
282}
283
294 UINTN Size
295 )
296{
297 //
298 // free the old ReturnStirng
299 //
300 SHELL_FREE_NON_NULL (mReturnString);
301
302 StringSize = Size;
303 mReturnString = AllocateZeroPool ((StringSize + 1) * sizeof (mReturnString[0]));
304 if (mReturnString == NULL) {
305 return EFI_OUT_OF_RESOURCES;
306 }
307
308 return EFI_SUCCESS;
309}
310
317CONST CHAR16 *
319 VOID
320 )
321{
322 return (mReturnString);
323}
UINT64 UINTN
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
Definition: String.c:224
VOID InputBarCleanup(VOID)
Definition: EditInputBar.c:37
EFI_STATUS InputBarSetPrompt(IN CONST CHAR16 *Str)
Definition: EditInputBar.c:267
EFI_STATUS InputBarSetStringSize(UINTN Size)
Definition: EditInputBar.c:293
VOID InputBarPrintInput(IN UINTN LastColumn, IN UINTN LastRow)
Definition: EditInputBar.c:58
EFI_STATUS InputBarRefresh(UINTN LastRow, UINTN LastColumn)
Definition: EditInputBar.c:118
CONST CHAR16 * InputBarGetString(VOID)
Definition: EditInputBar.c:318
VOID InputBarInit(IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx)
Definition: EditInputBar.c:23
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
EFI_STATUS EFIAPI ShellPrintEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR16 *Format,...)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_SYSTEM_TABLE * gST
EFI_BOOT_SERVICES * gBS
#define STRING_TOKEN(t)
CHAR16 *EFIAPI CatSPrint(IN CHAR16 *String OPTIONAL, IN CONST CHAR16 *FormatString,...)
Definition: UefiLibPrint.c:827
VOID EditorClearLine(IN UINTN Row, IN UINTN LastCol, IN UINTN LastRow)
UINT32 KeyShiftState
EFI_SIMPLE_TEXT_OUTPUT_MODE * Mode
EFI_INPUT_KEY Key
EFI_KEY_STATE KeyState
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
Definition: UefiSpec.h:2064