]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellDebug1CommandsLib/EditTitleBar.c
add Edit and Hexedit shared features.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / EditTitleBar.c
1 /** @file
2 Implements titlebar 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 "EditTitleBar.h"
16 #include "UefiShellDebug1CommandsLib.h"
17
18 CHAR16 *Title = NULL;
19
20 /**
21 Initialize a title bar.
22
23 @param[in] Prompt The prompt to print in the title bar.
24
25 @retval EFI_SUCCESS The initialization was successful.
26 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
27 **/
28 EFI_STATUS
29 EFIAPI
30 MainTitleBarInit (
31 CONST CHAR16 *Prompt
32 )
33 {
34 SHELL_FREE_NON_NULL (Title);
35 if (Prompt == NULL) {
36 Title = CatSPrint (NULL, L"");
37 } else {
38 //
39 // set Title
40 //
41 Title = CatSPrint (NULL, L"%s", Prompt);
42 }
43 if (Title == NULL) {
44 return EFI_OUT_OF_RESOURCES;
45 }
46
47 return EFI_SUCCESS;
48 }
49
50 /**
51 Clean up the memory used.
52 **/
53 VOID
54 EFIAPI
55 MainTitleBarCleanup (
56 VOID
57 )
58 {
59 SHELL_FREE_NON_NULL (Title);
60 Title = NULL;
61 }
62
63 typedef struct {
64 UINT32 Foreground : 4;
65 UINT32 Background : 4;
66 } TITLE_BAR_COLOR_ATTRIBUTES;
67
68 typedef union {
69 TITLE_BAR_COLOR_ATTRIBUTES Colors;
70 UINTN Data;
71 } TITLE_BAR_COLOR_UNION;
72
73 /**
74 Refresh function for MainTitleBar
75
76 @param[in] FileName The open file's name (or NULL).
77 @param[in] FileType The type fo the file.
78 @param[in] ReadOnly TRUE if the file is read only. FALSE otherwise.
79 @param[in] Modified TRUE if the file was modified. FALSE otherwise.
80 @param[in] LastCol The last printable column.
81 @param[in] LastRow The last printable row.
82
83 @retval EFI_SUCCESS The operation was successful.
84 **/
85 EFI_STATUS
86 EFIAPI
87 MainTitleBarRefresh (
88 IN CONST CHAR16 *FileName OPTIONAL,
89 IN CONST EDIT_FILE_TYPE FileType,
90 IN BOOLEAN ReadOnly,
91 IN BOOLEAN Modified,
92 IN UINTN LastCol,
93 IN UINTN LastRow
94 )
95 {
96 TITLE_BAR_COLOR_UNION Orig;
97 TITLE_BAR_COLOR_UNION New;
98 CONST CHAR16 *FileNameTmp;
99 INTN TempInteger;
100
101
102 //
103 // backup the old screen attributes
104 //
105 Orig.Data = gST->ConOut->Mode->Attribute;
106 New.Colors.Foreground = Orig.Colors.Background;
107 New.Colors.Background = Orig.Colors.Foreground;
108
109 gST->ConOut->SetAttribute (gST->ConOut, New.Data);
110
111 //
112 // clear the title line
113 //
114 EditorClearLine (1, LastCol, LastRow);
115
116 if (Title != NULL) {
117 //
118 // print the new title bar prefix
119 //
120 ShellPrintEx (
121 0,
122 0,
123 L"%s ",
124 Title
125 );
126 }
127 if (FileName == NULL) {
128 gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);
129 return EFI_SUCCESS;
130 }
131 //
132 // First Extract the FileName from fullpath
133 //
134 FileNameTmp = FileName;
135 for (TempInteger = StrLen (FileNameTmp) - 1; TempInteger >= 0; TempInteger--) {
136 if (FileNameTmp[TempInteger] == L'\\') {
137 break;
138 }
139 }
140
141 FileNameTmp = FileNameTmp + TempInteger + 1;
142
143 //
144 // the space for file name is 20 characters
145 //
146 if (StrLen (FileNameTmp) <= 20) {
147 ShellPrintEx (-1,-1, L"%s ", FileNameTmp);
148 for (TempInteger = StrLen (FileNameTmp); TempInteger < 20; TempInteger++) {
149 ShellPrintEx (-1,-1, L" ");
150 }
151
152 } else {
153 for (TempInteger = 0; TempInteger < 17; TempInteger++) {
154 ShellPrintEx (-1,-1, L"%c", FileNameTmp[TempInteger]);
155 }
156 //
157 // print "..."
158 //
159 ShellPrintEx (-1,-1, L"... ");
160 }
161 //
162 // print file type field
163 //
164 switch (FileType){
165 case FileTypeAscii:
166 case FileTypeUnicode:
167 if (FileType == FileTypeAscii){
168 ShellPrintEx (-1,-1, L" UNICODE ");
169 }
170 //
171 // print read-only field for text files
172 //
173 if (ReadOnly) {
174 ShellPrintEx (-1,-1, L"ReadOnly ");
175 } else {
176 ShellPrintEx (-1,-1, L" ");
177 }
178 break;
179 case FileTypeDiskBuffer:
180 case FileTypeMemBuffer:
181 //
182 // Print the offset.
183 //
184 ASSERT(FALSE);
185 case FileTypeFileBuffer:
186 break;
187 }
188 //
189 // print modified field
190 //
191 if (Modified) {
192 ShellPrintEx (-1,-1, L"Modified");
193 }
194 //
195 // restore the old attribute
196 //
197 gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);
198
199 return EFI_SUCCESS;
200 }