]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.c
ShellPkg/UefiShellDebug1CommandsLib: Remove unnecessary EFIAPI
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / EditStatusBar.c
CommitLineData
2442e62a 1/** @file\r
2 Implements statusbar interface functions.\r
3\r
17e59b33 4 Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved. <BR>\r
2442e62a 5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "EditStatusBar.h"\r
16#include "UefiShellDebug1CommandsLib.h"\r
17\r
18CHAR16 *StatusString;\r
19BOOLEAN StatusBarNeedRefresh;\r
20BOOLEAN StatusStringChanged;\r
21\r
22/**\r
23 Initialization function for Status Bar.\r
24\r
25 @retval EFI_SUCCESS The operation was successful.\r
26 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
27 @sa StatusBarSetStatusString\r
28**/\r
29EFI_STATUS\r
2442e62a 30StatusBarInit (\r
31 VOID\r
32 )\r
33{\r
34 //\r
35 // initialize the statusbar\r
36 //\r
37 StatusString = NULL;\r
38 StatusBarNeedRefresh = TRUE;\r
39 StatusStringChanged = FALSE;\r
40\r
41 //\r
42 // status string set to ""\r
43 //\r
44 return (StatusBarSetStatusString (L""));\r
45}\r
46\r
47/**\r
48 Cleanup function for the status bar.\r
49**/\r
50VOID\r
2442e62a 51StatusBarCleanup (\r
52 VOID\r
53 )\r
54{\r
55 //\r
56 // free the status string and backvar's status string\r
57 //\r
58 SHELL_FREE_NON_NULL (StatusString);\r
59}\r
60\r
61typedef struct {\r
62 UINT32 Foreground : 4;\r
17e59b33 63 UINT32 Background : 3;\r
2442e62a 64} STATUS_BAR_COLOR_ATTRIBUTES;\r
65\r
66typedef union {\r
67 STATUS_BAR_COLOR_ATTRIBUTES Colors;\r
68 UINTN Data;\r
69} STATUS_BAR_COLOR_UNION;\r
70\r
71/**\r
72 Cause the status bar to refresh it's printing on the screen.\r
73\r
74 @param[in] EditorFirst TRUE to indicate the first launch of the editor. \r
75 FALSE otherwise.\r
76 @param[in] LastRow LastPrintable row.\r
77 @param[in] LastCol Last printable column.\r
78 @param[in] FileRow Row in the file.\r
79 @param[in] FileCol Column in the file.\r
80 @param[in] InsertMode TRUE to indicate InsertMode. FALSE otherwise.\r
81\r
82 @retval EFI_SUCCESS The operation was successful.\r
83**/\r
84EFI_STATUS\r
2442e62a 85StatusBarRefresh (\r
86 IN BOOLEAN EditorFirst,\r
87 IN UINTN LastRow,\r
88 IN UINTN LastCol,\r
89 IN UINTN FileRow,\r
90 IN UINTN FileCol,\r
91 IN BOOLEAN InsertMode\r
92 )\r
93{\r
94 STATUS_BAR_COLOR_UNION Orig;\r
95 STATUS_BAR_COLOR_UNION New;\r
96\r
97 if (!StatusStringChanged && StatusBarNeedRefresh) {\r
98 StatusBarSetStatusString (L"\0");\r
99 }\r
100 //\r
101 // when it's called first time after editor launch, so refresh is mandatory\r
102 //\r
103 if (!StatusBarNeedRefresh && !StatusStringChanged) {\r
104 return EFI_SUCCESS;\r
105 }\r
106\r
107 //\r
108 // back up the screen attributes\r
109 //\r
110 Orig.Data = gST->ConOut->Mode->Attribute;\r
28981267 111 New.Data = 0;\r
17e59b33
JC
112 New.Colors.Foreground = Orig.Colors.Background & 0xF;\r
113 New.Colors.Background = Orig.Colors.Foreground & 0x7;\r
2442e62a 114\r
115 gST->ConOut->EnableCursor (gST->ConOut, FALSE);\r
17e59b33 116 gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);\r
2442e62a 117\r
118 //\r
119 // clear status bar\r
120 //\r
5a2beb74 121 EditorClearLine (LastRow, LastCol, LastRow);\r
2442e62a 122\r
123 //\r
124 // print row, column fields\r
125 //\r
6878e7a7 126 if (FileRow != (UINTN)(-1) && FileCol != (UINTN)(-1)) {\r
127 ShellPrintEx (\r
128 0,\r
5a2beb74 129 (INT32)(LastRow) - 1,\r
130 L" %d,%d %s",\r
6878e7a7 131 FileRow,\r
132 FileCol,\r
133 StatusString\r
134 );\r
135 } else {\r
136 ShellPrintEx (\r
137 0,\r
5a2beb74 138 (INT32)(LastRow) - 1,\r
6878e7a7 139 L" %s",\r
140 StatusString\r
141 );\r
142 }\r
2442e62a 143\r
144 //\r
145 // print insert mode field\r
146 //\r
147 if (InsertMode) {\r
5a2beb74 148 ShellPrintEx ((INT32)(LastCol) - 21, (INT32)(LastRow) - 1, L"|%s| Help: Ctrl-E", L"INS");\r
2442e62a 149 } else {\r
5a2beb74 150 ShellPrintEx ((INT32)(LastCol) - 21, (INT32)(LastRow) - 1, L"|%s| Help: Ctrl-E", L"OVR");\r
2442e62a 151 }\r
152 //\r
153 // restore the old screen attributes\r
154 //\r
155 gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
156\r
157 //\r
158 // restore position in edit area\r
159 //\r
160 gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
161\r
162 StatusBarNeedRefresh = FALSE;\r
163 StatusStringChanged = FALSE;\r
164\r
165 return EFI_SUCCESS;\r
166}\r
167\r
168/**\r
169 Set the status string text part.\r
170\r
171 @param[in] Str The string to use.\r
172\r
173 @retval EFI_SUCCESS The operation was successful.\r
174 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
175**/\r
176EFI_STATUS\r
2442e62a 177StatusBarSetStatusString (\r
178 IN CHAR16 *Str\r
179 )\r
180{\r
181 StatusStringChanged = TRUE;\r
182\r
183 //\r
184 // free the old status string\r
185 //\r
186 SHELL_FREE_NON_NULL (StatusString);\r
187 StatusString = CatSPrint (NULL, L"%s", Str);\r
188 if (StatusString == NULL) {\r
189 return EFI_OUT_OF_RESOURCES;\r
190 }\r
191\r
192 return EFI_SUCCESS;\r
193}\r
194\r
195/**\r
196 Function to retrieve the current status string.\r
197\r
198 @return The string that is used.\r
199**/\r
200CONST CHAR16*\r
2442e62a 201StatusBarGetString (\r
202 VOID\r
203 )\r
204{\r
205 return (StatusString);\r
206}\r
207\r
208/**\r
209 Function to set the need refresh boolean to TRUE.\r
210**/\r
211VOID\r
2442e62a 212StatusBarSetRefresh(\r
213 VOID\r
214 )\r
215{\r
216 StatusBarNeedRefresh = TRUE;\r
217}\r
218\r
219/**\r
220 Function to get the need refresh boolean to TRUE.\r
221\r
222 @retval TRUE The status bar needs to be refreshed.\r
223**/\r
224BOOLEAN\r
2442e62a 225StatusBarGetRefresh(\r
226 VOID\r
227 )\r
228{\r
229 return (StatusBarNeedRefresh);\r
230}\r