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