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