コード例 #1
0
ファイル: LocalVariableSet.cs プロジェクト: jiaw37/PowerArgs
        /// <summary>
        /// Sets the current console color variables to the given values, pushing the existing values onto a stack
        /// </summary>
        /// <param name="fg">The optional foreground color to set</param>
        /// <param name="bg">The optional background color to set</param>
        public void PushConsoleColors(RGB?fg = null, RGB?bg = null)
        {
            ConsoleColorStackElement el = new ConsoleColorStackElement();

            if (IsDefined("ConsoleForegroundColor"))
            {
                el.FG = (RGB)(ConsoleColor)this["ConsoleForegroundColor"];
            }

            if (IsDefined("ConsoleBackgroundColor"))
            {
                el.BG = (RGB)(ConsoleColor)this["ConsoleBackgroundColor"];
            }
            consoleStack.Push(el);

            if (fg.HasValue)
            {
                Force("ConsoleForegroundColor", (ConsoleColor)fg.Value);
            }

            if (bg.HasValue)
            {
                Force("ConsoleBackgroundColor", (ConsoleColor)bg.Value);
            }
        }
コード例 #2
0
        /// <summary>
        /// Sets the current console color variables to the given values, pushing the existing values onto a stack
        /// </summary>
        /// <param name="fg">The optional foreground color to set</param>
        /// <param name="bg">The optional background color to set</param>
        public void PushConsoleColors(ConsoleColor? fg = null, ConsoleColor? bg = null)
        {
            ConsoleColorStackElement el = new ConsoleColorStackElement();
            if(IsDefined("ConsoleForegroundColor"))
            {
                el.FG = (ConsoleColor)this["ConsoleForegroundColor"];
            }

            if (IsDefined("ConsoleBackgroundColor"))
            {
                el.BG = (ConsoleColor)this["ConsoleBackgroundColor"];
            }
            consoleStack.Push(el);

            if(fg.HasValue)
            {
                Force("ConsoleForegroundColor", fg.Value);
            }

            if (bg.HasValue)
            {
                Force("ConsoleBackgroundColor", bg.Value);
            }
        }