]>
Commit | Line | Data |
---|---|---|
2442e62a | 1 | /** @file\r |
2 | Implements statusbar interface functions.\r | |
3 | \r | |
ba0014b9 | 4 | Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. <BR>\r |
56ba3746 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
2442e62a | 6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include "EditStatusBar.h"\r | |
10 | #include "UefiShellDebug1CommandsLib.h"\r | |
11 | \r | |
47d20b54 MK |
12 | CHAR16 *StatusString;\r |
13 | BOOLEAN StatusBarNeedRefresh;\r | |
14 | BOOLEAN StatusStringChanged;\r | |
2442e62a | 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 | |
2442e62a | 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 | |
2442e62a | 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 | |
47d20b54 MK |
56 | UINT32 Foreground : 4;\r |
57 | UINT32 Background : 3;\r | |
2442e62a | 58 | } STATUS_BAR_COLOR_ATTRIBUTES;\r |
59 | \r | |
60 | typedef union {\r | |
47d20b54 MK |
61 | STATUS_BAR_COLOR_ATTRIBUTES Colors;\r |
62 | UINTN Data;\r | |
2442e62a | 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 | |
ba0014b9 | 68 | @param[in] EditorFirst TRUE to indicate the first launch of the editor.\r |
2442e62a | 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 | |
2442e62a | 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 | |
47d20b54 | 94 | \r |
2442e62a | 95 | //\r |
96 | // when it's called first time after editor launch, so refresh is mandatory\r | |
97 | //\r | |
98 | if (!StatusBarNeedRefresh && !StatusStringChanged) {\r | |
99 | return EFI_SUCCESS;\r | |
100 | }\r | |
101 | \r | |
102 | //\r | |
103 | // back up the screen attributes\r | |
104 | //\r | |
105 | Orig.Data = gST->ConOut->Mode->Attribute;\r | |
28981267 | 106 | New.Data = 0;\r |
17e59b33 JC |
107 | New.Colors.Foreground = Orig.Colors.Background & 0xF;\r |
108 | New.Colors.Background = Orig.Colors.Foreground & 0x7;\r | |
2442e62a | 109 | \r |
110 | gST->ConOut->EnableCursor (gST->ConOut, FALSE);\r | |
17e59b33 | 111 | gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);\r |
2442e62a | 112 | \r |
113 | //\r | |
114 | // clear status bar\r | |
115 | //\r | |
5a2beb74 | 116 | EditorClearLine (LastRow, LastCol, LastRow);\r |
2442e62a | 117 | \r |
118 | //\r | |
119 | // print row, column fields\r | |
120 | //\r | |
47d20b54 | 121 | if ((FileRow != (UINTN)(-1)) && (FileCol != (UINTN)(-1))) {\r |
6878e7a7 | 122 | ShellPrintEx (\r |
123 | 0,\r | |
5a2beb74 | 124 | (INT32)(LastRow) - 1,\r |
125 | L" %d,%d %s",\r | |
6878e7a7 | 126 | FileRow,\r |
127 | FileCol,\r | |
128 | StatusString\r | |
129 | );\r | |
130 | } else {\r | |
131 | ShellPrintEx (\r | |
132 | 0,\r | |
5a2beb74 | 133 | (INT32)(LastRow) - 1,\r |
6878e7a7 | 134 | L" %s",\r |
135 | StatusString\r | |
136 | );\r | |
137 | }\r | |
2442e62a | 138 | \r |
139 | //\r | |
140 | // print insert mode field\r | |
141 | //\r | |
142 | if (InsertMode) {\r | |
5a2beb74 | 143 | ShellPrintEx ((INT32)(LastCol) - 21, (INT32)(LastRow) - 1, L"|%s| Help: Ctrl-E", L"INS");\r |
2442e62a | 144 | } else {\r |
5a2beb74 | 145 | ShellPrintEx ((INT32)(LastCol) - 21, (INT32)(LastRow) - 1, L"|%s| Help: Ctrl-E", L"OVR");\r |
2442e62a | 146 | }\r |
47d20b54 | 147 | \r |
2442e62a | 148 | //\r |
149 | // restore the old screen attributes\r | |
150 | //\r | |
151 | gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r | |
152 | \r | |
153 | //\r | |
154 | // restore position in edit area\r | |
155 | //\r | |
156 | gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r | |
157 | \r | |
47d20b54 MK |
158 | StatusBarNeedRefresh = FALSE;\r |
159 | StatusStringChanged = FALSE;\r | |
2442e62a | 160 | \r |
161 | return EFI_SUCCESS;\r | |
162 | }\r | |
163 | \r | |
164 | /**\r | |
165 | Set the status string text part.\r | |
166 | \r | |
167 | @param[in] Str The string to use.\r | |
168 | \r | |
169 | @retval EFI_SUCCESS The operation was successful.\r | |
170 | @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r | |
171 | **/\r | |
172 | EFI_STATUS\r | |
2442e62a | 173 | StatusBarSetStatusString (\r |
47d20b54 | 174 | IN CHAR16 *Str\r |
2442e62a | 175 | )\r |
176 | {\r | |
177 | StatusStringChanged = TRUE;\r | |
178 | \r | |
179 | //\r | |
180 | // free the old status string\r | |
181 | //\r | |
182 | SHELL_FREE_NON_NULL (StatusString);\r | |
183 | StatusString = CatSPrint (NULL, L"%s", Str);\r | |
184 | if (StatusString == NULL) {\r | |
185 | return EFI_OUT_OF_RESOURCES;\r | |
186 | }\r | |
187 | \r | |
188 | return EFI_SUCCESS;\r | |
189 | }\r | |
190 | \r | |
191 | /**\r | |
192 | Function to retrieve the current status string.\r | |
193 | \r | |
194 | @return The string that is used.\r | |
195 | **/\r | |
47d20b54 | 196 | CONST CHAR16 *\r |
2442e62a | 197 | StatusBarGetString (\r |
198 | VOID\r | |
199 | )\r | |
200 | {\r | |
201 | return (StatusString);\r | |
202 | }\r | |
203 | \r | |
204 | /**\r | |
205 | Function to set the need refresh boolean to TRUE.\r | |
206 | **/\r | |
207 | VOID\r | |
47d20b54 | 208 | StatusBarSetRefresh (\r |
2442e62a | 209 | VOID\r |
210 | )\r | |
211 | {\r | |
212 | StatusBarNeedRefresh = TRUE;\r | |
213 | }\r | |
214 | \r | |
215 | /**\r | |
216 | Function to get the need refresh boolean to TRUE.\r | |
217 | \r | |
218 | @retval TRUE The status bar needs to be refreshed.\r | |
219 | **/\r | |
220 | BOOLEAN\r | |
47d20b54 | 221 | StatusBarGetRefresh (\r |
2442e62a | 222 | VOID\r |
223 | )\r | |
224 | {\r | |
225 | return (StatusBarNeedRefresh);\r | |
226 | }\r |