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