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