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