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

namespace CommonHelpers {

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

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify([HOptional] ref string inputString)
{
   return InputStringModify(null,ref inputString);
}

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify( [HOptional] ref string inputString,
                               HConsoleInputOptions options )
{
   return InputStringModify(null,ref inputString,options);
}

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify( [HOptional] ref string inputString,
                               HValidateConsoleInputCallback validationCallback )
{
   return InputStringModify(null,ref inputString,validationCallback);
}

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify( [HOptional] ref string inputString,
                               HConsoleInputOptions options,
                               HValidateConsoleInputCallback validationCallback )
{
   return InputStringModify(null,ref inputString,options,validationCallback);
}

//==================================================================================================

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify( [HOptional] string caption,
                               [HOptional] ref string inputString )
{
   return InputStringModify(caption,0,ref inputString);
}

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify( [HOptional] string caption,
                               [HOptional] ref string inputString,
                               HConsoleInputOptions options )
{
   return InputStringModify(caption,0,ref inputString,options);
}

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify
(
   [HOptional] string caption,
   [HOptional] ref string inputString,
   [HOptional] HValidateConsoleInputCallback validationCallback
)
{
   return InputStringModify(caption,0,ref inputString,validationCallback);
}

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify
(
   [HOptional] string caption,
   [HOptional] ref string inputString,
   HConsoleInputOptions options,
   [HOptional] HValidateConsoleInputCallback validationCallback
)
{
   return InputStringModify(caption,0,ref inputString,options,validationCallback);
}

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

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify( [HOptional] string caption,
                               ConsoleColor? captionColor,
                               [HOptional] ref string inputString )
{
   return InputStringModify(caption,captionColor,0,ref inputString);
}

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify( [HOptional] string caption,
                               ConsoleColor? captionColor,
                               [HOptional] ref string inputString,
                               HConsoleInputOptions options )
{
   return InputStringModify(caption,captionColor,0,ref inputString,options);
}

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify
(
   [HOptional] string caption,
   ConsoleColor? captionColor,
   [HOptional] ref string inputString,
   [HOptional] HValidateConsoleInputCallback validationCallback
)
{
   return InputStringModify(caption,captionColor,0,ref inputString,validationCallback);
}

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify
(
   [HOptional] string caption,
   ConsoleColor? captionColor,
   [HOptional] ref string inputString,
   HConsoleInputOptions options,
   [HOptional] HValidateConsoleInputCallback validationCallback
)
{
   return InputStringModify(caption,captionColor,0,ref inputString,options,validationCallback);
}

//==================================================================================================

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify( string caption,
                               [HOptional] int maxCaptionLength,
                               [HOptional] ref string inputString )
{
   return InputStringModify(
      caption, null, maxCaptionLength,
      ref inputString, null, null, 0, null );
}

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify( string caption,
                               [HOptional] int maxCaptionLength,
                               [HOptional] ref string inputString,
                               HConsoleInputOptions options )
{
   return InputStringModify(
      caption, null, maxCaptionLength,
      ref inputString, null, null, options, null );
}

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify
(
   string caption,
   [HOptional] int maxCaptionLength,
   [HOptional] ref string inputString,
   [HOptional] HValidateConsoleInputCallback validationCallback
)
{
   return InputStringModify(
      caption, null, maxCaptionLength,
      ref inputString, null, null, 0, validationCallback );
}

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify
(
   string caption,
   [HOptional] int maxCaptionLength,
   [HOptional] ref string inputString,
   HConsoleInputOptions options,
   [HOptional] HValidateConsoleInputCallback validationCallback
)
{
   return InputStringModify(
      caption, null, maxCaptionLength,
      ref inputString, null, null, options, validationCallback );
}

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

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify( string caption,
                               ConsoleColor? captionColor,
                               [HOptional] int maxCaptionLength,
                               [HOptional] ref string inputString )
{
   return InputStringModify(
      caption, captionColor, maxCaptionLength,
      ref inputString, null, null, 0, null );
}

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify( string caption,
                               ConsoleColor? captionColor,
                               [HOptional] int maxCaptionLength,
                               [HOptional] ref string inputString,
                               HConsoleInputOptions options )
{
   return InputStringModify(
      caption, captionColor, maxCaptionLength,
      ref inputString, null, null, options, null );
}

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify
(
   string caption,
   ConsoleColor? captionColor,
   [HOptional] int maxCaptionLength,
   [HOptional] ref string inputString,
   [HOptional] HValidateConsoleInputCallback validationCallback
)
{
   return InputStringModify(
      caption, captionColor, maxCaptionLength,
      ref inputString, null, null, 0, validationCallback );
}

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify
(
   string caption,
   ConsoleColor? captionColor,
   [HOptional] int maxCaptionLength,
   [HOptional] ref string inputString,
   HConsoleInputOptions options,
   [HOptional] HValidateConsoleInputCallback validationCallback
)
{
   return InputStringModify(
      caption, captionColor, maxCaptionLength,
      ref inputString, null, null, options, validationCallback );
}

//==================================================================================================

/// <exception cref="InvalidOperationException" />
/// <exception cref="HAbortConsoleInputException" />
public bool InputStringModify
(
   [HOptional] string caption,
   ConsoleColor? captionColor,
   [HOptional] int maxCaptionLength,
   [HOptional] ref string inputString,
   ConsoleColor? foregroundColor,
   ConsoleColor? backgroundColor,
   HConsoleInputOptions options,
   [HOptional] HValidateConsoleInputCallback validationCallback
)
{
   VerifyInNativeVisualMode();

   if (caption!=null)
      OutputArrowAlignedInputPrompt( caption,
         captionColor ?? InputCaptionColor,
         maxCaptionLength );

   lock (_InstanceSyncRoot_)
   {
      foregroundColor = foregroundColor ?? InputForegroundColor;
      backgroundColor = backgroundColor ?? InputBackgroundColor;

      bool result = false;

      try
      {
         using ( var colorRetention =
            new HConsoleColorRetention( this, foregroundColor, backgroundColor ))
         {
            string inputRoutineResult =
               StringInputRoutine(colorRetention,inputString,options,validationCallback);
            if (inputRoutineResult!=null)
            {
               inputString = inputRoutineResult;
               result = true;
            }
         }
      }
      catch (HAbortConsoleInputException)
      {
         Print(); throw;
      }

      Print();

      return result;
   }
}

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

} // CommonHelpers
