]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellDebug1CommandsLib/EditTitleBar.c
ShellPkg: Standardized HP Copyright Message String
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / EditTitleBar.c
CommitLineData
2442e62a 1/** @file\r
2 Implements titlebar interface functions.\r
3\r
c011b6c9 4 (C) Copyright 2013 Hewlett-Packard Development Company, L.P.<BR>\r
17e59b33 5 Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved. <BR>\r
2442e62a 6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "EditTitleBar.h"\r
17#include "UefiShellDebug1CommandsLib.h"\r
18\r
19CHAR16 *Title = NULL;\r
20\r
21/**\r
22 Initialize a title bar.\r
23\r
24 @param[in] Prompt The prompt to print in the title bar.\r
25\r
26 @retval EFI_SUCCESS The initialization was successful.\r
27 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
28**/\r
29EFI_STATUS\r
30EFIAPI\r
31MainTitleBarInit (\r
32 CONST CHAR16 *Prompt\r
33 )\r
34{\r
35 SHELL_FREE_NON_NULL (Title);\r
36 if (Prompt == NULL) {\r
37 Title = CatSPrint (NULL, L"");\r
38 } else {\r
39 //\r
40 // set Title\r
41 //\r
42 Title = CatSPrint (NULL, L"%s", Prompt);\r
43 }\r
44 if (Title == NULL) {\r
45 return EFI_OUT_OF_RESOURCES;\r
46 }\r
47\r
48 return EFI_SUCCESS;\r
49}\r
50\r
51/**\r
52 Clean up the memory used.\r
53**/\r
54VOID\r
55EFIAPI\r
56MainTitleBarCleanup (\r
57 VOID\r
58 )\r
59{\r
60 SHELL_FREE_NON_NULL (Title);\r
61 Title = NULL;\r
62}\r
63\r
64typedef struct {\r
65 UINT32 Foreground : 4;\r
66 UINT32 Background : 4;\r
67} TITLE_BAR_COLOR_ATTRIBUTES;\r
68\r
69typedef union {\r
70 TITLE_BAR_COLOR_ATTRIBUTES Colors;\r
71 UINTN Data;\r
72} TITLE_BAR_COLOR_UNION;\r
73\r
74/**\r
75 Refresh function for MainTitleBar\r
76\r
77 @param[in] FileName The open file's name (or NULL).\r
78 @param[in] FileType The type fo the file.\r
79 @param[in] ReadOnly TRUE if the file is read only. FALSE otherwise.\r
80 @param[in] Modified TRUE if the file was modified. FALSE otherwise.\r
81 @param[in] LastCol The last printable column.\r
82 @param[in] LastRow The last printable row.\r
980d554e 83 @param[in] Offset The offset into the file. (only for mem/disk)\r
84 @param[in] Size The file's size. (only for mem/disk)\r
2442e62a 85\r
86 @retval EFI_SUCCESS The operation was successful.\r
87**/\r
88EFI_STATUS\r
89EFIAPI\r
90MainTitleBarRefresh (\r
91 IN CONST CHAR16 *FileName OPTIONAL,\r
92 IN CONST EDIT_FILE_TYPE FileType,\r
980d554e 93 IN CONST BOOLEAN ReadOnly,\r
94 IN CONST BOOLEAN Modified,\r
95 IN CONST UINTN LastCol,\r
96 IN CONST UINTN LastRow,\r
97 IN CONST UINTN Offset,\r
98 IN CONST UINTN Size\r
2442e62a 99 )\r
100{\r
101 TITLE_BAR_COLOR_UNION Orig;\r
102 TITLE_BAR_COLOR_UNION New;\r
103 CONST CHAR16 *FileNameTmp;\r
104 INTN TempInteger;\r
105\r
106\r
107 //\r
108 // backup the old screen attributes\r
109 //\r
110 Orig.Data = gST->ConOut->Mode->Attribute;\r
28981267 111 New.Data = 0;\r
17e59b33
JC
112 New.Colors.Foreground = Orig.Colors.Background & 0xF;\r
113 New.Colors.Background = Orig.Colors.Foreground & 0x7;\r
2442e62a 114\r
17e59b33 115 gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);\r
2442e62a 116\r
117 //\r
118 // clear the title line\r
119 //\r
120 EditorClearLine (1, LastCol, LastRow);\r
121\r
122 if (Title != NULL) {\r
123 //\r
124 // print the new title bar prefix\r
125 //\r
126 ShellPrintEx (\r
127 0,\r
128 0,\r
129 L"%s ",\r
130 Title\r
131 );\r
132 }\r
133 if (FileName == NULL) {\r
134 gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
135 return EFI_SUCCESS;\r
136 }\r
137 //\r
138 // First Extract the FileName from fullpath\r
139 //\r
140 FileNameTmp = FileName;\r
141 for (TempInteger = StrLen (FileNameTmp) - 1; TempInteger >= 0; TempInteger--) {\r
142 if (FileNameTmp[TempInteger] == L'\\') {\r
143 break;\r
144 }\r
145 }\r
146\r
147 FileNameTmp = FileNameTmp + TempInteger + 1;\r
148\r
149 //\r
150 // the space for file name is 20 characters\r
151 //\r
152 if (StrLen (FileNameTmp) <= 20) {\r
153 ShellPrintEx (-1,-1, L"%s ", FileNameTmp);\r
154 for (TempInteger = StrLen (FileNameTmp); TempInteger < 20; TempInteger++) {\r
155 ShellPrintEx (-1,-1, L" ");\r
156 }\r
157\r
158 } else {\r
159 for (TempInteger = 0; TempInteger < 17; TempInteger++) {\r
160 ShellPrintEx (-1,-1, L"%c", FileNameTmp[TempInteger]);\r
161 }\r
162 //\r
163 // print "..."\r
164 //\r
165 ShellPrintEx (-1,-1, L"... ");\r
166 }\r
167 //\r
168 // print file type field\r
169 //\r
170 switch (FileType){\r
171 case FileTypeAscii:\r
172 case FileTypeUnicode:\r
173 if (FileType == FileTypeAscii){\r
abbea36e
CP
174 ShellPrintEx (-1,-1, L" ASCII ");\r
175 } else {\r
2442e62a 176 ShellPrintEx (-1,-1, L" UNICODE ");\r
177 }\r
178 //\r
179 // print read-only field for text files\r
180 //\r
181 if (ReadOnly) {\r
182 ShellPrintEx (-1,-1, L"ReadOnly ");\r
183 } else {\r
184 ShellPrintEx (-1,-1, L" ");\r
185 }\r
186 break;\r
187 case FileTypeDiskBuffer:\r
188 case FileTypeMemBuffer:\r
189 //\r
190 // Print the offset.\r
191 //\r
411a3c39 192 ShellPrintEx (-1,-1, L"Offset %X | Size %X", Offset, Size);\r
2442e62a 193 case FileTypeFileBuffer:\r
194 break;\r
e0c2cc6f 195 default:\r
196 break;\r
2442e62a 197 }\r
198 //\r
199 // print modified field\r
200 //\r
201 if (Modified) {\r
202 ShellPrintEx (-1,-1, L"Modified");\r
203 }\r
204 //\r
205 // restore the old attribute\r
206 //\r
207 gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
208\r
209 return EFI_SUCCESS;\r
210}\r