//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// CommonHelpers satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;

namespace CommonHelpers {

//**************************************************************************************************
partial class HConsole {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

enum HeaderFooterType { Normal, Shallow, Title }

//**************************************************************************************************

void PrintHeaderFooter( HeaderFooterType headerFooterType,
                        bool footer,
                        bool insertPrecedingBlankLine,
                        bool insertPosteriorBlankLine,
                        string caption )
{
   var color = HeaderFooterColor;
   var fillChar = HeaderFooterChar;

   switch (headerFooterType)
   {
   case HeaderFooterType.Shallow:
      color = ShallowHeaderFooterColor;
      fillChar = ShallowHeaderFooterChar;
      break;
   case HeaderFooterType.Title:
      color = TitleHeaderFooterColor;
      fillChar = TitleHeaderFooterChar;
      break;
   }

   int
      width = NormLimitedWidth,
      maxCaptionLength = width - (HeaderFooterPaddingWidth+1)*2;
   if (caption.Length>maxCaptionLength)
      caption = caption.Substring( 0,
         HArith.ConfinePositiveOrZero( maxCaptionLength ) );

   lock (_InstanceSyncRoot_)
   {
      if (insertPrecedingBlankLine)
         Print();
      if (!footer)
         Print(color,new string(fillChar,width));
      Print
      (
         color, "{1} {0} {2}", caption,
         new string(fillChar,HeaderFooterPaddingWidth),
         new string( fillChar,
            Math.Max( width-caption.Length-HeaderFooterPaddingWidth-2,
                      HeaderFooterPaddingWidth ) )
      );
      if (footer || headerFooterType==HeaderFooterType.Title)
         Print(color,new string(fillChar,width));
      if (insertPosteriorBlankLine)
         Print();
   }
}

//--------------------------------------------------------------------------------------------------

void PrintHeaderFooter( HeaderFooterType headerFooterType,
                        bool footer,
                        bool insertPrecedingBlankLine,
                        bool insertPosteriorBlankLine,
                        string captionFmt,
                        object[] parameters )
{
   PrintHeaderFooter( headerFooterType, footer,
      insertPrecedingBlankLine, insertPosteriorBlankLine,
      string.Format(captionFmt,parameters) );
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HConsole
//**************************************************************************************************

} // CommonHelpers
