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