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