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