]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellDebug1CommandsLib/EditTitleBar.c
f9ef7117b2cb07939b839e76b133a64e4edf02d5
[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 if (Title == NULL) {
38 return EFI_OUT_OF_RESOURCES;
39 }
40
41 return EFI_SUCCESS;
42 }
43
44 /**
45 Clean up the memory used.
46 **/
47 VOID
48 MainTitleBarCleanup (
49 VOID
50 )
51 {
52 SHELL_FREE_NON_NULL (Title);
53 Title = NULL;
54 }
55
56 typedef struct {
57 UINT32 Foreground : 4;
58 UINT32 Background : 4;
59 } TITLE_BAR_COLOR_ATTRIBUTES;
60
61 typedef union {
62 TITLE_BAR_COLOR_ATTRIBUTES Colors;
63 UINTN Data;
64 } TITLE_BAR_COLOR_UNION;
65
66 /**
67 Refresh function for MainTitleBar
68
69 @param[in] FileName The open file's name (or NULL).
70 @param[in] FileType The type fo the file.
71 @param[in] ReadOnly TRUE if the file is read only. FALSE otherwise.
72 @param[in] Modified TRUE if the file was modified. FALSE otherwise.
73 @param[in] LastCol The last printable column.
74 @param[in] LastRow The last printable row.
75 @param[in] Offset The offset into the file. (only for mem/disk)
76 @param[in] Size The file's size. (only for mem/disk)
77
78 @retval EFI_SUCCESS The operation was successful.
79 **/
80 EFI_STATUS
81 MainTitleBarRefresh (
82 IN CONST CHAR16 *FileName OPTIONAL,
83 IN CONST EDIT_FILE_TYPE FileType,
84 IN CONST BOOLEAN ReadOnly,
85 IN CONST BOOLEAN Modified,
86 IN CONST UINTN LastCol,
87 IN CONST UINTN LastRow,
88 IN CONST UINTN Offset,
89 IN CONST UINTN Size
90 )
91 {
92 TITLE_BAR_COLOR_UNION Orig;
93 TITLE_BAR_COLOR_UNION New;
94 CONST CHAR16 *FileNameTmp;
95 INTN TempInteger;
96
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 if (FileName == NULL) {
125 gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);
126 return EFI_SUCCESS;
127 }
128 //
129 // First Extract the FileName from fullpath
130 //
131 FileNameTmp = FileName;
132 for (TempInteger = StrLen (FileNameTmp) - 1; TempInteger >= 0; TempInteger--) {
133 if (FileNameTmp[TempInteger] == L'\\') {
134 break;
135 }
136 }
137
138 FileNameTmp = FileNameTmp + TempInteger + 1;
139
140 //
141 // the space for file name is 20 characters
142 //
143 if (StrLen (FileNameTmp) <= 20) {
144 ShellPrintEx (-1,-1, L"%s ", FileNameTmp);
145 for (TempInteger = StrLen (FileNameTmp); TempInteger < 20; TempInteger++) {
146 ShellPrintEx (-1,-1, L" ");
147 }
148
149 } else {
150 for (TempInteger = 0; TempInteger < 17; TempInteger++) {
151 ShellPrintEx (-1,-1, L"%c", FileNameTmp[TempInteger]);
152 }
153 //
154 // print "..."
155 //
156 ShellPrintEx (-1,-1, L"... ");
157 }
158 //
159 // print file type field
160 //
161 switch (FileType){
162 case FileTypeAscii:
163 case FileTypeUnicode:
164 if (FileType == FileTypeAscii){
165 ShellPrintEx (-1,-1, L" ASCII ");
166 } else {
167 ShellPrintEx (-1,-1, L" UNICODE ");
168 }
169 //
170 // print read-only field for text files
171 //
172 if (ReadOnly) {
173 ShellPrintEx (-1,-1, L"ReadOnly ");
174 } else {
175 ShellPrintEx (-1,-1, L" ");
176 }
177 break;
178 case FileTypeDiskBuffer:
179 case FileTypeMemBuffer:
180 //
181 // Print the offset.
182 //
183 ShellPrintEx (-1,-1, L"Offset %X | Size %X", Offset, Size);
184 case FileTypeFileBuffer:
185 break;
186 default:
187 break;
188 }
189 //
190 // print modified field
191 //
192 if (Modified) {
193 ShellPrintEx (-1,-1, L"Modified");
194 }
195 //
196 // restore the old attribute
197 //
198 gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);
199
200 return EFI_SUCCESS;
201 }