]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.c
add Edit and Hexedit shared features.
[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 ShellPrintEx (
129 0,
130 (INT32)(LastRow) - 4,
131 L" Row: %d Col: %d %s",
132 FileRow,
133 FileCol,
134 StatusString
135 );
136
137 //
138 // print insert mode field
139 //
140 if (InsertMode) {
141 ShellPrintEx ((INT32)(LastCol) - 10, (INT32)(LastRow) - 4, L"|%s|", L"INS");
142 } else {
143 ShellPrintEx ((INT32)(LastCol) - 10, (INT32)(LastRow) - 4, L"|%s|", L"OVR");
144 }
145 //
146 // restore the old screen attributes
147 //
148 gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);
149
150 //
151 // restore position in edit area
152 //
153 gST->ConOut->EnableCursor (gST->ConOut, TRUE);
154
155 StatusBarNeedRefresh = FALSE;
156 StatusStringChanged = FALSE;
157
158 return EFI_SUCCESS;
159 }
160
161 /**
162 Set the status string text part.
163
164 @param[in] Str The string to use.
165
166 @retval EFI_SUCCESS The operation was successful.
167 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
168 **/
169 EFI_STATUS
170 EFIAPI
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 EFIAPI
196 StatusBarGetString (
197 VOID
198 )
199 {
200 return (StatusString);
201 }
202
203 /**
204 Function to set the need refresh boolean to TRUE.
205 **/
206 VOID
207 EFIAPI
208 StatusBarSetRefresh(
209 VOID
210 )
211 {
212 StatusBarNeedRefresh = TRUE;
213 }
214
215 /**
216 Function to get the need refresh boolean to TRUE.
217
218 @retval TRUE The status bar needs to be refreshed.
219 **/
220 BOOLEAN
221 EFIAPI
222 StatusBarGetRefresh(
223 VOID
224 )
225 {
226 return (StatusBarNeedRefresh);
227 }