Exemple #1
0
        /// <summary>
        ///     Manages the number of different colors that the Windows console is able to display in a given session.
        /// </summary>
        /// <param name="colorStore">The ColorStore instance in which the ColorManager will store colors.</param>
        /// <param name="colorMapper">
        ///     The ColorMapper instance the ColorManager will use to relate different color
        ///     types to one another.
        /// </param>
        /// <param name="maxColorChanges">
        ///     The maximum number of color changes allowed by the ColorManager.  It's
        ///     necessary to keep track of this, because the Windows console can only display 16 different colors in
        ///     a given session.
        /// </param>
        /// <param name="initialColorChangeCountValue">The number of color changes which have already occurred.</param>
        public ColorManager(ColorStore colorStore, ColorMapper colorMapper, int maxColorChanges,
                            int initialColorChangeCountValue, bool isInCompatibilityMode)
        {
            this.colorStore  = colorStore;
            this.colorMapper = colorMapper;

            colorChangeCount      = initialColorChangeCountValue;
            this.maxColorChanges  = maxColorChanges;
            IsInCompatibilityMode = isInCompatibilityMode;
        }
        static Console()
        {
            var isInCompatibilityMode = false;
            var isWindows             = ColorManager.IsWindows();

            try
            {
                if (isWindows)
                {
                    defaultColorMap = new ColorMapper().GetBufferColors();
                }
            }
            catch (ConsoleAccessException)
            {
                isInCompatibilityMode = true;
            }

            ReplaceAllColorsWithDefaults(isInCompatibilityMode, isWindows);
            System.Console.CancelKeyPress += Console_CancelKeyPress;
        }